-
Notifications
You must be signed in to change notification settings - Fork 8
350 lines (321 loc) · 14.2 KB
/
Copy pathgendoc-runtime.yaml
File metadata and controls
350 lines (321 loc) · 14.2 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
# Copyright 2026 FlagOS Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Generate docs for runtime images
# Post-build: verify each runtime image best-effort, compose a per-image
# description markdown (single source for the docs site, the in-repo
# runtime/<name>.md file, and the Harbor repository description), then
# commit + upload.
#
# Aligned with gendoc-base.yaml: the runtime description refresh uses the same
# upload-artifact transport, per-backend extract jobs on hardware runners, and
# self-healing retry loop. Verify counts in the PR body come from the extract
# jobs' real e2e verification (scripts/verify_runtime.py), not hand-entered
# workflow inputs.
#
# Manual-only (no workflow_run trigger): runtime images are rebuilt repeatedly
# during the FlagGems testing phase, so auto-triggering would produce noisy
# empty PRs.
#
# Transport: each extract job writes an empty version TSV and annotates it with
# metadata headers (run id, verify outcome) via scripts/annotate_version_tsv.py,
# then uploads it as a per-backend artifact (versions-<backend>) with
# upload-artifact. The TSV is a metadata carrier only — the description CONTENT
# is configs-driven: docs/gen_descriptions.py's render_runtime() does not read
# TSV data, so finalize regenerates it fresh from configs.yaml via gen_data.py.
# Accumulate downloads all matching artifacts with download-artifact, merges
# them, and saves the cumulative set to a git state branch
# (auto/versions-<label>-state) so retries don't lose already-collected data.
#
# Self-healing: self-hosted runner connectivity to GitHub is unreliable across
# vendors. The accumulate job collects whatever extractors succeed, saves partial
# results to the state branch, then self-triggers with only the missing backends.
# This loops until all are collected or the retry cap (50) is hit.
on:
workflow_dispatch:
inputs:
backend:
description: 'Backends to process — "all" or space-separated names'
type: string
default: 'all'
retry_count:
description: 'Number of retries so far (set by the workflow itself)'
type: number
default: 0
permissions:
contents: write
pull-requests: write
actions: write
defaults:
run:
shell: bash
jobs:
authorize:
# Only accounts listed in .github/builders.txt may trigger this workflow
# manually; see .github/actions/check-trigger-author for the check.
# actions/checkout is required: local composite actions are resolved from
# the workspace, so the repo must exist before the action step runs.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/check-trigger-author
set-matrix:
needs: authorize
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.m.outputs.matrix }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- run: python3 -m pip install --user pyyaml
- id: m
env:
BACKEND: ${{ github.event.inputs.backend || 'all' }}
run: |
if [[ "${BACKEND}" == "all" ]]; then
python3 scripts/generate_matrix.py --runtime > matrix.json
else
python3 scripts/generate_matrix.py --runtime ${BACKEND} > matrix.json
fi
echo "matrix=$(jq -c . matrix.json)" >> "$GITHUB_OUTPUT"
extract:
needs: set-matrix
# Self-hosted runners are best-effort. When a runner is unreachable
# (checkout / Harbor login / docker permissions), the job fails here.
# The accumulate job detects the gap and re-dispatches only that backend.
continue-on-error: true
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set-matrix.outputs.matrix) }}
runs-on: ${{ fromJSON(matrix.runson) }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install PyYAML
run: |
python3 -c "import yaml" 2>/dev/null \
|| python3 -m pip install --user --break-system-packages pyyaml
- name: Harbor login (for image pull)
env:
HARBOR_USER: ${{ secrets.HARBOR_USER }}
HARBOR_PW: ${{ secrets.HARBOR_PASSWORD }}
# Harbor is internal — bypass any HTTP_PROXY/HTTPS_PROXY the runner
# may have set for GitHub access, otherwise docker login routes
# Harbor traffic through the proxy and fails.
# Only uppercase HTTP_PROXY/HTTPS_PROXY (lowercase clash with runner
# env vars set by the GitHub Actions runner config).
HTTP_PROXY: ""
HTTPS_PROXY: ""
no_proxy: "harbor.baai.ac.cn,.baai.ac.cn"
run: |
host=$(python3 -c "import yaml;print(yaml.safe_load(open('.github/build-config.yml'))['registry']['host'])")
for i in 1 2 3; do
if printf '%s' "$HARBOR_PW" | docker login "$host" -u "$HARBOR_USER" --password-stdin; then
exit 0
fi
echo "Harbor login attempt $i failed, retrying in 30s..."
sleep 30
done
echo "::warning::Harbor login failed after 3 attempts — skipping ${{ matrix.name }}"
exit 1
- name: Verify runtime image (best-effort)
continue-on-error: true
id: verify
run: |
python3 docs/gen_data.py
python3 scripts/verify_runtime.py "${{ matrix.name }}"
# The TSV is a metadata transport only — description content is
# configs-driven and regenerated at finalize. An empty TSV still carries
# the # verify: outcome (real e2e result → PR body counts) and # run: id,
# and marks the backend as collected (annotate_version_tsv.py requires
# the file to exist; collect_version_tsvs.py counts .tsv files).
- name: Create version TSV (transport)
run: |
mkdir -p versions
: > "versions/${{ matrix.name }}.tsv"
- name: Record verify status
if: always()
run: |
mkdir -p versions
echo "${{ steps.verify.outcome }}" > "versions/${{ matrix.name }}.verify_outcome"
- name: Annotate version TSV
run: python3 scripts/annotate_version_tsv.py "${{ matrix.name }}" versions
- name: Upload version artifact
uses: actions/upload-artifact@v7
with:
name: versions-${{ matrix.name }}
path: versions/${{ matrix.name }}.tsv
if-no-files-found: warn
accumulate:
needs: [set-matrix, extract]
if: always() && needs.set-matrix.result == 'success'
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
RETRY_COUNT: ${{ github.event.inputs.retry_count || 0 }}
MAX_RETRIES: 50
outputs:
done: ${{ steps.collect.outputs.done }}
missing: ${{ steps.collect.outputs.missing }}
count: ${{ steps.collect.outputs.count }}
label: ${{ steps.collect.outputs.label }}
verify_ok: ${{ steps.collect.outputs.verify_ok }}
verify_fail: ${{ steps.collect.outputs.verify_fail }}
verify_skip: ${{ steps.collect.outputs.verify_skip }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- run: python3 -m pip install --user pyyaml
# merge-multiple flattens the per-backend artifact contents into
# versions-dl/<backend>.tsv, which collect_version_tsvs.py reads.
- name: Download version artifacts
continue-on-error: true
uses: actions/download-artifact@v8
with:
path: versions-dl
pattern: versions-*
merge-multiple: true
# Restore previously-collected TSVs from the state branch so that
# backends not refreshed this retry retain their data across runs.
# On retry=0 the state branch doesn't exist yet — that's fine, we
# start fresh.
# For scoped runs, only restore TSVs for the backends being collected.
- name: Restore state from previous retries
env:
GIT_AUTHOR_NAME: flagos-ci
GIT_AUTHOR_EMAIL: noreply@flagos.net
GIT_COMMITTER_NAME: flagos-ci
GIT_COMMITTER_EMAIL: noreply@flagos.net
SCOPE: ${{ github.event.inputs.backend || 'all' }}
run: |
label="$(python3 -c 'import yaml;print(yaml.safe_load(open("configs.yaml"))["version"])' 2>/dev/null || echo 'unknown')"
state_branch="auto/versions-${label}-state"
if git ls-remote --heads origin "refs/heads/${state_branch}" | grep -q refs; then
echo "Restoring state from ${state_branch}"
git fetch origin "${state_branch}"
mkdir -p versions
if [[ "${SCOPE}" == "all" ]]; then
git checkout FETCH_HEAD -- versions/
else
for bk in ${SCOPE}; do
f="versions/${bk}.tsv"
if git show "FETCH_HEAD:${f}" > "${f}" 2>/dev/null; then
echo " Restored ${bk}.tsv"
fi
done
fi
else
echo "No state branch (${state_branch}) — starting fresh"
mkdir -p versions
fi
# collect: merge TSVs → check completeness.
# State was restored above; this step overwrites any stale entries
# with freshly-downloaded data. Always exits 0 — the next step
# (Finalize or Retry) acts on the done/missing outputs.
- id: collect
env:
GIT_AUTHOR_NAME: flagos-ci
GIT_AUTHOR_EMAIL: noreply@flagos.net
GIT_COMMITTER_NAME: flagos-ci
GIT_COMMITTER_EMAIL: noreply@flagos.net
run: |
# Collect: merge TSVs → check completeness.
# Determine the expected backend set — the same scope set-matrix
# used, so scoped runs don't auto-retry for backends that were
# never requested.
SCOPE="${{ github.event.inputs.backend || 'all' }}"
if [[ "${SCOPE}" == "all" ]]; then
EXPECTED=""
else
EXPECTED="${SCOPE}"
fi
result=$(python3 scripts/collect_version_tsvs.py \
--versions versions --remote versions-dl \
--retry "${RETRY_COUNT:-0}" \
--expected "${EXPECTED}")
echo "$result"
# Parse JSON once, write each field to GITHUB_OUTPUT.
echo "$result" | python3 -c "
import sys, json
d = json.load(sys.stdin)
for k in ('done', 'count', 'label', 'missing',
'verify_ok', 'verify_fail', 'verify_skip'):
print(f'{k}={d[k]}')
" | tee -a "$GITHUB_OUTPUT"
# Persist collected TSVs to the state branch so they survive
# across retries (each accumulate runs on a fresh ubuntu-latest VM).
# Each save is a full snapshot of versions/ — no incremental merge.
- name: Save state for next retry
if: always() && steps.collect.outcome == 'success'
env:
GIT_AUTHOR_NAME: flagos-ci
GIT_AUTHOR_EMAIL: noreply@flagos.net
GIT_COMMITTER_NAME: flagos-ci
GIT_COMMITTER_EMAIL: noreply@flagos.net
run: |
label="$(python3 -c 'import yaml;print(yaml.safe_load(open("configs.yaml"))["version"])' 2>/dev/null || echo 'unknown')"
state_branch="auto/versions-${label}-state"
if [ ! -d versions ] || [ -z "$(ls -A versions 2>/dev/null)" ]; then
echo "No version data to save"
exit 0
fi
# Stage all TSV files so write-tree captures them (collect step
# copies them from versions-dl/ — they are untracked).
git add -f versions/*.tsv 2>/dev/null || true
# Build a tree of the versions/ directory contents, then wrap it
# in an outer tree so restore via checkout -- versions/ works.
inner_tree=$(git write-tree --prefix=versions/)
if [ -z "$inner_tree" ]; then
echo "Failed to create inner tree"
git restore --staged versions/ 2>/dev/null || true
exit 0
fi
outer_tree=$(printf "040000 tree %s\tversions" "$inner_tree" | git mktree)
# Use previous state commit as parent if it exists.
parent=""
if git ls-remote --heads origin "refs/heads/${state_branch}" | grep -q refs; then
parent=$(git rev-parse "origin/${state_branch}" 2>/dev/null || echo "")
fi
parent_opt=""
if [ -n "$parent" ]; then
parent_opt="-p $parent"
fi
commit=$(echo "state:${label}" | git commit-tree "$outer_tree" $parent_opt)
git push -f origin "${commit}:refs/heads/${state_branch}"
echo "Saved state to ${state_branch} (commit ${commit:0:12})"
# Unstage to keep working tree clean for the finalize step.
git restore --staged versions/ 2>/dev/null || true
- name: Finalize (descriptions + PR) or retry
if: always() && steps.collect.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
VERSIONS_DIR: ${{ github.workspace }}/versions
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
# collect poisons the index (git add -f versions/); unstage it.
git restore --staged .
git clean -fd -- versions-dl 2>/dev/null || true
python3 scripts/finalize_descriptions.py \
--mode runtime \
--done "${{ steps.collect.outputs.done }}" \
--count "${{ steps.collect.outputs.count || 0 }}" \
--label "${{ steps.collect.outputs.label || 'unknown' }}" \
--missing "${{ steps.collect.outputs.missing || '' }}" \
--verify-ok "${{ steps.collect.outputs.verify_ok || 0 }}" \
--verify-fail "${{ steps.collect.outputs.verify_fail || 0 }}" \
--verify-skip "${{ steps.collect.outputs.verify_skip || 0 }}" \
--retry "${{ env.RETRY_COUNT || 0 }}" \
--max-retries "${MAX_RETRIES:-50}"