Skip to content

Commit 7cc7b37

Browse files
committed
Move the release train workflow file list into a reusable action
All three branch-creation workflows checked for the same two files with their own copy of the loop. Extract check-release-train-workflows so the list has one definition; callers choose between generating the missing files and failing fast via fail-on-missing. Signed-off-by: Ryan Baxter <ryan.baxter@broadcom.com>
1 parent 6952236 commit 7cc7b37

4 files changed

Lines changed: 123 additions & 88 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: 'Check Release Train Workflows'
2+
description: >
3+
Checks a branch for the workflow files a release branch needs in order to join
4+
a Spring release train, and reports which are missing. This is the single
5+
definition of that file list - callers that generate the missing files and
6+
callers that fail on them both read it from here.
7+
8+
inputs:
9+
repo:
10+
description: 'Full repository path to check (e.g. spring-cloud/spring-cloud-config-commercial)'
11+
required: true
12+
branch:
13+
description: 'Branch to check the workflow files on'
14+
required: true
15+
token:
16+
description: 'GitHub token with read access to the repository'
17+
required: true
18+
fail-on-missing:
19+
description: >
20+
Fail the step when a workflow file is missing, rather than only reporting
21+
it through the outputs. Use this where the caller has no way to generate
22+
the missing files and wants to stop before doing any other work.
23+
required: false
24+
default: 'false'
25+
26+
outputs:
27+
any-missing:
28+
description: "'true' when at least one required workflow file is missing, otherwise 'false'"
29+
value: ${{ steps.check.outputs.any-missing }}
30+
missing:
31+
description: 'Space-separated list of the missing workflow file names (empty when none are missing)'
32+
value: ${{ steps.check.outputs.missing }}
33+
34+
runs:
35+
using: composite
36+
steps:
37+
- name: Check for required release train workflows
38+
id: check
39+
shell: bash
40+
env:
41+
GH_TOKEN: ${{ inputs.token }}
42+
REPO: ${{ inputs.repo }}
43+
BRANCH: ${{ inputs.branch }}
44+
FAIL_ON_MISSING: ${{ inputs.fail-on-missing }}
45+
run: |
46+
# The workflows a release branch must carry to join a release train.
47+
required_workflows=("release-train-join.yml" "release-train-ready.yml")
48+
49+
missing=()
50+
for workflow in "${required_workflows[@]}"; do
51+
if gh api "repos/${REPO}/contents/.github/workflows/${workflow}?ref=${BRANCH}" --silent 2>/dev/null; then
52+
echo " ✓ ${workflow} present in ${REPO} at ${BRANCH}"
53+
else
54+
echo " ✗ ${workflow} missing from ${REPO} at ${BRANCH}"
55+
missing+=("${workflow}")
56+
fi
57+
done
58+
59+
if [[ ${#missing[@]} -eq 0 ]]; then
60+
echo "any-missing=false" >> "$GITHUB_OUTPUT"
61+
echo "missing=" >> "$GITHUB_OUTPUT"
62+
echo "All required release train workflows are present on ${BRANCH}."
63+
exit 0
64+
fi
65+
66+
echo "any-missing=true" >> "$GITHUB_OUTPUT"
67+
echo "missing=${missing[*]}" >> "$GITHUB_OUTPUT"
68+
69+
if [[ "$FAIL_ON_MISSING" != "true" ]]; then
70+
exit 0
71+
fi
72+
73+
echo
74+
echo "ERROR: required release train workflow(s) missing from ${REPO} at ${BRANCH}:"
75+
for workflow in "${missing[@]}"; do
76+
echo " - .github/workflows/${workflow}"
77+
done
78+
echo
79+
echo "Run run-github-actions-workflow-generator.yml for ${REPO} on ${BRANCH}"
80+
echo "to generate the missing workflow(s), then re-run this workflow."
81+
exit 1

.github/workflows/create-commercial-release-branch.yml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -145,37 +145,12 @@ jobs:
145145
# created, so a missing file fails fast instead of leaving a half-created
146146
# release branch and a projects.json entry to clean up by hand.
147147
- name: Verify release train workflows exist on source branch
148-
env:
149-
GH_TOKEN: ${{ inputs.token || secrets.token || secrets.GH_ACTIONS_REPO_TOKEN }}
150-
run: |
151-
source_repo="spring-cloud/${{ inputs.project }}"
152-
source_branch="${{ inputs.branch }}"
153-
154-
missing=()
155-
for workflow in "release-train-join.yml" "release-train-ready.yml"; do
156-
if gh api "repos/${source_repo}/contents/.github/workflows/${workflow}?ref=${source_branch}" --silent 2>/dev/null; then
157-
echo " ✓ ${workflow} present in ${source_repo} at ${source_branch}"
158-
else
159-
echo " ✗ ${workflow} missing from ${source_repo} at ${source_branch}"
160-
missing+=("${workflow}")
161-
fi
162-
done
163-
164-
if [[ ${#missing[@]} -gt 0 ]]; then
165-
echo
166-
echo "ERROR: required release train workflow(s) missing from ${source_repo} at ${source_branch}:"
167-
for workflow in "${missing[@]}"; do
168-
echo " - .github/workflows/${workflow}"
169-
done
170-
echo
171-
echo "The release branch is cut from ${source_branch} and inherits its workflows, so"
172-
echo "release-train-join.yml could not be dispatched on it."
173-
echo "Run run-github-actions-workflow-generator.yml for ${source_repo} on ${source_branch}"
174-
echo "to generate the missing workflow(s), then re-run this workflow."
175-
exit 1
176-
fi
177-
178-
echo "Check passed: release train workflows are present on ${source_branch}."
148+
uses: ./.github/actions/check-release-train-workflows
149+
with:
150+
repo: spring-cloud/${{ inputs.project }}
151+
branch: ${{ inputs.branch }}
152+
token: ${{ inputs.token || secrets.token || secrets.GH_ACTIONS_REPO_TOKEN }}
153+
fail-on-missing: 'true'
179154

180155
- name: Create milestone in source repo if missing
181156
uses: ./.github/actions/create-milestone

.github/workflows/create-hotfix-release-branch.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,29 @@ jobs:
252252
needs: [derive, update-versions]
253253
runs-on: ubuntu-latest
254254
steps:
255+
- name: Checkout
256+
uses: actions/checkout@v4
257+
with:
258+
ref: ${{ inputs.sha || github.sha }}
259+
255260
- name: Check for required release train workflows
256-
id: check
261+
id: check-workflows
262+
uses: ./.github/actions/check-release-train-workflows
263+
with:
264+
repo: ${{ needs.derive.outputs.commercial_repo }}
265+
branch: ${{ needs.derive.outputs.commercial_branch }}
266+
token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
267+
268+
- name: Determine primary JDK for the generator
269+
id: jdk
270+
if: steps.check-workflows.outputs.any-missing == 'true'
257271
shell: bash
258272
env:
259273
GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
260274
run: |
261275
commercial_project="${{ needs.derive.outputs.commercial_project }}"
262276
release_branch="${{ needs.derive.outputs.commercial_branch }}"
263277
264-
missing=false
265-
for workflow in "release-train-join.yml" "release-train-ready.yml"; do
266-
if gh api "repos/spring-cloud/${commercial_project}/contents/.github/workflows/${workflow}?ref=${release_branch}" --silent 2>/dev/null; then
267-
echo " ✓ ${workflow} present"
268-
else
269-
echo " ✗ ${workflow} missing"
270-
missing=true
271-
fi
272-
done
273-
echo "needs-generation=${missing}" >> "$GITHUB_OUTPUT"
274-
275278
# Look up primary JDK from projects.json.
276279
# initialize-commercial-branch already ran update-projects-json, which added
277280
# commercial.jdkVersions[release_branch] sourced from oss.jdkVersions['X.Y.x'].
@@ -312,26 +315,15 @@ jobs:
312315
JSEOF
313316
)
314317
echo "primary-jdk=${primary_jdk}" >> "$GITHUB_OUTPUT"
315-
316-
if [[ "$missing" == "false" ]]; then
317-
echo "All required workflows are present — skipping generator."
318-
else
319-
echo "One or more required workflows are missing — generator will run (primary JDK: ${primary_jdk})."
320-
fi
321-
322-
- name: Checkout
323-
if: steps.check.outputs.needs-generation == 'true'
324-
uses: actions/checkout@v4
325-
with:
326-
ref: ${{ inputs.sha || github.sha }}
318+
echo "Generator will run with primary JDK ${primary_jdk} for the missing workflow(s): ${{ steps.check-workflows.outputs.missing }}"
327319
328320
- name: Run workflow generator for hotfix branch
329-
if: steps.check.outputs.needs-generation == 'true'
321+
if: steps.check-workflows.outputs.any-missing == 'true'
330322
uses: ./.github/actions/generate-workflows-for-branch
331323
with:
332324
repo: ${{ needs.derive.outputs.commercial_repo }}
333325
branch: ${{ needs.derive.outputs.commercial_branch }}
334-
primary-jdk: ${{ steps.check.outputs.primary-jdk }}
326+
primary-jdk: ${{ steps.jdk.outputs.primary-jdk }}
335327
token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
336328

337329
trigger-release-train-join:

.github/workflows/create-oss-release-branch.yml

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -350,27 +350,25 @@ jobs:
350350
needs: [derive, update-release-branch]
351351
runs-on: ubuntu-latest
352352
steps:
353+
- name: Checkout spring-cloud-github-actions
354+
uses: actions/checkout@v4
355+
with:
356+
ref: ${{ inputs.sha || github.sha }}
357+
353358
- name: Check for required release train workflows in OSS branch
354-
id: check
359+
id: check-workflows
360+
uses: ./.github/actions/check-release-train-workflows
361+
with:
362+
repo: spring-cloud/${{ inputs.oss_repo }}
363+
branch: ${{ inputs.oss_branch }}
364+
token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
365+
366+
- name: Determine primary JDK for the generator
367+
id: jdk
368+
if: steps.check-workflows.outputs.any-missing == 'true'
355369
env:
356370
GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
357371
run: |
358-
oss_repo="spring-cloud/${{ inputs.oss_repo }}"
359-
oss_branch="${{ inputs.oss_branch }}"
360-
commercial_project="${{ needs.derive.outputs.commercial_project }}"
361-
commercial_branch="${{ needs.derive.outputs.commercial_branch }}"
362-
363-
missing=false
364-
for workflow in "release-train-join.yml" "release-train-ready.yml"; do
365-
if gh api "repos/${oss_repo}/contents/.github/workflows/${workflow}?ref=${oss_branch}" --silent 2>/dev/null; then
366-
echo " ✓ ${workflow} present in OSS repo at ${oss_branch}"
367-
else
368-
echo " ✗ ${workflow} missing from OSS repo at ${oss_branch}"
369-
missing=true
370-
fi
371-
done
372-
echo "needs-generation=${missing}" >> "$GITHUB_OUTPUT"
373-
374372
# Look up the primary JDK for this OSS branch from projects.json.
375373
project_key="${{ inputs.oss_repo }}"
376374
oss_branch="${{ inputs.oss_branch }}"
@@ -408,26 +406,15 @@ jobs:
408406
JSEOF
409407
)
410408
echo "primary-jdk=${primary_jdk}" >> "$GITHUB_OUTPUT"
411-
412-
if [[ "$missing" == "false" ]]; then
413-
echo "All required workflows are present — skipping generator."
414-
else
415-
echo "One or more required workflows are missing — generator will run (primary JDK: ${primary_jdk})."
416-
fi
417-
418-
- name: Checkout spring-cloud-github-actions
419-
if: steps.check.outputs.needs-generation == 'true'
420-
uses: actions/checkout@v4
421-
with:
422-
ref: ${{ inputs.sha || github.sha }}
409+
echo "Generator will run with primary JDK ${primary_jdk} for the missing workflow(s): ${{ steps.check-workflows.outputs.missing }}"
423410
424411
- name: Run workflow generator for commercial release branch
425-
if: steps.check.outputs.needs-generation == 'true'
412+
if: steps.check-workflows.outputs.any-missing == 'true'
426413
uses: ./.github/actions/generate-workflows-for-branch
427414
with:
428415
repo: ${{ needs.derive.outputs.commercial_repo }}
429416
branch: ${{ needs.derive.outputs.commercial_branch }}
430-
primary-jdk: ${{ steps.check.outputs.primary-jdk }}
417+
primary-jdk: ${{ steps.jdk.outputs.primary-jdk }}
431418
token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
432419

433420
# Dispatch release-train-join.yml in the commercial repo and wait for it to

0 commit comments

Comments
 (0)