Repository navigation
352 lines (334 loc) · 15.5 KB
/
Copy pathtrigger-downstream.yml
File metadata and controls
352 lines (334 loc) · 15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# SPDX-FileCopyrightText: 1996- European Centre for Medium-Range Weather Forecasts (ECMWF)
# SPDX-License-Identifier: Apache-2.0
# GENERATED FILE - DO NOT EDIT.
# Regenerate via the ci-infrastructure-generate CLI.
# Source of truth: each repo's .ci/manifest.toml.
name: Downstream runner (metkit)
on:
workflow_run:
workflows:
- CI
- CI (fork)
types: [completed]
workflow_dispatch:
inputs:
pull-request:
description: Number of the pull request whose commit to run downstream CI for
required: true
type: string
level:
description: '''all'', or the highest consumer level to run (as the run-downstream-ci labels)'
required: true
default: '1'
type: string
concurrency:
group: trigger-downstream-runner-${{ (github.event.workflow_run.name == 'CI (fork)' && github.event.workflow_run.display_title) || github.event.workflow_run.head_sha || inputs.pull-request }}
cancel-in-progress: true
jobs:
ci-approval:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: ecmwf/ci-infrastructure/actions/require-ci-approval@main
context:
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: read
outputs:
head-sha: ${{ steps.ctx.outputs.head-sha }}
head-branch: ${{ steps.ctx.outputs.head-branch }}
ci-conclusion: ${{ steps.ctx.outputs.ci-conclusion }}
ci-url: ${{ steps.ctx.outputs.ci-url }}
ci-run-id: ${{ steps.ctx.outputs.ci-run-id }}
ci-summary: ${{ steps.ctx.outputs.ci-summary }}
pull-request: ${{ steps.ctx.outputs.pull-request }}
hpc-only: ${{ steps.ctx.outputs.hpc-only }}
steps:
- name: Resolve the commit under test
id: ctx
uses: ecmwf/ci-infrastructure/actions/resolve-dispatch-context@main
with:
pull-request: ${{ inputs.pull-request }}
fork-ci-workflow: ci-fork.yml
needs: [ci-approval]
label-gate:
if: needs.context.outputs.hpc-only != 'true'
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
run: ${{ steps.gate.outputs.run }}
depth: ${{ steps.gate.outputs.depth }}
steps:
- name: Check the downstream-CI label
id: gate
uses: ecmwf/ci-infrastructure/actions/should-downstream-run@main
with:
sha: ${{ needs.context.outputs.head-sha }}
pull-request: ${{ needs.context.outputs.pull-request }}
level: ${{ inputs.level }}
needs: [ci-approval, context]
validate:
if: ${{ (needs.context.outputs.ci-conclusion == 'success') && needs['label-gate'].outputs.run == 'true' }}
runs-on: ubuntu-latest
steps:
- id: mint
uses: ecmwf/ci-infrastructure/actions/mint-token@main
with:
client-id: ${{ secrets.CI_READER_APP_CLIENT_ID }}
private-key: ${{ secrets.CI_READER_APP_PRIVATE_KEY }}
repositories: "*"
permissions: contents:read actions:read
- uses: actions/checkout@v6
with:
ref: ${{ needs.context.outputs.head-sha }}
token: ${{ steps.mint.outputs.token }}
persist-credentials: false
allow-unsafe-pr-checkout: true
- uses: ecmwf/ci-infrastructure/actions/validate-generated-workflows@main
with:
token: ${{ steps.mint.outputs.token }}
needs: [ci-approval, context, label-gate]
resolve:
if: ${{ (needs.context.outputs.ci-conclusion == 'success') && needs['label-gate'].outputs.run == 'true' }}
needs: [ci-approval, context, label-gate, validate]
runs-on: ubuntu-latest
env:
ARTIFACT_S3_ENDPOINT: ${{ secrets.ARTIFACT_S3_ENDPOINT }}
ARTIFACT_S3_BUCKET: ${{ secrets.ARTIFACT_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
outputs:
fdb: ${{ steps.r-fdb.outcome == 'success' && steps.r-fdb.outputs.json || '' }}
fdb-ref: ${{ steps.r-fdb.outcome == 'success' && steps.r-fdb.outputs.own-sha || '' }}
gribjump: ${{ steps.r-gribjump.outcome == 'success' && steps.r-gribjump.outputs.json || '' }}
gribjump-ref: ${{ steps.r-gribjump.outcome == 'success' && steps.r-gribjump.outputs.own-sha || '' }}
pins: ${{ steps.pins.outputs.pins }}
dispatch-plans: ${{ steps.plans.outputs.dispatch-plans }}
steps:
- id: mint
uses: ecmwf/ci-infrastructure/actions/mint-token@main
with:
client-id: ${{ secrets.CI_READER_APP_CLIENT_ID }}
private-key: ${{ secrets.CI_READER_APP_PRIVATE_KEY }}
repositories: ecbuild,eccodes,eckit,fdb,gribjump,metkit,stack-dependencies
permissions: contents:read actions:read
- name: Pin the commits the upstream's CI resolved
env:
GH_TOKEN: ${{ steps.mint.outputs.token }}
HEAD_SHA: ${{ needs.context.outputs.head-sha }}
CI_RUN_ID: ${{ needs.context.outputs.ci-run-id }}
run: "set -euo pipefail\npins=\"${GITHUB_REPOSITORY}@${HEAD_SHA}\"\ndir=\"${RUNNER_TEMP}/resolved-pins\"\nif [ -n \"${CI_RUN_ID}\" ] && gh run download \"${CI_RUN_ID}\" --repo \"${GITHUB_REPOSITORY}\" \\\n --name resolved-pins --dir \"$dir\" 2>/dev/null; then\n while read -r pin; do\n if [[ \"$pin\" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+@[0-9a-f]{40}$ ]] && [[ \"$pin\" != \"${GITHUB_REPOSITORY}@\"* ]]; then\n pins=\"$pins $pin\"\n fi\n done < <(tr ' ' '\\n' < \"$dir/pins.txt\")\n echo \"Starting from the commits run ${CI_RUN_ID} resolved: $pins\"\nelse\n echo \"::notice::No resolved-pins artifact on CI run '${CI_RUN_ID}'; the other repos resolve at their branch tips.\"\nfi\necho \"PINS=$pins\" >> \"$GITHUB_ENV\"\necho \"EXPECTED=\" >> \"$GITHUB_ENV\"\n"
- id: pick-fdb
if: (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 1)
uses: ecmwf/ci-infrastructure/actions/pick-ref@main
with:
repo: ecmwf/fdb
try-branch: ${{ needs.context.outputs.head-branch }}
fallback-ref: develop
token: ${{ steps.mint.outputs.token }}
- if: (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 1)
uses: actions/checkout@v6
with:
repository: ecmwf/fdb
ref: ${{ steps.pick-fdb.outputs.ref }}
token: ${{ steps.mint.outputs.token }}
persist-credentials: false
path: .downstream/fdb
sparse-checkout: .ci
- name: Resolve fdb
id: r-fdb
if: (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 1)
continue-on-error: true
uses: ecmwf/ci-infrastructure/actions/resolve-deps@main
with:
manifest: .downstream/fdb/.ci/manifest.toml
current-branch: ${{ steps.pick-fdb.outputs.ref }}
pin: ${{ env.PINS }}
expected-artifacts: ${{ env.EXPECTED }}
matrix: build,python
token: ${{ steps.mint.outputs.token }}
rebuild-missing: 'true'
- name: Carry fdb's commits to the next consumer
if: steps.r-fdb.outcome == 'success'
env:
R_PINS: ${{ steps.r-fdb.outputs.pins }}
R_ARTIFACTS: ${{ steps.r-fdb.outputs.artifacts }}
run: 'echo "PINS=${R_PINS}" >> "$GITHUB_ENV"
echo "EXPECTED=${EXPECTED} ${R_ARTIFACTS}" >> "$GITHUB_ENV"'
- id: pick-gribjump
if: (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 2)
uses: ecmwf/ci-infrastructure/actions/pick-ref@main
with:
repo: ecmwf/gribjump
try-branch: ${{ needs.context.outputs.head-branch }}
fallback-ref: develop
token: ${{ steps.mint.outputs.token }}
- if: (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 2)
uses: actions/checkout@v6
with:
repository: ecmwf/gribjump
ref: ${{ steps.pick-gribjump.outputs.ref }}
token: ${{ steps.mint.outputs.token }}
persist-credentials: false
path: .downstream/gribjump
sparse-checkout: .ci
- name: Resolve gribjump
id: r-gribjump
if: (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 2)
continue-on-error: true
uses: ecmwf/ci-infrastructure/actions/resolve-deps@main
with:
manifest: .downstream/gribjump/.ci/manifest.toml
current-branch: ${{ steps.pick-gribjump.outputs.ref }}
pin: ${{ env.PINS }}
expected-artifacts: ${{ env.EXPECTED }}
matrix: build,python
token: ${{ steps.mint.outputs.token }}
rebuild-missing: 'true'
- name: Carry gribjump's commits to the next consumer
if: steps.r-gribjump.outcome == 'success'
env:
R_PINS: ${{ steps.r-gribjump.outputs.pins }}
R_ARTIFACTS: ${{ steps.r-gribjump.outputs.artifacts }}
run: 'echo "PINS=${R_PINS}" >> "$GITHUB_ENV"
echo "EXPECTED=${EXPECTED} ${R_ARTIFACTS}" >> "$GITHUB_ENV"'
- id: pins
run: echo "pins=${PINS}" >> "$GITHUB_OUTPUT"
- id: plans
env:
PLANS_0: ${{ steps.r-fdb.outputs.dispatch-plans || '[]' }}
PLANS_1: ${{ steps.r-gribjump.outputs.dispatch-plans || '[]' }}
run: 'plans=$(printf ''%s\n'' "${PLANS_0}" "${PLANS_1}" | jq -cs ''add // []'')
echo "dispatch-plans=${plans}" >> "$GITHUB_OUTPUT"'
rebuild-producers:
needs: [ci-approval, context, label-gate, resolve]
runs-on: ubuntu-latest
steps:
- if: needs.resolve.outputs.dispatch-plans != '' && needs.resolve.outputs.dispatch-plans != '[]'
uses: ecmwf/ci-infrastructure/actions/dispatch-producers@main
with:
dispatch-plans: ${{ needs.resolve.outputs.dispatch-plans }}
repositories: ecbuild,eccodes,eckit,fdb,gribjump,metkit,stack-dependencies
client-id: ${{ secrets.CI_DISPATCHER_APP_CLIENT_ID }}
app-private-key: ${{ secrets.CI_DISPATCHER_APP_PRIVATE_KEY }}
if: ${{ needs['label-gate'].outputs.run == 'true' }}
report-start:
if: ${{ (needs.context.outputs.ci-conclusion == 'success') && needs['label-gate'].outputs.run == 'true' }}
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Post pending downstream status
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api -X POST \
"/repos/${{ github.repository }}/statuses/${{ needs.context.outputs.head-sha }}" \
-f state=pending \
-f context='downstream/runner' \
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-f description='Downstream runner tests running'
needs: [ci-approval, context, label-gate]
report-ci-failure:
if: ${{ (needs.context.outputs.ci-conclusion != 'success' && needs.context.outputs.ci-conclusion != '') && needs['label-gate'].outputs.run == 'true' }}
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Post downstream failure status
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api -X POST \
"/repos/${{ github.repository }}/statuses/${{ needs.context.outputs.head-sha }}" \
-f state=failure \
-f context='downstream/runner' \
-f target_url="${{ needs.context.outputs.ci-url }}" \
-f description="${{ needs.context.outputs.ci-summary }}; downstream runner not run"
needs: [ci-approval, context, label-gate]
fdb:
name: fdb
needs: [ci-approval, context, label-gate, validate, resolve, rebuild-producers]
if: ${{ (!cancelled() && !failure() && needs['validate'].result == 'success' && needs['resolve'].result == 'success') && needs['label-gate'].outputs.run == 'true' && (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 1) }}
uses: ecmwf/fdb/.github/workflows/cross-repo-trigger.yml@develop
with:
from-repo: ${{ github.repository }}
from-sha: ${{ needs.context.outputs.head-sha }}
from-jobs: '["metkit/build"]'
branch: ${{ needs.context.outputs.head-branch }}
fallback-ref: develop
pin: ${{ needs.resolve.outputs.pins }}
resolved: ${{ needs.resolve.outputs.fdb }}
resolved-ref: ${{ needs.resolve.outputs.fdb-ref }}
secrets: inherit
gribjump:
name: gribjump
needs: [ci-approval, context, label-gate, validate, resolve, rebuild-producers, fdb]
if: ${{ (!cancelled() && !failure() && needs['validate'].result == 'success' && needs['resolve'].result == 'success' && needs['fdb'].result == 'success') && needs['label-gate'].outputs.run == 'true' && (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 2) }}
uses: ecmwf/gribjump/.github/workflows/cross-repo-trigger.yml@develop
with:
from-repo: ${{ github.repository }}
from-sha: ${{ needs.context.outputs.head-sha }}
from-jobs: '["metkit/build"]'
branch: ${{ needs.context.outputs.head-branch }}
fallback-ref: develop
pin: ${{ needs.resolve.outputs.pins }}
resolved: ${{ needs.resolve.outputs.gribjump }}
resolved-ref: ${{ needs.resolve.outputs.gribjump-ref }}
secrets: inherit
zfdb:
name: zfdb
needs: [ci-approval, context, label-gate, validate, resolve, gribjump]
runs-on: ubuntu-latest
steps:
- id: mint
uses: ecmwf/ci-infrastructure/actions/mint-token@main
with:
client-id: ${{ secrets.CI_DISPATCHER_APP_CLIENT_ID }}
private-key: ${{ secrets.CI_DISPATCHER_APP_PRIVATE_KEY }}
repositories: zfdb
permissions: actions:write
- name: Dispatch zfdb (private consumer)
uses: ecmwf/ci-infrastructure/actions/dispatch-and-wait@main
with:
consumer-repo: ecmwf/zfdb
ref: develop
from-repo: ${{ github.repository }}
from-sha: ${{ needs.context.outputs.head-sha }}
from-jobs: '["metkit/build"]'
branch: ${{ needs.context.outputs.head-branch }}
fallback-ref: develop
pin: ${{ needs.resolve.outputs.pins }}
token: ${{ steps.mint.outputs.token }}
artifact-names: ''
wait-for-run-conclusion: 'true'
if: ${{ needs['label-gate'].outputs.run == 'true' && (needs['label-gate'].outputs.depth == 'all' || needs['label-gate'].outputs.depth >= 3) }}
report-result:
needs: [ci-approval, context, label-gate, validate, fdb, gribjump, zfdb]
if: ${{ (always() && needs.context.outputs.ci-conclusion == 'success') && needs['label-gate'].outputs.run == 'true' }}
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Post final downstream status
env:
GH_TOKEN: ${{ github.token }}
run: |
state=success
for r in ${{ needs.validate.result }} ${{ needs.fdb.result }} ${{ needs.gribjump.result }} ${{ needs.zfdb.result }}; do
if [ "$r" = failure ] || [ "$r" = cancelled ]; then
state=failure
fi
done
depth="${{ needs['label-gate'].outputs.depth }}"
scope=""
if [ "$depth" != all ]; then scope=" (up to level $depth)"; fi
gh api -X POST \
"/repos/${{ github.repository }}/statuses/${{ needs.context.outputs.head-sha }}" \
-f state="$state" \
-f context='downstream/runner' \
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-f description="Downstream runner tests $state$scope"