Skip to content

Commit b3aa95b

Browse files
committed
ci: Simplify ci-os-only handling
Handle 'ci-os-only' occurrences in the .cirrus.star file instead of .cirrus.tasks.yml file. Now, 'ci-os-only' occurrences are controlled from one central place instead of dealing with them in each task. Author: Andres Freund <andres@anarazel.de> Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/20240413021221.hg53rvqlvldqh57i%40awork3.anarazel.de Backpatch: 15-, where CI support was added
1 parent 88f3f7f commit b3aa95b

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

.cirrus.star

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ https://github.com/bazelbuild/starlark/blob/master/spec.md
77
See also .cirrus.yml and src/tools/ci/README
88
"""
99

10-
load("cirrus", "env", "fs", "yaml")
10+
load("cirrus", "env", "fs", "re", "yaml")
1111

1212

1313
def main():
@@ -66,6 +66,7 @@ def main():
6666
def compute_environment_vars():
6767
cenv = {}
6868

69+
###
6970
# Some tasks are manually triggered by default because they might use too
7071
# many resources for users of free Cirrus credits, but they can be
7172
# triggered automatically by naming them in an environment variable e.g.
@@ -82,6 +83,33 @@ def compute_environment_vars():
8283
else:
8384
value = 'manual'
8485
cenv[name] = value
86+
###
87+
88+
###
89+
# Parse "ci-os-only:" tag in commit message and set
90+
# CI_{$OS}_ENABLED variable for each OS
91+
92+
operating_systems = [
93+
'freebsd',
94+
'linux',
95+
'macos',
96+
'windows',
97+
]
98+
commit_message = env.get('CIRRUS_CHANGE_MESSAGE')
99+
match_re = r"(^|.*\n)ci-os-only: ([^\n]+)($|\n.*)"
100+
101+
# re.match() returns an array with a tuple of (matched-string, match_1, ...)
102+
m = re.match(match_re, commit_message)
103+
if m and len(m) > 0:
104+
os_only = m[0][2]
105+
os_only_list = re.split(r'[, ]+', os_only)
106+
else:
107+
os_only_list = operating_systems
108+
109+
for os in operating_systems:
110+
os_enabled = os in os_only_list
111+
cenv['CI_{0}_ENABLED'.format(os.upper())] = os_enabled
112+
###
85113

86114
return cenv
87115

.cirrus.tasks.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ task:
4747

4848
<<: *freebsd_task_template
4949

50-
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*freebsd.*'
50+
only_if: $CI_FREEBSD_ENABLED
5151

5252
sysinfo_script: |
5353
id
@@ -153,7 +153,7 @@ task:
153153

154154
<<: *linux_task_template
155155

156-
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*'
156+
only_if: $CI_LINUX_ENABLED
157157

158158
ccache_cache:
159159
folder: ${CCACHE_DIR}
@@ -239,7 +239,7 @@ task:
239239
240240
<<: *macos_task_template
241241

242-
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*(macos|darwin|osx).*'
242+
only_if: $CI_MACOS_ENABLED
243243

244244
sysinfo_script: |
245245
id
@@ -389,7 +389,7 @@ task:
389389

390390
<<: *windows_task_template
391391

392-
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
392+
only_if: $CI_WINDOWS_ENABLED
393393

394394
sysinfo_script: |
395395
chcp
@@ -476,7 +476,7 @@ task:
476476

477477
# task that did not run, count as a success, so we need to recheck Linux'
478478
# condition here ...
479-
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*'
479+
only_if: $CI_LINUX_ENABLED
480480

481481
<<: *linux_task_template
482482

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy