Skip to content

Commit 74c3165

Browse files
committed
Fix release validation for historical checkout refs
1 parent a50561d commit 74c3165

3 files changed

Lines changed: 53 additions & 7 deletions

File tree

‎.github/workflows/release-android-snapshot-helper.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ jobs:
3636
with:
3737
ref: ${{ inputs.checkout_ref || github.ref }}
3838

39+
- name: Checkout release validator
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
41+
with:
42+
ref: ${{ github.workflow_sha }}
43+
path: .release-validator
44+
sparse-checkout: scripts/release-version.mjs
45+
sparse-checkout-cone-mode: false
46+
persist-credentials: false
47+
3948
- name: Setup Node.js
4049
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
4150
with:
@@ -47,7 +56,7 @@ jobs:
4756
TAG_NAME: ${{ inputs.release_tag }}
4857
run: |
4958
set -euo pipefail
50-
node scripts/release-version.mjs asset-tag "$TAG_NAME"
59+
node .release-validator/scripts/release-version.mjs asset-tag "$TAG_NAME"
5160
VERSION="${TAG_NAME#v}"
5261
echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT"
5362
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

‎.github/workflows/release-ios-runner.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ jobs:
3939
with:
4040
ref: ${{ inputs.checkout_ref || github.ref }}
4141

42+
- name: Checkout release validator
43+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
44+
with:
45+
ref: ${{ github.workflow_sha }}
46+
path: .release-validator
47+
sparse-checkout: scripts/release-version.mjs
48+
sparse-checkout-cone-mode: false
49+
persist-credentials: false
50+
4251
- name: Setup toolchain
4352
uses: ./.github/actions/setup-node-pnpm
4453
with:
@@ -50,7 +59,7 @@ jobs:
5059
TAG_NAME: ${{ inputs.release_tag }}
5160
run: |
5261
set -euo pipefail
53-
node scripts/release-version.mjs asset-tag "$TAG_NAME"
62+
node .release-validator/scripts/release-version.mjs asset-tag "$TAG_NAME"
5463
VERSION="${TAG_NAME#v}"
5564
echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT"
5665
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

‎test/repo-guards/release-assets.test.ts‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { mkdtempForTestSync } from '@agent-device/test-kit';
99
const repo = path.resolve(import.meta.dirname, '../..');
1010
const workflows = ['release-ios-runner.yml', 'release-android-snapshot-helper.yml'];
1111

12-
type Step = { name: string; run?: string; env?: Record<string, string> };
12+
type Step = {
13+
name: string;
14+
run?: string;
15+
env?: Record<string, string>;
16+
with?: Record<string, string>;
17+
};
1318

1419
function fixture() {
1520
const root = fs.realpathSync(mkdtempForTestSync('release-assets-'));
@@ -93,13 +98,17 @@ function run(root: string, env: Record<string, string>, script: string, args: st
9398
return spawnSync('/bin/sh', [script, ...args], { cwd: root, env, encoding: 'utf8' });
9499
}
95100

96-
function metadataStep(workflow: string): Step {
101+
function workflowSteps(workflow: string): Step[] {
97102
const doc = parse(fs.readFileSync(path.join(repo, '.github/workflows', workflow), 'utf8')) as {
98103
jobs: Record<string, { steps: Step[] }>;
99104
};
100-
const step = Object.values(doc.jobs)
101-
.flatMap((job) => job.steps)
102-
.find((candidate) => candidate.name === 'Resolve release metadata');
105+
return Object.values(doc.jobs).flatMap((job) => job.steps);
106+
}
107+
108+
function metadataStep(workflow: string): Step {
109+
const step = workflowSteps(workflow).find(
110+
(candidate) => candidate.name === 'Resolve release metadata',
111+
);
103112
assert.ok(step?.run);
104113
return step;
105114
}
@@ -117,6 +126,25 @@ for (const workflow of workflows) {
117126
] as const) {
118127
test(`${workflow} handles ${label} as data`, () => {
119128
const f = fixture();
129+
const historical = path.join(f.root, 'historical.mjs');
130+
fs.writeFileSync(historical, "console.error('unknown command'); process.exit(1);\n");
131+
const refs: Record<string, string> = {
132+
'${{ inputs.checkout_ref || github.ref }}': historical,
133+
'${{ github.workflow_sha }}': path.join(repo, 'scripts/release-version.mjs'),
134+
};
135+
for (const checkout of workflowSteps(workflow).filter((step) =>
136+
step.name.startsWith('Checkout'),
137+
)) {
138+
const source = refs[checkout.with?.ref ?? ''];
139+
assert.ok(source, `unexpected checkout ref: ${checkout.with?.ref}`);
140+
const destination = path.join(
141+
f.root,
142+
checkout.with?.path ?? '',
143+
'scripts/release-version.mjs',
144+
);
145+
fs.mkdirSync(path.dirname(destination), { recursive: true });
146+
fs.copyFileSync(source, destination);
147+
}
120148
const tag = makeTag(f.marker);
121149
const step = metadataStep(workflow);
122150
const inputExpression = '${{ inputs.release_tag }}';

0 commit comments

Comments
 (0)