summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2025-08-14 11:48:04 -0400
committerAndres Freund <andres@anarazel.de>2025-08-14 12:18:23 -0400
commitb3aa95b61e90e3871f17a9aa134192a9ea3951ce (patch)
treeec0b95b029c5a097bd5e1748973d1223e21683ed
parent88f3f7fd831e81c090ec627ccb7adceb203e0d30 (diff)
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
-rw-r--r--.cirrus.star30
-rw-r--r--.cirrus.tasks.yml10
2 files changed, 34 insertions, 6 deletions
diff --git a/.cirrus.star b/.cirrus.star
index 29f019114a1..8e52e64cc54 100644
--- a/.cirrus.star
+++ b/.cirrus.star
@@ -7,7 +7,7 @@ https://github.com/bazelbuild/starlark/blob/master/spec.md
See also .cirrus.yml and src/tools/ci/README
"""
-load("cirrus", "env", "fs", "yaml")
+load("cirrus", "env", "fs", "re", "yaml")
def main():
@@ -66,6 +66,7 @@ def main():
def compute_environment_vars():
cenv = {}
+ ###
# Some tasks are manually triggered by default because they might use too
# many resources for users of free Cirrus credits, but they can be
# triggered automatically by naming them in an environment variable e.g.
@@ -82,6 +83,33 @@ def compute_environment_vars():
else:
value = 'manual'
cenv[name] = value
+ ###
+
+ ###
+ # Parse "ci-os-only:" tag in commit message and set
+ # CI_{$OS}_ENABLED variable for each OS
+
+ operating_systems = [
+ 'freebsd',
+ 'linux',
+ 'macos',
+ 'windows',
+ ]
+ commit_message = env.get('CIRRUS_CHANGE_MESSAGE')
+ match_re = r"(^|.*\n)ci-os-only: ([^\n]+)($|\n.*)"
+
+ # re.match() returns an array with a tuple of (matched-string, match_1, ...)
+ m = re.match(match_re, commit_message)
+ if m and len(m) > 0:
+ os_only = m[0][2]
+ os_only_list = re.split(r'[, ]+', os_only)
+ else:
+ os_only_list = operating_systems
+
+ for os in operating_systems:
+ os_enabled = os in os_only_list
+ cenv['CI_{0}_ENABLED'.format(os.upper())] = os_enabled
+ ###
return cenv
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 3a5cdebf398..7f450c05747 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -47,7 +47,7 @@ task:
<<: *freebsd_task_template
- only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*freebsd.*'
+ only_if: $CI_FREEBSD_ENABLED
sysinfo_script: |
id
@@ -153,7 +153,7 @@ task:
<<: *linux_task_template
- only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*'
+ only_if: $CI_LINUX_ENABLED
ccache_cache:
folder: ${CCACHE_DIR}
@@ -239,7 +239,7 @@ task:
<<: *macos_task_template
- only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*(macos|darwin|osx).*'
+ only_if: $CI_MACOS_ENABLED
sysinfo_script: |
id
@@ -389,7 +389,7 @@ task:
<<: *windows_task_template
- only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+ only_if: $CI_WINDOWS_ENABLED
sysinfo_script: |
chcp
@@ -476,7 +476,7 @@ task:
# task that did not run, count as a success, so we need to recheck Linux'
# condition here ...
- only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*'
+ only_if: $CI_LINUX_ENABLED
<<: *linux_task_template