Skip to content

Commit 49cba82

Browse files
anarazelmacdicenbyavuz
committed
ci: Per-repo configuration for manually trigger tasks
We do not want to trigger some tasks by default, to avoid using too many compute credits. These tasks have to be manually triggered to be run. But e.g. for cfbot we do have sufficient resources, so we always want to start those tasks. With this commit, an individual repository can be configured to trigger them automatically using an environment variable defined under "Repository Settings", for example: REPO_CI_AUTOMATIC_TRIGGER_TASKS="mingw netbsd openbsd" This will enable cfbot to turn them on by default when running tests for the Commitfest app. Backpatch this back to PG 15, even though PG 15 does not have any manually triggered task. Keeping the CI infrastructure the same seems advantageous. Author: Andres Freund <andres@anarazel.de> Co-authored-by: Thomas Munro <thomas.munro@gmail.com> Co-authored-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/20240413021221.hg53rvqlvldqh57i%40awork3.anarazel.de Backpatch-through: 16
1 parent d0e7e04 commit 49cba82

File tree

4 files changed

+75
-13
lines changed

4 files changed

+75
-13
lines changed

.cirrus.star

Lines changed: 46 additions & 4 deletions
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")
10+
load("cirrus", "env", "fs", "yaml")
1111

1212

1313
def main():
@@ -18,32 +18,74 @@ def main():
1818
1919
1) the contents of .cirrus.yml
2020
21-
2) if defined, the contents of the file referenced by the, repository
21+
2) computed environment variables
22+
23+
3) if defined, the contents of the file referenced by the, repository
2224
level, REPO_CI_CONFIG_GIT_URL variable (see
2325
https://cirrus-ci.org/guide/programming-tasks/#fs for the accepted
2426
format)
2527
26-
3) .cirrus.tasks.yml
28+
4) .cirrus.tasks.yml
2729
"""
2830

2931
output = ""
3032

3133
# 1) is evaluated implicitly
3234

35+
3336
# Add 2)
37+
additional_env = compute_environment_vars()
38+
env_fmt = """
39+
###
40+
# Computed environment variables start here
41+
###
42+
{0}
43+
###
44+
# Computed environment variables end here
45+
###
46+
"""
47+
output += env_fmt.format(yaml.dumps({'env': additional_env}))
48+
49+
50+
# Add 3)
3451
repo_config_url = env.get("REPO_CI_CONFIG_GIT_URL")
3552
if repo_config_url != None:
3653
print("loading additional configuration from \"{}\"".format(repo_config_url))
3754
output += config_from(repo_config_url)
3855
else:
3956
output += "\n# REPO_CI_CONFIG_URL was not set\n"
4057

41-
# Add 3)
58+
59+
# Add 4)
4260
output += config_from(".cirrus.tasks.yml")
4361

62+
4463
return output
4564

4665

66+
def compute_environment_vars():
67+
cenv = {}
68+
69+
# Some tasks are manually triggered by default because they might use too
70+
# many resources for users of free Cirrus credits, but they can be
71+
# triggered automatically by naming them in an environment variable e.g.
72+
# REPO_CI_AUTOMATIC_TRIGGER_TASKS="task_name other_task" under "Repository
73+
# Settings" on Cirrus CI's website.
74+
75+
default_manual_trigger_tasks = ['mingw', 'netbsd', 'openbsd']
76+
77+
repo_ci_automatic_trigger_tasks = env.get('REPO_CI_AUTOMATIC_TRIGGER_TASKS', '')
78+
for task in default_manual_trigger_tasks:
79+
name = 'CI_TRIGGER_TYPE_' + task.upper()
80+
if repo_ci_automatic_trigger_tasks.find(task) != -1:
81+
value = 'automatic'
82+
else:
83+
value = 'manual'
84+
cenv[name] = value
85+
86+
return cenv
87+
88+
4789
def config_from(config_src):
4890
"""return contents of config file `config_src`, surrounded by markers
4991
indicating start / end of the included file

.cirrus.tasks.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ task:
239239

240240
task:
241241
depends_on: SanityCheck
242-
trigger_type: manual
243242

244243
env:
245244
# Below are experimentally derived to be a decent choice.
@@ -257,6 +256,8 @@ task:
257256

258257
matrix:
259258
- name: NetBSD - Meson
259+
# See REPO_CI_AUTOMATIC_TRIGGER_TASKS in .cirrus.star
260+
trigger_type: $CI_TRIGGER_TYPE_NETBSD
260261
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*'
261262
env:
262263
OS_NAME: netbsd
@@ -274,6 +275,8 @@ task:
274275
<<: *netbsd_task_template
275276

276277
- name: OpenBSD - Meson
278+
# See REPO_CI_AUTOMATIC_TRIGGER_TASKS in .cirrus.star
279+
trigger_type: $CI_TRIGGER_TYPE_OPENBSD
277280
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*'
278281
env:
279282
OS_NAME: openbsd
@@ -754,13 +757,11 @@ task:
754757
<< : *WINDOWS_ENVIRONMENT_BASE
755758
name: Windows - Server 2019, MinGW64 - Meson
756759

757-
# due to resource constraints we don't run this task by default for now
758-
trigger_type: manual
759-
# worth using only_if despite being manual, otherwise this task will show up
760-
# when e.g. ci-os-only: linux is used.
761-
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
762-
# otherwise it'll be sorted before other tasks
760+
# See REPO_CI_AUTOMATIC_TRIGGER_TASKS in .cirrus.star.
761+
trigger_type: $CI_TRIGGER_TYPE_MINGW
762+
763763
depends_on: SanityCheck
764+
only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
764765

765766
env:
766767
TEST_JOBS: 4 # higher concurrency causes occasional failures

.cirrus.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
#
1111
# 1) the contents of this file
1212
#
13-
# 2) if defined, the contents of the file referenced by the, repository
13+
# 2) computed environment variables
14+
#
15+
# Used to enable/disable tasks based on the execution environment. See
16+
# .cirrus.star: compute_environment_vars()
17+
#
18+
# 3) if defined, the contents of the file referenced by the, repository
1419
# level, REPO_CI_CONFIG_GIT_URL variable (see
1520
# https://cirrus-ci.org/guide/programming-tasks/#fs for the accepted
1621
# format)
1722
#
18-
# 3) .cirrus.tasks.yml
23+
# This allows running tasks in a different execution environment than the
24+
# default, e.g. to have sufficient resources for cfbot.
25+
#
26+
# 4) .cirrus.tasks.yml
1927
#
2028
# This composition is done by .cirrus.star
2129

src/tools/ci/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ defined in .cirrus.yml, by redefining the relevant yaml anchors.
8282
Custom compute resources can be provided using
8383
- https://cirrus-ci.org/guide/supported-computing-services/
8484
- https://cirrus-ci.org/guide/persistent-workers/
85+
86+
87+
Enabling manual tasks by default
88+
================================
89+
90+
Some tasks are not triggered automatically by default, to avoid using up CI
91+
credits too quickly. This can be changed on the repository level, e.g. when
92+
custom compute resources are configured.
93+
94+
The following repository level environment variables are recognized:
95+
- REPO_CI_AUTOMATIC_TRIGGER_TASKS - space-separated list of (mingw|netbsd|openbsd)

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