-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollout-deploy-docs-trigger.yml
More file actions
288 lines (257 loc) · 10.9 KB
/
Copy pathrollout-deploy-docs-trigger.yml
File metadata and controls
288 lines (257 loc) · 10.9 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
name: Rollout Deploy Docs Trigger
run-name: ${{ format('{0} ({1})', github.workflow, inputs.projects || 'all') }}
# Pushes the canonical Deploy Docs trigger (examples/deploy-docs-trigger.yml) to
# every source branch listed in config/projects.json that already has one.
#
# Branches without a trigger workflow are skipped, never created.
#
# Defaults to a dry run. Set dry_run to false to actually commit and push.
#
# See README-rollout-deploy-docs-trigger.md for details.
on:
workflow_dispatch:
inputs:
projects:
description: 'Comma-separated list of Spring Cloud project names to run against (e.g. spring-cloud-build,spring-cloud-config). When empty, all projects in projects.json are processed.'
required: false
type: string
default: ''
repo_type:
description: 'Which repository flavors to update'
required: false
type: choice
default: 'both'
options:
- both
- oss
- commercial
dry_run:
description: 'Dry run, if checked no changes will be committed, but you can see what would be updated'
required: false
type: boolean
default: true
token:
description: 'GitHub token with write access to all target repos. Falls back to GH_ACTIONS_REPO_TOKEN.'
required: false
type: string
default: ''
permissions:
contents: read
jobs:
setup:
name: Build Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-matrix.outputs.matrix }}
count: ${{ steps.build-matrix.outputs.count }}
excluded: ${{ steps.build-matrix.outputs.excluded }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Avoid persisting this repository's GITHUB_TOKEN as a git
# extraheader; it would override the credentials the sync action
# uses when talking to the target repositories.
persist-credentials: false
- name: Build matrix
id: build-matrix
env:
PROJECTS_FILTER: ${{ inputs.projects }}
REPO_TYPE: ${{ inputs.repo_type }}
run: |
node - << 'JSEOF'
const fs = require('fs');
const projects = JSON.parse(fs.readFileSync('config/projects.json', 'utf8'));
const filterRaw = (process.env.PROJECTS_FILTER || '').trim();
const filter = filterRaw
? new Set(filterRaw.split(',').map(p => p.trim()).filter(Boolean))
: new Set();
const repoType = (process.env.REPO_TYPE || 'both').trim();
const typeKeys = repoType === 'both' ? ['oss', 'commercial'] : [repoType];
// release/ branches and -internal branches are excluded: they are
// short-lived or private-facing and are not published as docs.
const isExcluded = branch =>
branch.startsWith('release/') || branch.endsWith('-internal');
// One entry per repository x scheduled branch. Whether a branch
// actually has a trigger workflow is decided by the sync action,
// which skips (never creates) when the file is absent.
const entries = [];
const excluded = [];
for (const [projectKey, config] of Object.entries(projects)) {
if (projectKey === 'defaults') continue;
if (filter.size > 0 && !filter.has(projectKey)) continue;
for (const typeKey of typeKeys) {
if (!config[typeKey]) continue;
const repo = typeKey === 'commercial'
? `spring-cloud/${projectKey}-commercial`
: `spring-cloud/${projectKey}`;
for (const branch of (config[typeKey].branches || {}).scheduled || []) {
if (isExcluded(branch)) {
excluded.push({ repo, branch });
continue;
}
entries.push({ repo, branch, type: typeKey });
}
}
}
entries.sort((a, b) =>
a.repo.localeCompare(b.repo) || a.branch.localeCompare(b.branch));
console.log(`Repository/branch pairs to process: ${entries.length}`);
for (const e of entries) console.log(` ${e.repo} @ ${e.branch} (${e.type})`);
// Listed rather than silently dropped, so the excluded set stays visible.
if (excluded.length) {
console.log(`\nExcluded - release/ or -internal branch: ${excluded.length}`);
for (const e of excluded) console.log(` ${e.repo} @ ${e.branch}`);
}
fs.appendFileSync(process.env.GITHUB_OUTPUT,
`matrix=${JSON.stringify({ include: entries })}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `count=${entries.length}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT,
`excluded=${JSON.stringify(excluded)}\n`);
JSEOF
sync:
name: "Sync — ${{ matrix.repo }} @ ${{ matrix.branch }}"
needs: setup
if: needs.setup.outputs.count != '0'
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 8
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Sync deploy-docs trigger
id: sync
uses: ./.github/actions/sync-deploy-docs-trigger
with:
repository: ${{ matrix.repo }}
branch: ${{ matrix.branch }}
dry-run: ${{ inputs.dry_run }}
token: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
- name: Record result
if: always()
id: record
env:
REPO: ${{ matrix.repo }}
BRANCH: ${{ matrix.branch }}
TYPE: ${{ matrix.type }}
CHANGED: ${{ steps.sync.outputs.changed }}
STATUS: ${{ steps.sync.outputs.status }}
OUTCOME: ${{ steps.sync.outcome }}
run: |
set -euo pipefail
safe="${REPO//\//-}-${BRANCH//\//-}"
safe="${safe//./-}"
echo "safe-name=${safe}" >> "$GITHUB_OUTPUT"
jq -n \
--arg repo "$REPO" \
--arg branch "$BRANCH" \
--arg type "$TYPE" \
--arg status "${STATUS:-failed}" \
--arg outcome "$OUTCOME" \
--argjson changed "${CHANGED:-false}" \
'{repo: $repo, branch: $branch, type: $type, status: $status, outcome: $outcome, changed: $changed}' \
> "result-${safe}.json"
- name: Upload result
if: always()
uses: actions/upload-artifact@v4
with:
name: result-${{ steps.record.outputs.safe-name }}
path: result-${{ steps.record.outputs.safe-name }}.json
summary:
name: Summary
needs: [setup, sync]
runs-on: ubuntu-latest
if: always()
steps:
- name: Download results
uses: actions/download-artifact@v4
with:
pattern: result-*
merge-multiple: true
path: results
- name: Write summary
env:
DRY_RUN: ${{ inputs.dry_run }}
EXCLUDED: ${{ needs.setup.outputs.excluded }}
run: |
node - << 'JSEOF'
const fs = require('fs');
let results = [];
try {
results = fs.readdirSync('results')
.filter(f => f.endsWith('.json'))
.map(f => JSON.parse(fs.readFileSync(`results/${f}`, 'utf8')))
.sort((a, b) =>
a.repo.localeCompare(b.repo) || a.branch.localeCompare(b.branch));
} catch (err) {
console.log('No results to summarize.');
}
const dryRun = (process.env.DRY_RUN || 'false') === 'true';
const icon = r => r.outcome !== 'success' ? '❌'
: r.status === 'unchanged' ? '➖'
: r.status === 'skipped-no-trigger' ? '⏭️'
: r.status === 'skipped-no-branch' ? '⏭️'
: '✅';
const lines = [];
lines.push(dryRun ? '## Trigger rollout summary (dry run — nothing pushed)'
: '## Trigger rollout summary');
lines.push('');
lines.push('| | Repository | Branch | Type | Result |');
lines.push('|---|---|---|---|---|');
for (const r of results) {
lines.push(`| ${icon(r)} | \`${r.repo}\` | \`${r.branch}\` | ${r.type} | ` +
`${r.outcome !== 'success' ? 'failed' : r.status} |`);
}
lines.push('');
const failed = results.filter(r => r.outcome !== 'success');
const changed = results.filter(r => r.outcome === 'success' && r.changed);
const unchanged = results.filter(r => r.status === 'unchanged');
const noTrigger = results.filter(r => r.status === 'skipped-no-trigger');
const noBranch = results.filter(r => r.status === 'skipped-no-branch');
lines.push(`**${results.length}** branches processed — ` +
`**${changed.length}** ${dryRun ? 'would change' : 'changed'}, ` +
`**${unchanged.length}** already up to date, ` +
`**${noTrigger.length}** skipped (no trigger workflow), ` +
`**${noBranch.length}** skipped (branch missing), ` +
`**${failed.length}** failed.`);
if (noTrigger.length) {
lines.push('');
lines.push('### Skipped — no trigger workflow on the branch');
lines.push('');
lines.push('These branches are deliberately not built; the rollout never creates the file.');
lines.push('');
for (const r of noTrigger) lines.push(`- \`${r.repo}\` @ \`${r.branch}\``);
}
// Excluded before the matrix was built, so these never produce a
// result artifact - carry them through from the setup job rather
// than leaving them buried in that job's log.
let excluded = [];
try {
excluded = JSON.parse(process.env.EXCLUDED || '[]');
} catch (err) {
console.log(`Could not parse excluded list: ${err.message}`);
}
lines.push('');
lines.push('### Excluded — `release/` or `-internal` branch');
lines.push('');
if (excluded.length) {
lines.push('These are not published as docs and are never targeted by this rollout.');
lines.push('');
for (const e of excluded) lines.push(`- \`${e.repo}\` @ \`${e.branch}\``);
lines.push('');
lines.push(`**${excluded.length}** branches excluded.`);
} else {
lines.push('None — no `release/` or `-internal` branches in `projects.json`.');
}
if (failed.length) {
lines.push('');
lines.push('Failed: ' + failed.map(r => `\`${r.repo}@${r.branch}\``).join(', '));
}
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, lines.join('\n') + '\n');
console.log(lines.join('\n'));
if (failed.length) process.exit(1);
JSEOF