Skip to content

Commit 59c0629

Browse files
committed
fix(actions/checkout): bump actions/checkout to v6.0.3
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 6908a61 commit 59c0629

10 files changed

Lines changed: 453 additions & 143 deletions

.github/workflows/__shared-ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ jobs:
2323
contents: read
2424
uses: ./.github/workflows/__test-action-matrix-outputs.yml
2525

26+
test-action-checkout:
27+
needs: linter
28+
permissions:
29+
contents: read
30+
uses: ./.github/workflows/__test-action-checkout.yml
31+
32+
test-action-checkout-issue-comment:
33+
needs: linter
34+
permissions:
35+
contents: read
36+
pull-requests: read
37+
uses: ./.github/workflows/__test-action-checkout-issue-comment.yml
38+
2639
test-action-get-github-actions-bot-user:
2740
needs: linter
2841
permissions:
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Internal - Tests for checkout action (issue_comment simulation)
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: read
9+
10+
jobs:
11+
test-checkout-issue-comment:
12+
name: Checkout action on simulated issue_comment
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Arrange - Checkout repository
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
persist-credentials: false
19+
20+
- name: Arrange - Get PR information for simulation
21+
id: pr-info
22+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
23+
with:
24+
script: |
25+
const assert = require('node:assert/strict');
26+
const prNumber = 1;
27+
assert.ok(prNumber, 'Could not determine PR number from static test configuration');
28+
29+
const pr = await github.rest.pulls.get({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
pull_number: prNumber,
33+
});
34+
35+
core.setOutput('head-sha', pr.data.head.sha);
36+
core.setOutput('head-ref', pr.data.head.ref);
37+
core.setOutput('pr-number', prNumber);
38+
39+
core.info(`PR #${prNumber} Head SHA: ${pr.data.head.sha}`);
40+
core.info(`PR #${prNumber} Head Ref: ${pr.data.head.ref}`);
41+
42+
- name: Act - Simulate issue_comment event context and checkout
43+
id: checkout
44+
uses: ./actions/checkout
45+
with:
46+
ref: refs/pull/${{ steps.pr-info.outputs.pr-number }}/head
47+
persist-credentials: true
48+
49+
- name: Assert - Verify correct PR SHA was checked out
50+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
51+
env:
52+
EXPECTED_SHA: ${{ steps.pr-info.outputs.head-sha }}
53+
with:
54+
script: |
55+
const assert = require('node:assert/strict');
56+
const { execSync } = require('child_process');
57+
const currentSha = execSync('git rev-parse HEAD').toString().trim();
58+
const expectedSha = process.env.EXPECTED_SHA;
59+
60+
core.info(`Current SHA: ${currentSha}`);
61+
core.info(`Expected PR Head SHA: ${expectedSha}`);
62+
63+
try {
64+
assert.strictEqual(
65+
currentSha,
66+
expectedSha,
67+
`Checked out SHA (${currentSha}) does not match PR head SHA (${expectedSha})`
68+
);
69+
} catch (error) {
70+
core.setFailed(error.message);
71+
return;
72+
}
73+
74+
core.info('Verified: Checked out correct PR head SHA');
75+
76+
- name: Assert - Verify not on main branch
77+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
78+
env:
79+
EXPECTED_BRANCH: ${{ steps.pr-info.outputs.head-ref }}
80+
with:
81+
script: |
82+
const assert = require('node:assert/strict');
83+
const { execSync } = require('child_process');
84+
const currentBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
85+
const expectedBranch = process.env.EXPECTED_BRANCH;
86+
87+
core.info(`Current branch/ref: ${currentBranch}`);
88+
core.info(`Expected branch: ${expectedBranch}`);
89+
90+
try {
91+
assert.notStrictEqual(currentBranch, 'main', 'Checked out main branch instead of PR branch');
92+
assert.notStrictEqual(currentBranch, 'master', 'Checked out master branch instead of PR branch');
93+
assert.ok(
94+
currentBranch === 'HEAD' || currentBranch === expectedBranch,
95+
`Checked out unexpected ref ${currentBranch}; expected HEAD or ${expectedBranch}`
96+
);
97+
} catch (error) {
98+
core.setFailed(error.message);
99+
return;
100+
}
101+
102+
if (currentBranch === 'HEAD') {
103+
core.warning('Repository is in detached HEAD state; this is expected when checking out refs/pull/<n>/head.');
104+
}
105+
106+
core.info('Verified: Not on main/master branch');
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Internal - Tests for checkout action
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
tests:
11+
name: Tests for checkout action
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Arrange - Checkout repository using checkout action
15+
id: checkout
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
persist-credentials: false
19+
20+
- name: Act - Run custom checkout action with defaults
21+
id: custom-checkout-defaults
22+
uses: ./actions/checkout
23+
24+
- name: Assert - Verify repository is checked out
25+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
26+
with:
27+
script: |
28+
const assert = require('node:assert/strict');
29+
const { existsSync } = require('node:fs');
30+
assert.ok(existsSync('.git'), 'Repository .git directory is missing');
31+
assert.ok(existsSync('README.md'), 'README.md is missing');
32+
33+
- name: Act - Run custom checkout action with fetch-depth 0
34+
id: custom-checkout-full-history
35+
uses: ./actions/checkout
36+
with:
37+
fetch-depth: "0"
38+
39+
- name: Assert - Verify full history is fetched
40+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
41+
with:
42+
script: |
43+
const assert = require('node:assert/strict');
44+
const { execSync } = require('child_process');
45+
const commitCount = Number.parseInt(execSync('git rev-list --count HEAD').toString().trim(), 10);
46+
assert.ok(commitCount >= 1, 'No commits found in repository');
47+
48+
- name: Act - Run custom checkout action with LFS disabled (default)
49+
id: custom-checkout-no-lfs
50+
uses: ./actions/checkout
51+
with:
52+
lfs: "false"
53+
54+
- name: Assert - Verify checkout succeeded
55+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
56+
with:
57+
script: |
58+
const assert = require('node:assert/strict');
59+
const { existsSync } = require('node:fs');
60+
assert.ok(existsSync('README.md'), 'README.md is missing');
61+
62+
- name: Assert - Verify token is not persisted by default
63+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
64+
with:
65+
script: |
66+
const assert = require('node:assert/strict');
67+
const { execSync } = require('child_process');
68+
69+
let persisted = false;
70+
try {
71+
execSync('git config --local --get url.https://github.com/.insteadOf', { stdio: 'pipe' });
72+
persisted = true;
73+
} catch {
74+
persisted = false;
75+
}
76+
77+
assert.equal(persisted, false, 'Token credentials were persisted when they should not have been');

.github/workflows/__test-action-get-github-actions-bot-user.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,27 @@ jobs:
2121
uses: ./actions/get-github-actions-bot-user
2222

2323
- name: Assert - Check get-github-actions-bot-user outputs
24+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
2425
env:
2526
STEPS_GET_GITHUB_ACTIONS_BOT_USER_OUTPUTS_NAME: ${{ steps.get-github-actions-bot-user.outputs.name }}
2627
STEPS_GET_GITHUB_ACTIONS_BOT_USER_OUTPUTS_EMAIL: ${{ steps.get-github-actions-bot-user.outputs.email }}
27-
run: |
28-
if [ "${STEPS_GET_GITHUB_ACTIONS_BOT_USER_OUTPUTS_NAME}" != 'github-actions[bot]' ]; then
29-
echo "get-github-actions-bot-user output name is not valid"
30-
exit 1
31-
fi
28+
with:
29+
script: |
30+
const assert = require('node:assert/strict');
31+
const outputName = process.env.STEPS_GET_GITHUB_ACTIONS_BOT_USER_OUTPUTS_NAME;
32+
const outputEmail = process.env.STEPS_GET_GITHUB_ACTIONS_BOT_USER_OUTPUTS_EMAIL;
33+
34+
core.info(`Output name: ${outputName}`);
35+
core.info(`Output email: ${outputEmail}`);
3236
33-
if [ "${STEPS_GET_GITHUB_ACTIONS_BOT_USER_OUTPUTS_EMAIL}" != '41898282+github-actions[bot]@users.noreply.github.com' ]; then
34-
echo "get-github-actions-bot-user output email is not valid"
35-
exit 1
36-
fi
37+
try {
38+
assert.strictEqual(outputName, 'github-actions[bot]', 'get-github-actions-bot-user output name is not valid');
39+
assert.strictEqual(
40+
outputEmail,
41+
'41898282+github-actions[bot]@users.noreply.github.com',
42+
'get-github-actions-bot-user output email is not valid'
43+
);
44+
} catch (error) {
45+
core.setFailed(error.message);
46+
return;
47+
}

.github/workflows/__test-action-get-issue-number.yml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,35 @@ jobs:
2222
uses: ./actions/get-issue-number
2323

2424
- name: Assert - Check get-issue-number behavior by event type
25+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
2526
env:
27+
EVENT_NAME: ${{ github.event_name }}
2628
STEPS_GET_ISSUE_NUMBER_OUTCOME: ${{ steps.get-issue-number.outcome }}
2729
STEPS_GET_ISSUE_NUMBER_OUTPUTS_ISSUE_NUMBER: ${{ steps.get-issue-number.outputs.issue-number }}
2830
EXPECTED_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
29-
run: |
30-
if [ "${GITHUB_EVENT_NAME}" = 'pull_request' ]; then
31-
if [ "${STEPS_GET_ISSUE_NUMBER_OUTCOME}" != 'success' ]; then
32-
echo "get-issue-number should succeed for pull_request events"
33-
exit 1
34-
fi
31+
with:
32+
script: |
33+
const assert = require('node:assert/strict');
34+
const eventName = process.env.EVENT_NAME;
35+
const outcome = process.env.STEPS_GET_ISSUE_NUMBER_OUTCOME;
36+
const issueNumber = process.env.STEPS_GET_ISSUE_NUMBER_OUTPUTS_ISSUE_NUMBER;
37+
const expectedPrNumber = process.env.EXPECTED_PULL_REQUEST_NUMBER;
38+
39+
core.info(`Event name: ${eventName}`);
40+
core.info(`Action outcome: ${outcome}`);
3541
36-
if [ "${STEPS_GET_ISSUE_NUMBER_OUTPUTS_ISSUE_NUMBER}" != "${EXPECTED_PULL_REQUEST_NUMBER}" ]; then
37-
echo "get-issue-number output is not valid for pull_request events"
38-
exit 1
39-
fi
40-
elif [ "${STEPS_GET_ISSUE_NUMBER_OUTCOME}" != 'failure' ]; then
41-
echo "get-issue-number should fail when event is not pull_request"
42-
exit 1
43-
fi
42+
try {
43+
if (eventName === 'pull_request') {
44+
assert.strictEqual(outcome, 'success', 'get-issue-number should succeed for pull_request events');
45+
assert.strictEqual(
46+
issueNumber,
47+
expectedPrNumber,
48+
'get-issue-number output is not valid for pull_request events'
49+
);
50+
} else {
51+
assert.strictEqual(outcome, 'failure', 'get-issue-number should fail when event is not pull_request');
52+
}
53+
} catch (error) {
54+
core.setFailed(error.message);
55+
return;
56+
}

.github/workflows/__test-action-matrix-outputs.yml

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,27 @@ jobs:
2828
artifact-name: "test-matrix-outputs-${{ matrix.os }}"
2929

3030
- name: Check set matrix outputs
31-
shell: bash
32-
run: |
33-
EXPECTED_ARTIFACT_NAME="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-test-matrix-outputs-${{ matrix.os }}"
34-
35-
if [ "${STEPS_SET_MATRIX_OUTPUT_OUTPUTS_ARTIFACT_NAME}" != "$EXPECTED_ARTIFACT_NAME" ]; then
36-
echo "Set matrix output 1 result is not valid"
37-
exit 1
38-
fi
31+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
3932
env:
33+
GITHUB_RUN_ID_VALUE: ${{ github.run_id }}
34+
GITHUB_RUN_NUMBER_VALUE: ${{ github.run_number }}
35+
MATRIX_OS: ${{ matrix.os }}
4036
STEPS_SET_MATRIX_OUTPUT_OUTPUTS_ARTIFACT_NAME: ${{ steps.set-matrix-output.outputs.artifact-name }}
37+
with:
38+
script: |
39+
const assert = require('node:assert/strict');
40+
const actualArtifactName = process.env.STEPS_SET_MATRIX_OUTPUT_OUTPUTS_ARTIFACT_NAME;
41+
const expectedArtifactName = `${process.env.GITHUB_RUN_ID_VALUE}-${process.env.GITHUB_RUN_NUMBER_VALUE}-test-matrix-outputs-${process.env.MATRIX_OS}`;
42+
43+
core.info(`Actual artifact name: ${actualArtifactName}`);
44+
core.info(`Expected artifact name: ${expectedArtifactName}`);
45+
46+
try {
47+
assert.strictEqual(actualArtifactName, expectedArtifactName, 'Set matrix output 1 result is not valid');
48+
} catch (error) {
49+
core.setFailed(error.message);
50+
return;
51+
}
4152
4253
tests-2:
4354
name: Arrange - Set empty output
@@ -96,27 +107,50 @@ jobs:
96107
artifact-name: test-matrix-outputs-${{ matrix.os }}
97108

98109
- name: Check matrix outputs
99-
shell: bash
100-
run: |
101-
# Output result must be a json array of 2 entries
102-
if [ "$(echo "$OUTPUT_RESULT" | jq -e '. | length')" != "2" ]; then
103-
echo "Get matrix outputs result is not valid"
104-
exit 1
105-
fi
106-
107-
# Output result must contain the first and third entries
108-
if [ "$(echo "$OUTPUT_RESULT" | jq -ce '. | sort')" != '[{"test":"test content 1"},{"test":"test content 3"}]' ]; then
109-
echo "Get matrix outputs result is not valid"
110-
exit 1
111-
fi
110+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
112111
env:
113112
OUTPUT_RESULT: ${{ steps.get-matrix-outputs.outputs.result }}
113+
with:
114+
script: |
115+
const assert = require('node:assert/strict');
116+
const outputResult = process.env.OUTPUT_RESULT;
117+
118+
let parsed;
119+
try {
120+
parsed = JSON.parse(outputResult);
121+
} catch (error) {
122+
core.setFailed(`Get matrix outputs result is not valid JSON: ${error.message}`);
123+
return;
124+
}
125+
126+
try {
127+
assert.ok(Array.isArray(parsed), 'Get matrix outputs result is not an array');
128+
assert.strictEqual(parsed.length, 2, 'Get matrix outputs result does not contain 2 entries');
129+
130+
const normalizedActual = [...parsed].sort((a, b) => String(a.test).localeCompare(String(b.test)));
131+
const normalizedExpected = [
132+
{ test: 'test content 1' },
133+
{ test: 'test content 3' },
134+
];
135+
assert.deepStrictEqual(normalizedActual, normalizedExpected, 'Get matrix outputs result is not valid');
136+
} catch (error) {
137+
core.setFailed(error.message);
138+
return;
139+
}
114140
115141
- name: Check artifacts have been deleted
116-
shell: bash
117-
run: |
118-
ARTIFACTS_PATH="/tmp/$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-test-matrix-outputs-${{ matrix.os }}"
119-
if [ -d "$ARTIFACTS_PATH" ]; then
120-
echo "Artifacts have not been deleted"
121-
exit 1
122-
fi
142+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
143+
env:
144+
ARTIFACTS_PATH: /tmp/${{ github.run_id }}-${{ github.run_number }}-test-matrix-outputs-${{ matrix.os }}
145+
with:
146+
script: |
147+
const assert = require('node:assert/strict');
148+
const { existsSync } = require('node:fs');
149+
const artifactsPath = process.env.ARTIFACTS_PATH;
150+
151+
try {
152+
assert.strictEqual(existsSync(artifactsPath), false, 'Artifacts have not been deleted');
153+
} catch (error) {
154+
core.setFailed(error.message);
155+
return;
156+
}

0 commit comments

Comments
 (0)