41be14a7bcf81093e08fac8b1d2966c0d0684ec8
[alexxy/gromacs.git] / admin / gitlab-ci / rules.gitlab-ci.yml
1 # Mix-in definitions to inherit a standardized *rules* parameter.
2 # Reference:
3 # * https://docs.gitlab.com/ee/ci/yaml/#rules
4 # * https://docs.gitlab.com/ee/ci/variables/README.html#syntax-of-environment-variable-expressions
5
6 # GitLab CI uses a YAML array for the *rules* job parameter, but neither YAML
7 # nor GitLab CI syntax provide a way to merge arrays. However, elements of
8 # *rules* are mappings, and we can at least reduce the amount of copy-paste
9 # syntax by providing anchors and example arrays.
10 # The following YAML objects may be referenced through "anchors" as elements of
11 # the *rules* array in mix-in jobs (defined later in the file).
12 # The &<name> annotation is a YAML anchor that allows the annotated {"if", "when"} hash
13 # to be inserted with a *<name> alias in a `rules` arrays in the current file.
14 # Commonly reusable elements have anchors defined for easy copy-paste templating
15 # of new rule sets. Rule elements that are unique to a single *rules* mix-in may
16 # be defined with the rule set for readability, particularly when the element is
17 # the main distinguishing characteristic of the mix-in.
18
19 # Exclude from pipelines launched outside the "gromacs" GitLab project namespace.
20 .rules-element:if-not-gromacs-then-never: &if-not-gromacs-then-never
21   if: '$CI_PROJECT_NAMESPACE != "gromacs"'
22   when: never
23
24 # Exclude if the GROMACS_RELEASE variable is set.
25 .rules-element:if-release-then-never: &if-release-then-never
26   if: '$GROMACS_RELEASE'
27   when: never
28
29 # Exclude unless the GROMACS_RELEASE variable is set (through the web interface).
30 .rules-element:if-not-release-then-never: &if-not-release-then-never
31   if: '$GROMACS_RELEASE == null'
32   when: never
33
34 # Include in pipelines triggered through the web interface.
35 .rules-element:if-web-then-always: &if-web-then-always
36   if: '$CI_PIPELINE_SOURCE == "web"'
37   when: always
38
39 # Exclude from pipelines triggered by "push" events.
40 .rules-element:if-push-then-never: &if-push-then-never
41   if: '$CI_PIPELINE_SOURCE == "push"'
42   when: never
43
44 # Include in pipelines triggered by "push" events to any branch.
45 .rules-element:if-push-then-always: &if-push-then-always
46   if: '$CI_PIPELINE_SOURCE == "push"'
47   when: always
48
49 # Include in "schedule" pipelines (e.g. nightly jobs)
50 .rules-element:if-schedule-then-always: &if-schedule-then-always
51   if: '$CI_PIPELINE_SOURCE == "schedule"'
52   when: always
53
54 # Include in pipelines triggered in the merge request process.
55 .rules-element:if-mr-then-always: &if-mr-then-always
56   if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
57   when: always
58
59 # Exclude from pipelines triggered in the merge request process, such as for
60 # jobs that duplicate checks already performed for "push" events or that we
61 # only want to run in scheduled / manually triggered pipelines.
62 .rules-element:if-mr-then-never: &if-mr-then-never
63   if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
64   when: never
65
66 # When composing a rule set, note that the first matching rule is applied.
67 # If you want later rules to be evaluated, you must make sure that the *if*
68 # clause of the earlier rules does not match. This may require inverting the
69 # logic of a rule element *if* and *when* clause in a new element definition
70 # (above) in order to construct new rule sets.
71
72 # Jobs that run for new commits and pipelines triggered by schedules or
73 # through the web interface, unless GROMACS_RELEASE is set. Excluded from
74 # extra pipelines generated by merge request events.
75 # Includes non-gromacs projects. Note that jobs using this rule are
76 # eligible to run on non-gromacs project infrastructure, and should therefore
77 # override the default *tag* parameter to exclude tags specific to the GROMACS
78 # GitLab Runner infrastructure. I.e. in the job definition, set `tags: []`
79 .rules:basic-push:
80   rules:
81     - *if-release-then-never
82     - *if-web-then-always
83     - *if-push-then-always
84     - *if-schedule-then-always
85     - *if-mr-then-never
86
87 # Jobs that run for merge requests and schedules, but not when GROMACS_RELEASE
88 # is set. Excludes non-gromacs projects.
89 # More elaborate rule sets for merge requests should be based on the same sequence.
90 .rules:merge-requests:
91   rules:
92     - *if-not-gromacs-then-never
93     - *if-release-then-never
94     - *if-web-then-always
95     - *if-push-then-never
96     - *if-schedule-then-always
97     - *if-mr-then-always
98
99 # Jobs that run for merge requests and schedules for branch `master`,
100 # but not when GROMACS_RELEASE is set.
101 # Excludes non-gromacs projects.
102 .rules:merge-requests:master:
103   rules:
104     - *if-not-gromacs-then-never
105     - *if-release-then-never
106     - *if-web-then-always
107     # This rule catches "push" and other events in branches other than `master`
108     # but allows merge_request_events for merge requests targeting master.
109     - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master" && $CI_COMMIT_REF_NAME != "master"'
110       when: never
111     - *if-schedule-then-always
112     - *if-mr-then-always
113
114 # Jobs that run for merge requests and schedules for branch `release-2020`,
115 # but not when GROMACS_RELEASE is set.
116 # Excludes non-gromacs projects.
117 .rules:merge-requests:release-2020:
118   rules:
119     - *if-not-gromacs-then-never
120     - *if-release-then-never
121     # This next rule catches "push" and other events in branches other than `release-2020`
122     # but allows merge_request_events for merge requests targeting `release-2020`.
123     # This rule is before "web" so the web interface won't include jobs that can't succeed
124     # (and would not ordinarily be run). Such jobs are hard to identify in a way that is
125     # sufficiently general for a global rules definition.
126     # If extra coverage is needed through a web-triggered job in merge request branches,
127     # we could provide an additional short-circuiting rule based on an environment variable
128     # to be provided through the web interface.
129     - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "release-2020" && $CI_COMMIT_REF_NAME != "release-2020"'
130       when: never
131     - *if-web-then-always
132     - *if-schedule-then-always
133     - *if-mr-then-always
134
135 # Rule to run a job only in nightly release-preparation pipelines.
136 # Checks if the GROMACS_RELEASE variable was set (typically through the GitLab web interface).
137 # Excludes merge_requests and non-gromacs projects.
138 .rules:nightly-only-for-release:
139   rules:
140     - *if-not-gromacs-then-never
141     - *if-not-release-then-never
142     - *if-web-then-always
143     - *if-schedule-then-always
144
145 # Jobs that run on schedules, but not for merge requests or when GROMACS_RELEASE
146 # is set. Excludes non-gromacs projects.
147 .rules:nightly-not-for-release:
148   rules:
149     - *if-not-gromacs-then-never
150     - *if-release-then-never
151     - *if-web-then-always
152     - *if-schedule-then-always