Skip to content

Commit 0040a57

Browse files
committed
fix(release/plan): use api instead of local git
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent a4e4d78 commit 0040a57

4 files changed

Lines changed: 113 additions & 49 deletions

File tree

.github/workflows/__shared-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
needs: linter
7171
uses: ./.github/workflows/__test-action-release-plan.yml
7272
permissions:
73-
contents: read
73+
contents: write
7474
pull-requests: read
7575

7676
test-action-release-summarize-changelog:

.github/workflows/__test-action-release-plan.yml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Tests for "release/plan" action
1111
runs-on: ubuntu-latest
1212
permissions:
13-
contents: read
13+
contents: write
1414
pull-requests: read
1515
steps:
1616
- name: Arrange - Checkout
@@ -37,3 +37,79 @@ jobs:
3737
assert.ok(process.env.RELEASE_TAG.startsWith('get-configuration-'), `Expected tag to start with "get-configuration-", got "${process.env.RELEASE_TAG}"`);
3838
assert.ok(process.env.RELEASE_NAME, 'Expected planned name to be set');
3939
assert.ok(process.env.RELEASE_NAME.startsWith('Version get-configuration - '), `Expected name to start with "Version get-configuration - ", got "${process.env.RELEASE_NAME}"`);
40+
41+
- name: Arrange - Create colliding tag
42+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
43+
env:
44+
RELEASE_TAG: ${{ steps.drafter-plan.outputs.tag }}
45+
TARGET_SHA: ${{ github.sha }}
46+
with:
47+
github-token: ${{ github.token }}
48+
script: |
49+
const releaseTag = (process.env.RELEASE_TAG || '').trim();
50+
const targetSha = (process.env.TARGET_SHA || '').trim();
51+
52+
if (!releaseTag) {
53+
throw new Error('Expected planned release tag before creating a colliding tag');
54+
}
55+
56+
if (!targetSha) {
57+
throw new Error('Expected target sha before creating a colliding tag');
58+
}
59+
60+
await github.rest.git.createRef({
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
ref: `refs/tags/${releaseTag}`,
64+
sha: targetSha,
65+
});
66+
67+
- name: Act - Plan drafter release with existing tag
68+
id: existing-tag-plan
69+
continue-on-error: true
70+
uses: ./actions/release/plan
71+
with:
72+
working-directory: actions/release/get-configuration
73+
74+
- name: Assert - Existing remote tag blocks release plan
75+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
76+
env:
77+
RELEASE_TAG: ${{ steps.drafter-plan.outputs.tag }}
78+
STEP_OUTCOME: ${{ steps.existing-tag-plan.outcome }}
79+
with:
80+
script: |
81+
const assert = require('node:assert');
82+
83+
const releaseTag = (process.env.RELEASE_TAG || '').trim();
84+
const stepOutcome = (process.env.STEP_OUTCOME || '').trim();
85+
86+
assert.ok(releaseTag, 'Expected colliding tag to be set');
87+
assert.equal(stepOutcome, 'failure', `Expected plan action to fail when tag already exists, got "${stepOutcome}"`);
88+
89+
- name: Cleanup - Delete colliding tag
90+
if: always()
91+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
92+
env:
93+
RELEASE_TAG: ${{ steps.drafter-plan.outputs.tag }}
94+
with:
95+
github-token: ${{ github.token }}
96+
script: |
97+
const releaseTag = (process.env.RELEASE_TAG || '').trim();
98+
99+
if (!releaseTag) {
100+
return;
101+
}
102+
103+
try {
104+
await github.rest.git.deleteRef({
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
ref: `tags/${releaseTag}`,
108+
});
109+
} catch (error) {
110+
if (error.status === 404) {
111+
return;
112+
}
113+
114+
throw error;
115+
}

actions/release/plan/action.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,21 @@ runs:
8080
github-token: ${{ inputs.github-token }}
8181
script: |
8282
const assertTagDoesNotExist = async releaseTag => {
83-
const remoteTag = await exec.getExecOutput(
84-
'git',
85-
['ls-remote', '--exit-code', '--tags', 'origin', `refs/tags/${releaseTag}`],
86-
{ ignoreReturnCode: true, silent: true }
87-
);
83+
try {
84+
await github.rest.git.getRef({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
ref: `tags/${releaseTag}`,
88+
});
89+
} catch (error) {
90+
if (error.status === 404) {
91+
return;
92+
}
8893
89-
if (remoteTag.exitCode === 0) {
90-
throw new Error(`Remote tag already exists: ${releaseTag}`);
94+
throw new Error(`Cannot check remote tag ${releaseTag}: ${error.message}`);
9195
}
9296
93-
if (remoteTag.exitCode !== 2) {
94-
throw new Error(`Cannot check remote tag ${releaseTag}: ${remoteTag.stderr}`);
95-
}
97+
throw new Error(`Remote tag already exists: ${releaseTag}`);
9698
};
9799
98100
try {

actions/release/summarize-changelog/package-lock.json

Lines changed: 23 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)