@@ -256,50 +256,48 @@ jobs:
256256 BUILD_SHA : ${{ needs.setup.outputs.build-sha }}
257257 TEST_SHA : ${{ needs.setup.outputs.test-sha }}
258258 run : |
259- python3 - << 'PYEOF'
260- import os, re
259+ node - << 'JSEOF'
260+ const fs = require('fs');
261+ const path = require('path');
261262
262- build_sha = os.environ[' BUILD_SHA']
263- test_sha = os.environ[' TEST_SHA']
263+ const buildSha = process.env. BUILD_SHA;
264+ const testSha = process.env. TEST_SHA;
264265
265- ACTIONS = {
266- '.github/actions/release-train-build/action.yml': (
267- 'Build Release',
268- 'spring-cloud/spring-cloud-github-actions/.github/actions/release-train-build',
269- build_sha,
270- ),
271- '.github/actions/release-train-test/action.yml': (
272- 'Test Release',
273- 'spring-cloud/spring-cloud-github-actions/.github/actions/release-train-test',
274- test_sha,
275- ),
276- }
266+ const ACTIONS = [
267+ {
268+ file: '.github/actions/release-train-build/action.yml',
269+ name: 'Build Release',
270+ ref: 'spring-cloud/spring-cloud-github-actions/.github/actions/release-train-build',
271+ sha: buildSha,
272+ },
273+ {
274+ file: '.github/actions/release-train-test/action.yml',
275+ name: 'Test Release',
276+ ref: 'spring-cloud/spring-cloud-github-actions/.github/actions/release-train-test',
277+ sha: testSha,
278+ },
279+ ];
277280
278- SHA_RE = re.compile(r'(@) [0-9a-f]{40}')
281+ const SHA_RE = /@ [0-9a-f]{40}/g;
279282
280- for path, (action_name, action_ref, sha) in ACTIONS.items():
281- os.makedirs(os.path.dirname(path), exist_ok=True)
282- if os.path.exists(path):
283- with open(path) as f:
284- content = f.read()
285- new_content = SHA_RE.sub(lambda m: m.group(1) + sha, content)
286- if new_content == content:
287- print(f' {path}: SHA already up to date.')
288- else:
289- with open(path, 'w') as f:
290- f.write(new_content)
291- print(f' {path}: updated SHA to {sha}.')
292- else:
293- with open(path, 'w') as f:
294- f.write(
295- f'name: {action_name}\n'
296- f'runs:\n'
297- f' using: composite\n'
298- f' steps:\n'
299- f' - uses: {action_ref}@{sha}\n'
300- )
301- print(f' {path}: created.')
302- PYEOF
283+ for (const { file, name, ref, sha } of ACTIONS) {
284+ fs.mkdirSync(path.dirname(file), { recursive: true });
285+ if (fs.existsSync(file)) {
286+ const original = fs.readFileSync(file, 'utf8');
287+ const updated = original.replace(SHA_RE, `@${sha}`);
288+ if (updated === original) {
289+ console.log(` ${file}: SHA already up to date.`);
290+ } else {
291+ fs.writeFileSync(file, updated, 'utf8');
292+ console.log(` ${file}: updated SHA to ${sha}.`);
293+ }
294+ } else {
295+ const content = `name: ${name}\nruns:\n using: composite\n steps:\n - uses: ${ref}@${sha}\n`;
296+ fs.writeFileSync(file, content, 'utf8');
297+ console.log(` ${file}: created.`);
298+ }
299+ }
300+ JSEOF
303301
304302 - name : Run workflow generator
305303 working-directory : repo
0 commit comments