88 required : false
99 type : string
1010 default : ' '
11- release-train-build-sha :
12- description : ' SHA to pin the release-train-build wrapper action to. Defaults to the latest commit that modified the action in this repo.'
13- required : false
14- type : string
15- default : ' '
16- release-train-test-sha :
17- description : ' SHA to pin the release-train-test wrapper action to. Defaults to the latest commit that modified the action in this repo.'
11+ sha :
12+ description : ' SHA to pin both release-train wrapper actions to. Defaults to the latest commit in this repo.'
1813 required : false
1914 type : string
2015 default : ' '
4540 matrix : ${{ steps.build-matrix.outputs.matrix }}
4641 generator-version : ${{ steps.find-generator.outputs.version }}
4742 generator-url : ${{ steps.find-generator.outputs.url }}
48- build-sha : ${{ steps.find-shas.outputs.build-sha }}
49- test-sha : ${{ steps.find-shas.outputs.test-sha }}
43+ sha : ${{ steps.find-sha.outputs.sha }}
5044 steps :
5145 - name : Checkout
5246 uses : actions/checkout@v4
@@ -70,33 +64,21 @@ jobs:
7064 echo "Generator version : ${version}"
7165 echo "Download URL : ${url}"
7266
73- - name : Find action SHAs
74- id : find-shas
67+ - name : Find action SHA
68+ id : find-sha
7569 env :
7670 GH_TOKEN : ${{ inputs.token || secrets.GH_ACTIONS_REPO_TOKEN }}
7771 run : |
78- if [[ -n "${{ inputs.release-train-build- sha }}" ]]; then
79- build_sha ="${{ inputs.release-train-build- sha }}"
72+ if [[ -n "${{ inputs.sha }}" ]]; then
73+ sha ="${{ inputs.sha }}"
8074 else
81- build_sha =$(gh api "repos/spring-cloud/spring-cloud-github-actions/commits" \
75+ sha =$(gh api "repos/spring-cloud/spring-cloud-github-actions/commits" \
8276 -X GET \
83- -f path=".github/actions/release-train-build/action.yml" \
8477 -f per_page=1 \
8578 --jq '.[0].sha')
8679 fi
87- if [[ -n "${{ inputs.release-train-test-sha }}" ]]; then
88- test_sha="${{ inputs.release-train-test-sha }}"
89- else
90- test_sha=$(gh api "repos/spring-cloud/spring-cloud-github-actions/commits" \
91- -X GET \
92- -f path=".github/actions/release-train-test/action.yml" \
93- -f per_page=1 \
94- --jq '.[0].sha')
95- fi
96- echo "build-sha=${build_sha}" >> "$GITHUB_OUTPUT"
97- echo "test-sha=${test_sha}" >> "$GITHUB_OUTPUT"
98- echo "release-train-build SHA : ${build_sha}"
99- echo "release-train-test SHA : ${test_sha}"
80+ echo "sha=${sha}" >> "$GITHUB_OUTPUT"
81+ echo "SHA : ${sha}"
10082
10183 - name : Build matrix
10284 id : build-matrix
@@ -253,38 +235,35 @@ jobs:
253235 - name : Update release-train wrapper actions
254236 working-directory : repo
255237 env :
256- BUILD_SHA : ${{ needs.setup.outputs.build-sha }}
257- TEST_SHA : ${{ needs.setup.outputs.test-sha }}
238+ SHA : ${{ needs.setup.outputs.sha }}
258239 run : |
259240 node - << 'JSEOF'
260241 const fs = require('fs');
261242 const path = require('path');
262243
263- const buildSha = process.env.BUILD_SHA;
264- const testSha = process.env.TEST_SHA;
244+ const sha = process.env.SHA;
265245
266246 const ACTIONS = [
267247 {
268248 file: '.github/actions/release-train-build/action.yml',
269249 name: 'Build Release',
270250 ref: 'spring-cloud/spring-cloud-github-actions/.github/actions/release-train-build',
271- sha: buildSha ,
251+ sha,
272252 },
273253 {
274254 file: '.github/actions/release-train-test/action.yml',
275255 name: 'Test Release',
276256 ref: 'spring-cloud/spring-cloud-github-actions/.github/actions/release-train-test',
277- sha: testSha ,
257+ sha,
278258 },
279259 ];
280260
281- const SHA_RE = /@[0-9a-f]{40}/g;
282-
283261 for (const { file, name, ref, sha } of ACTIONS) {
284262 fs.mkdirSync(path.dirname(file), { recursive: true });
285263 if (fs.existsSync(file)) {
286264 const original = fs.readFileSync(file, 'utf8');
287- const updated = original.replace(SHA_RE, `@${sha}`);
265+ const shaRe = new RegExp(`(${ref.replace(/\//g, '\\/')})@[0-9a-f]{40}`, 'g');
266+ const updated = original.replace(shaRe, `$1@${sha}`);
288267 if (updated === original) {
289268 console.log(` ${file}: SHA already up to date.`);
290269 } else {
0 commit comments