Repository navigation
294 lines (285 loc) · 14.3 KB
/
Copy pathci.yml
File metadata and controls
294 lines (285 loc) · 14.3 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
name: CI
on:
push:
branches: [main]
pull_request:
# A MANUAL RUN. Orunbase's Run and Deploy buttons start this workflow on
# main with component names, an environment and the deploy record's id
# (the deploys contract: ci.yml on main; inputs component, environment,
# deploy_id); "Run workflow" in the Actions tab does the same by hand. The
# plan step plans those components in that environment under the
# push-to-main trigger, so each one runs exactly as a merge runs it: stage
# and prod apply and deploy, dev verifies. An empty `component` means
# every component in the environment, a redeploy with nothing changed.
workflow_dispatch:
inputs:
component:
description: "Component names, comma-separated (component.yaml metadata.name); empty for every component"
required: false
type: string
default: ""
environment:
description: "Target environment"
required: true
type: choice
options: [dev, stage, prod]
deploy_id:
description: "Orunbase deploy record (dpl_…), set by Orunbase; appears in the run name"
required: false
type: string
default: ""
# A manual run names itself after what it runs: Orunbase finds a deploy's run
# by the id in this name (GitHub's dispatch API returns no run id). Every
# other event keeps GitHub's default name (an empty run-name falls back to it).
run-name: ${{ github.event_name == 'workflow_dispatch' && format('Deploy {0} → {1} · {2}', inputs.component || 'every component', inputs.environment, inputs.deploy_id || 'by hand') || '' }}
# PR runs share a group per ref and superseded runs are cancelled (each
# push re-plans anyway), which stops stale fan-outs from starving the
# runner pool. Main pushes get a unique group each: convergence runs plan
# --changed per commit, and GitHub replaces *pending* runs in a shared
# group even with cancel-in-progress false — a superseded main run's
# components would silently never converge.
concurrency:
group: ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
packages: write
id-token: write
# A lane of several jobs posts one check run per job, named by the job's
# check title, so branch protection sees the same names as before lanes.
checks: write
jobs:
plan:
runs-on: ubuntu-latest
outputs:
lane-matrix: ${{ steps.matrix.outputs.lane-matrix }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
# A TREE THAT NAMES NO WORKSPACE PLANS NOTHING. `ws_CHANGE_ME` is the
# placeholder this repository ships with until someone links it; every
# remote op of a plan here would be refused, so the job says so and
# stops green, and `run` below has no lanes to start. A product built by
# an Orun bootstrap never carries the placeholder — the bootstrap writes
# the product's own workspace into intent.yaml — and a bootstrap that had no
# workspace to write leaves `ws_SET_ME`, which is NOT skipped: it fails
# here loudly rather than deploying nothing in silence.
#
# This replaced an `ORUN_CI` repository variable, which a bootstrap has
# no way to set: every product it built would have converged on nothing.
- id: linked
run: |
if grep -Eq '^[[:space:]]*workspace:[[:space:]]*ws_CHANGE_ME[[:space:]]*$' intent.yaml; then
echo "::notice title=Orun CI::intent.yaml names no Orun workspace (ws_CHANGE_ME) — nothing to plan. Link this repository (orun cloud link) and set execution.state.workspace to turn the pipeline on."
echo "linked=false" >> "$GITHUB_OUTPUT"
else
echo "linked=true" >> "$GITHUB_OUTPUT"
fi
- if: steps.linked.outputs.linked == 'true'
uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- if: steps.linked.outputs.linked == 'true'
env:
# Surface the best-effort catalog auto-sync (execution.state.autopushCatalog).
# A successful push prints "✓ pushed catalog …"; ORUN_VERBOSE also makes
# any skip/failure visible instead of silent.
ORUN_VERBOSE: "1"
# A manual run's selection, read from the environment, never
# interpolated into the script.
DISPATCH_COMPONENT: ${{ inputs.component }}
DISPATCH_ENVIRONMENT: ${{ inputs.environment }}
run: |
set -euo pipefail
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
# A MANUAL RUN plans under the push-to-main trigger: the profiles
# a merge runs, filtered to the environment and the components it
# names. Not --changed: a redeploy is asked for when nothing has
# changed. Main only, because that trigger deploys stage and prod.
if [ "$GITHUB_REF" != "refs/heads/main" ]; then
echo "::error title=Orun CI::A manual run deploys main only; this one was started on ${GITHUB_REF}."
exit 1
fi
plan_args=(
--trigger github-push-main
--env "$DISPATCH_ENVIRONMENT"
--intent intent.yaml
--output plan.json
)
if [ -n "${DISPATCH_COMPONENT//[[:space:],]/}" ]; then
# Keep the named components that have something to run in this
# environment. orun refuses the others as unmatched (a test
# suite has no job in prod), and a run of only those is nothing
# selected, not a failure: it stays green with no lanes, which
# Orunbase reads as nothing selected.
orun plan --trigger github-push-main --env "$DISPATCH_ENVIRONMENT" \
--intent intent.yaml --output env-plan.json --no-catalog-refresh >/dev/null
kept=0
IFS=',' read -ra picked <<< "$DISPATCH_COMPONENT"
for c in "${picked[@]}"; do
c="${c//[[:space:]]/}"
[ -z "$c" ] && continue
if ! [[ "$c" =~ ^[a-z0-9][a-z0-9._-]{0,99}$ ]]; then
echo "::error title=Orun CI::'$c' is not a component name (component.yaml metadata.name)."
exit 1
fi
if jq -e --arg c "$c" 'any(.jobs[]; .component == $c)' env-plan.json >/dev/null; then
plan_args+=(--component "$c")
kept=$((kept + 1))
else
echo "::notice title=Orun CI::$c has nothing to run in ${DISPATCH_ENVIRONMENT} (or is not a component); left out."
fi
done
if [ "$kept" = 0 ]; then
jq '.jobs = [] | .lanes = []' env-plan.json > plan.json
plan_args=()
fi
fi
else
plan_args=(
--from-ci github
--event-file "$GITHUB_EVENT_PATH"
--intent intent.yaml
--output plan.json
--changed
)
fi
if [ "${#plan_args[@]}" -gt 0 ]; then
orun plan "${plan_args[@]}"
fi
# A manual run that selects nothing runs nothing, and says so.
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ] && [ "$(jq '.jobs | length' plan.json)" = 0 ]; then
echo "::notice title=Orun CI::Nothing to run for ${DISPATCH_COMPONENT:-every component} in ${DISPATCH_ENVIRONMENT}."
fi
# One matrix entry per LANE (execution.lanes in intent.yaml). A plan
# without lanes gets one per job, exactly the old matrix, and
# `orun run --lane <job id>` on it is `--job <job id>`.
- id: matrix
if: steps.linked.outputs.linked == 'true'
run: |
echo "lane-matrix=$(jq -c 'if ((.lanes // []) | length) > 0
then [.lanes[] | {"lane": .id, "name": .name}]
else [.jobs[] | {"lane": .id, "name": .checkName}] end' plan.json)" >> "$GITHUB_OUTPUT"
- if: steps.linked.outputs.linked == 'true'
uses: actions/upload-artifact@v7
with:
name: orun-plan
path: plan.json
run:
needs: plan
runs-on: ubuntu-latest
# A BOOTSTRAP LANDING IS CHECKED BY `plan` ALONE. Every phase of an Orun
# bootstrap lands on a branch named for its task — the provenance
# pen's `orun/<KEY>-<slug>`, and the bootstrap's tasks are all `BASE-n` —
# and is merged by `orun.pr/land@v1` as soon as this workflow is green.
# On those pull requests `plan` above is the check: the intent, every
# component and every composition resolve, the changed set is computed,
# and the plan is uploaded. The lanes are not run there, because the merge
# runs every one of them again on main moments later, for real, and the
# bootstrap watches that convergence to green before the next phase — the
# PR pass was the same work twice, and a third of a bootstrap's wall-clock.
# Every other pull request runs its lanes exactly as before.
if: >-
${{ needs.plan.outputs.lane-matrix != '[]' && needs.plan.outputs.lane-matrix != ''
&& !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'orun/BASE-')) }}
strategy:
fail-fast: false
# Stagger the fan-out: every lane hits the lease-bound resolve at job
# start, and an unbounded herd (fifty lanes) saturated it twice. Sixteen
# keeps the herd well under that and is above execution.lanes.maxLanes
# (6), so a packed plan starts every lane at once; it only binds on a
# small plan that runs one lane per job. Inside a lane a job that waits
# on another lane holds no slot.
max-parallel: 16
matrix:
include: ${{ fromJson(needs.plan.outputs.lane-matrix) }}
name: ${{ matrix.name }}
env:
# One pnpm store for every lane, restored below. Each lane installs the
# whole workspace with --frozen-lockfile; without this every one of them
# downloaded all ~500 packages from the registry again.
npm_config_store_dir: /home/runner/.pnpm-store
PNPM_STORE_DIR: /home/runner/.pnpm-store
steps:
- uses: actions/checkout@v6
# Keyed by the lockfile alone, so every lane of every run shares one
# entry until a dependency changes. The first lane to finish saves it;
# the rest find the key taken and skip the save.
- name: pnpm store cache
uses: actions/cache@v4
with:
path: /home/runner/.pnpm-store
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-store-${{ runner.os }}-
- uses: actions/download-artifact@v8
with:
name: orun-plan
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
# exec-id is the RUN id alone (no attempt suffix): a `gh run rerun
# --failed` then RESUMES the same orun execution — jobs that succeeded in
# a prior attempt stay completed, so re-run lanes' cross-job dependencies
# are already satisfied instead of waiting forever on lanes that are not
# re-running (the partial-rerun deadlock). --retry re-opens THIS
# lane's failed jobs when they terminally failed in a prior attempt
# (no-op on first attempts); its completed jobs stay completed — together
# they make `gh run rerun --failed` a true resume.
- run: |
# --retry only on re-run attempts: on a fresh attempt a failed
# upstream is a genuine failure and dependents must fail fast; on a
# resume (gh run rerun --failed) the upstream's own retry lane will
# re-open it, so lanes wait out the race instead.
retry_flag=""
if [ "${GITHUB_RUN_ATTEMPT:-1}" -gt 1 ]; then retry_flag="--retry"; fi
# EVERY RUN REPORTS TO THE PLATFORM, a pull request's included.
#
# A PR lane resolves its secrets like any other (a verify lane still
# reads the wiring its fixture stands in for, an infra lane plans
# against the real account), and a job's secret refs are resolved
# before its first step whatever its profile does — so a PR run
# without remote state failed every lane that declares one:
#
# ✗ cloudflare-d1.stage.terraform: secret resolution failed: local
# runs resolve secrets only from ORUN_SECRET_<KEY> overrides
#
# and a phase's PR could never be verified before it merged. This
# used to drop the state flag on PRs, on the belief that the backend
# refuses a pull_request OIDC token by design. It does not: the
# exchange's only gate is the repo link's CI settings (oidcEnabled,
# allowedRefPattern, allowedEnvironments — identity-worker
# oidc-exchange.ts), and the resource-hidden `not_found` seen at the
# time is exactly what an UNLINKED repository answers, push or PR.
# Remote state on a PR also puts the PR's runs in front of the
# platform, which renders runs on refs/pull/<n> as that PR's row.
# Fork PRs get no OIDC token from GitHub at all and still fail
# closed. Nothing mutating runs here: deploy/apply profiles are gated
# on triggerRef github-push-main.
state_flag="--remote-state"
orun run \
--plan plan.json \
--runner github-actions \
$state_flag \
--lane "${{ matrix.lane }}" \
--exec-id "${{ github.run_id }}" \
$retry_flag
env:
# GITHUB_TOKEN is the only credential CI holds — GitHub-issued and
# ephemeral. Every provider credential (the Cloudflare token and
# account id — this product has no second provider) is an
# orun-managed secret:
# brokered fresh per run from the workspace's integrations, resolved
# lease-bound by the jobs that declare it (profile secretBindings or
# component secretEnv), and log-redacted. Nothing provider-shaped is
# stored in GitHub.
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_CONFIG: /home/runner/.docker