-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-github-actions-workflow-generator.yml
More file actions
283 lines (256 loc) · 11 KB
/
Copy pathrun-github-actions-workflow-generator.yml
File metadata and controls
283 lines (256 loc) · 11 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
name: Run GitHub Actions Workflow Generator
on:
workflow_dispatch:
inputs:
generator-version:
description: 'Version of github-actions-workflow-generator to use (e.g. 0.0.5). Defaults to latest release.'
required: false
type: string
default: ''
sha:
description: 'Commit SHA of this repo to copy release-train action files from. Defaults to the commit that triggered this workflow.'
required: false
type: string
default: ''
spring-release:
description: 'Spring release train version (e.g. 2026.1). When set, also processes release/[version] branches found in the spring-io/release-train README.adoc for that version.'
required: false
type: string
default: ''
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: ''
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 }}
generator-version: ${{ steps.find-generator.outputs.version }}
generator-url: ${{ steps.find-generator.outputs.url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Find generator version and download URL
id: find-generator
env:
GH_TOKEN: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
run: |
if [[ -n "${{ inputs.generator-version }}" ]]; then
version="${{ inputs.generator-version }}"
tag="v${version}"
else
response=$(gh api repos/spring-io/github-actions-workflow-generator/releases/latest)
tag=$(echo "$response" | jq -r '.tag_name')
version="${tag#v}"
fi
url="https://github.com/spring-io/github-actions-workflow-generator/releases/download/${tag}/github-actions-workflow-generator-${version}.jar"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "url=${url}" >> "$GITHUB_OUTPUT"
echo "Generator version : ${version}"
echo "Download URL : ${url}"
- name: Build matrix
id: build-matrix
env:
GH_TOKEN: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
SPRING_RELEASE: ${{ inputs.spring-release }}
PROJECTS_FILTER: ${{ inputs.projects }}
run: |
node - << 'JSEOF'
const { execFileSync } = require('child_process');
const fs = require('fs');
// Fetch projects.json from the main branch
const b64 = execFileSync('gh', [
'api', 'repos/spring-cloud/spring-cloud-github-actions/contents/config/projects.json',
'-X', 'GET', '-f', 'ref=main', '--jq', '.content'
], { encoding: 'utf8' }).trim();
const projects = JSON.parse(Buffer.from(b64, 'base64').toString('utf8'));
const defaults = projects.defaults || {};
const projectsFilterRaw = (process.env.PROJECTS_FILTER || '').trim();
const projectsFilter = projectsFilterRaw
? new Set(projectsFilterRaw.split(',').map(p => p.trim()).filter(Boolean))
: new Set();
function getJdks(projectKey, typeKey, branch) {
const typeCfg = (projects[projectKey] || {})[typeKey] || {};
const jdkmap = typeCfg.jdkVersions || {};
if (jdkmap[branch]) return jdkmap[branch];
if (jdkmap['default']) return jdkmap['default'];
const defJdkmap = (defaults[typeKey] || {}).jdkVersions || {};
if (defJdkmap[branch]) return defJdkmap[branch];
return defJdkmap['default'] || ['17', '21', '25'];
}
function primaryJdk(jdks) {
return jdks.includes('8') ? '8' : '17';
}
const entries = [];
const seen = new Set();
function addEntry(repo, branch, typeKey, projectKey, jdkLookupBranch) {
const key = `${repo}@${branch}`;
if (seen.has(key)) return;
seen.add(key);
const jdks = getJdks(projectKey, typeKey, jdkLookupBranch || branch);
entries.push({ repo, branch, primary_jdk: primaryJdk(jdks) });
}
// Build entries from projects.json
for (const [projectKey, config] of Object.entries(projects)) {
if (projectKey === 'defaults') continue;
if (projectsFilter.size > 0 && !projectsFilter.has(projectKey)) continue;
for (const typeKey of ['oss', 'commercial']) {
const typeCfg = config[typeKey];
if (!typeCfg) continue;
const repo = typeKey === 'commercial'
? `spring-cloud/${projectKey}-commercial`
: `spring-cloud/${projectKey}`;
for (const branch of (typeCfg.branches || {}).scheduled || []) {
addEntry(repo, branch, typeKey, projectKey);
}
}
}
// Optionally add release/[version] branches from the Spring release train README
const springRelease = (process.env.SPRING_RELEASE || '').trim();
if (springRelease) {
let readmeB64;
try {
readmeB64 = execFileSync('gh', [
'api', 'repos/spring-io/release-train/contents/README.adoc',
'-X', 'GET', '-f', `ref=${springRelease}`, '--jq', '.content'
], { encoding: 'utf8' }).trim();
} catch (err) {
console.error(`Warning: could not fetch README.adoc for spring release ${springRelease}: ${err.message}`);
}
if (readmeB64) {
const content = Buffer.from(readmeB64, 'base64').toString('utf8');
let currentRepo = null;
let currentProjectKey = null;
for (const line of content.split('\n')) {
if (/^== /.test(line)) {
if (!line.includes('Spring Cloud')) {
currentRepo = null;
currentProjectKey = null;
}
continue;
}
const releasingMatch = line.match(
/\*\*Releasing from:\*\* https:\/\/github\.com\/spring-cloud\/([^\[]+)\[/
);
if (releasingMatch) {
const repoName = releasingMatch[1].trim().replace(/\/$/, '');
currentRepo = `spring-cloud/${repoName}`;
currentProjectKey = repoName.replace(/-commercial$/, '');
continue;
}
if (currentRepo) {
const versionMatch = line.match(/=== .+ (\d+\.\d+(?:\.\d+(?:\.\d+)?)?)\s*$/);
if (versionMatch) {
const version = versionMatch[1];
const parts = version.split('.');
const parentBranch = parts.slice(0, -1).join('.') + '.x';
if (projectsFilter.size > 0 && !projectsFilter.has(currentProjectKey)) continue;
addEntry(currentRepo, `release/${version}`, 'commercial', currentProjectKey, parentBranch);
}
}
}
}
}
const matrix = { include: entries };
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix=${JSON.stringify(matrix)}\n`);
console.log(`Matrix built: ${entries.length} entries`);
JSEOF
generate:
name: "Generate — ${{ matrix.repo }}@${{ matrix.branch }}"
needs: setup
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha || github.sha }}
token: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
- name: Generate workflows
id: generate
uses: ./.github/actions/generate-workflows-for-branch
with:
repo: ${{ matrix.repo }}
branch: ${{ matrix.branch }}
primary-jdk: ${{ matrix.primary_jdk }}
generator-version: ${{ needs.setup.outputs.generator-version }}
token: ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
- name: Record result
if: always()
id: record
env:
REPO: ${{ matrix.repo }}
BRANCH: ${{ matrix.branch }}
CHANGED: ${{ steps.generate.outputs.changed }}
run: |
safe="${REPO//\//-}-${BRANCH//\//-}"
safe="${safe//./-}"
echo "safe-name=${safe}" >> "$GITHUB_OUTPUT"
echo '{"repo":"'"$REPO"'","branch":"'"$BRANCH"'","changed":'"${CHANGED:-false}"'}' \
> "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: generate
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
run: |
node - << 'JSEOF'
const fs = require('fs');
const path = require('path');
const files = fs.readdirSync('results').filter(f => f.endsWith('.json'));
const results = files
.map(f => JSON.parse(fs.readFileSync(path.join('results', f), 'utf8')))
.sort((a, b) => {
if (a.changed !== b.changed) return a.changed ? -1 : 1;
return `${a.repo}@${a.branch}`.localeCompare(`${b.repo}@${b.branch}`);
});
const updated = results.filter(r => r.changed);
const unchanged = results.filter(r => !r.changed);
let md = '## Workflow Generator Results\n\n';
if (updated.length > 0) {
md += `### Updated (${updated.length})\n\n`;
md += '| Repository | Branch |\n|---|---|\n';
for (const r of updated) {
md += `| \`${r.repo}\` | \`${r.branch}\` |\n`;
}
md += '\n';
} else {
md += '> No changes were made.\n\n';
}
if (unchanged.length > 0) {
md += `<details><summary>Unchanged (${unchanged.length})</summary>\n\n`;
md += '| Repository | Branch |\n|---|---|\n';
for (const r of unchanged) {
md += `| \`${r.repo}\` | \`${r.branch}\` |\n`;
}
md += '\n</details>\n';
}
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, md);
console.log(md);
JSEOF