-
Notifications
You must be signed in to change notification settings - Fork 0
301 lines (271 loc) · 11.4 KB
/
Copy pathrollout-deploy-docs.yml
File metadata and controls
301 lines (271 loc) · 11.4 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
name: Rollout Deploy Docs Workflow
# Pushes the shared deploy-docs caller (examples/deploy-docs.yml) to the
# docs-build branch of every Spring Cloud project in config/projects.json.
#
# Defaults to a dry run. Set dry_run to false to actually commit and push.
#
# See README-rollout-deploy-docs.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: 'Update commercial, oss, or both?'
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
enable_workflow:
description: 'Enable the Deploy Docs workflow if it is disabled'
required: false
type: boolean
default: true
actions_ref:
description: 'Tag or SHA of the shared deploy-docs workflow from this repo to use'
required: false
type: string
default: 'main'
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 }}
skipped: ${{ steps.build-matrix.outputs.skipped }}
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:
GH_TOKEN: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
PROJECTS_FILTER: ${{ inputs.projects }}
REPO_TYPE: ${{ inputs.repo_type }}
DOCS_BRANCH: 'docs-build'
run: |
node - << 'JSEOF'
const { execFileSync } = require('child_process');
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];
const docsBranch = (process.env.DOCS_BRANCH || 'docs-build').trim();
// Collect candidate repositories from projects.json.
const candidates = [];
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;
candidates.push({
repo: typeKey === 'commercial'
? `spring-cloud/${projectKey}-commercial`
: `spring-cloud/${projectKey}`,
type: typeKey,
});
}
}
// Only keep repositories that actually have a docs build branch.
// Everything dropped is listed explicitly rather than silently
// disappearing from the matrix.
const entries = [];
const skipped = [];
for (const candidate of candidates) {
try {
execFileSync('gh', [
'api', `repos/${candidate.repo}/branches/${docsBranch}`, '--jq', '.name',
], { encoding: 'utf8', stdio: 'pipe' });
entries.push(candidate);
} catch (err) {
skipped.push(candidate.repo);
}
}
entries.sort((a, b) => a.repo.localeCompare(b.repo));
console.log(`Repositories with a '${docsBranch}' branch: ${entries.length}`);
for (const entry of entries) console.log(` ${entry.repo} (${entry.type})`);
if (skipped.length) {
console.log(`\nSkipped - no '${docsBranch}' branch (or not accessible): ${skipped.length}`);
for (const repo of skipped) console.log(` ${repo}`);
}
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, `skipped=${JSON.stringify(skipped)}\n`);
JSEOF
sync:
name: "Sync — ${{ matrix.repo }}"
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:
# 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: Sync deploy-docs workflow
id: sync
uses: ./.github/actions/sync-deploy-docs-workflow
with:
repository: ${{ matrix.repo }}
actions-ref: ${{ inputs.actions_ref }}
dry-run: ${{ inputs.dry_run }}
enable-workflow: ${{ inputs.enable_workflow }}
token: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
- name: Record result
if: always()
id: record
env:
REPO: ${{ matrix.repo }}
TYPE: ${{ matrix.type }}
CHANGED: ${{ steps.sync.outputs.changed }}
STATUS: ${{ steps.sync.outputs.status }}
WORKFLOW_STATE: ${{ steps.sync.outputs.workflow-state }}
OUTCOME: ${{ steps.sync.outcome }}
run: |
set -euo pipefail
safe="${REPO//\//-}"
echo "safe-name=${safe}" >> "$GITHUB_OUTPUT"
jq -n \
--arg repo "$REPO" \
--arg type "$TYPE" \
--arg status "${STATUS:-failed}" \
--arg workflowState "${WORKFLOW_STATE:-unknown}" \
--arg outcome "$OUTCOME" \
--argjson changed "${CHANGED:-false}" \
'{repo: $repo, type: $type, status: $status, workflowState: $workflowState, 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 }}
SKIPPED: ${{ needs.setup.outputs.skipped }}
DOCS_BRANCH: 'docs-build'
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));
} 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-branch' ? '⏭️'
: '✅';
const lines = [];
lines.push(dryRun ? '## Rollout summary (dry run — nothing pushed)' : '## Rollout summary');
lines.push('');
lines.push('| | Repository | Type | File | Workflow |');
lines.push('|---|---|---|---|---|');
for (const r of results) {
const workflow = r.workflowState === 'enabled' ? '🔓 enabled'
: r.workflowState === 'already-active' ? 'active'
: r.workflowState || 'unknown';
lines.push(`| ${icon(r)} | \`${r.repo}\` | ${r.type} | ` +
`${r.outcome !== 'success' ? 'failed' : r.status} | ${workflow} |`);
}
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 enabled = results.filter(r => r.workflowState === 'enabled');
const wouldEnable = results.filter(r => (r.workflowState || '').startsWith('would-enable'));
lines.push(`**${results.length}** repositories processed — ` +
`**${changed.length}** ${dryRun ? 'would change' : 'changed'}, ` +
`**${unchanged.length}** already up to date, ` +
`**${failed.length}** failed.`);
const enableCount = dryRun ? wouldEnable.length : enabled.length;
if (enableCount) {
lines.push('');
lines.push(`**${enableCount}** disabled workflows ${dryRun ? 'would be' : 'were'} enabled. ` +
'GitHub keys a workflow by path, so this also re-enables the same-named ' +
'trigger workflow on the source branches.');
}
if (failed.length) {
lines.push('');
lines.push('Failed: ' + failed.map(r => `\`${r.repo}\``).join(', '));
}
// Repositories dropped before the matrix was built never produce a
// result artifact, so carry them through from the setup job rather
// than leaving them buried in that job's log.
let skipped = [];
try {
skipped = JSON.parse(process.env.SKIPPED || '[]');
} catch (err) {
console.log(`Could not parse skipped list: ${err.message}`);
}
const docsBranch = process.env.DOCS_BRANCH || 'docs-build';
lines.push('');
lines.push(`### Skipped — no \`${docsBranch}\` branch`);
lines.push('');
if (skipped.length) {
lines.push('| | Repository |');
lines.push('|---|---|');
for (const repo of skipped.slice().sort()) lines.push(`| ⏭️ | \`${repo}\` |`);
lines.push('');
lines.push(`**${skipped.length}** repositories were not processed.`);
} else {
lines.push(`None — every repository in \`projects.json\` has a \`${docsBranch}\` branch.`);
}
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, lines.join('\n') + '\n');
console.log(lines.join('\n'));
if (failed.length) process.exit(1);
JSEOF