Skip to content

Commit 919b586

Browse files
committed
Try new actual release process
1 parent ca92f51 commit 919b586

2 files changed

Lines changed: 44 additions & 94 deletions

File tree

.github/workflows/draft-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
runs-on: 'ubuntu-latest'
1818
steps:
1919
- name: 'Checkout'
20-
uses: 'actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11' # ratchet:actions/checkout@v4
20+
uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
2121

2222
- name: 'Setup node'
23-
uses: 'actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8' # ratchet:actions/setup-node@v4
23+
uses: 'actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a' # ratchet:actions/setup-node@v4
2424
with:
2525
node-version: '22.x'
2626

.github/workflows/release.yml

Lines changed: 42 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,101 +7,51 @@ on:
77
required: true
88

99
jobs:
10-
release:
11-
name: 'Release'
10+
create-release:
11+
if: |-
12+
${{ startsWith(github.event.head_commit.message, 'Release: v') }}
1213
runs-on: 'ubuntu-latest'
14+
outputs:
15+
created: '${{ steps.create-release.outputs.created || false }}'
16+
tag: '${{ steps.create-release.outputs.tag }}'
17+
version: '${{ steps.create-release.outputs.version }}'
1318
steps:
14-
- name: 'Checkout'
15-
uses: 'actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11' # ratchet:actions/checkout@v4
16-
17-
- name: 'Get package version'
18-
run: |-
19-
echo "NEW_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
20-
21-
- name: 'Get previous release tag'
22-
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
23-
with:
24-
github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
25-
script: |-
26-
try {
27-
const latestRelease = await github.rest.repos.getLatestRelease({
28-
owner: context.repo.owner,
29-
repo: context.repo.repo,
30-
});
31-
core.exportVariable("PREV_TAG", latestRelease.data.tag_name);
32-
} catch (err) {
33-
if (err["status"] === 404) {
34-
core.info(`No releases found`);
35-
} else {
36-
core.setFailed(`Failed to load latest release: ${err}`);
37-
}
38-
}
39-
4019
- name: 'Create release'
41-
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
42-
with:
43-
github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
44-
script: |-
45-
const tag = "v" + process.env.NEW_VERSION;
46-
47-
try {
48-
const createReleaseRequest = {
49-
owner: context.repo.owner,
50-
repo: context.repo.repo,
51-
tag_name: tag,
52-
target_commitish: context.sha,
53-
name: tag,
54-
generate_release_notes: true,
55-
};
56-
57-
if (process.env.PREV_TAG) {
58-
const releaseNotes = await github.rest.repos.generateReleaseNotes({
59-
owner: context.repo.owner,
60-
repo: context.repo.repo,
61-
tag_name: tag,
62-
target_commitish: context.sha,
63-
previous_tag_name: process.env.PREV_TAG,
64-
});
65-
66-
createReleaseRequest.body = releaseNotes.data.body;
67-
createReleaseRequest.generate_release_notes = false;
68-
}
69-
70-
const response = await github.rest.repos.createRelease(createReleaseRequest);
71-
72-
core.info(
73-
`Created release ${response.data.name} at ${response.data.html_url}`
74-
);
75-
} catch (err) {
76-
core.setFailed(`Failed to create release: ${err}`);
77-
}
78-
79-
- name: 'Update floating tag'
80-
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
20+
id: 'create-release'
21+
uses: 'abcxyz/pkg/.github/actions/create-release@main' # ratchet:exclude
8122
with:
82-
script: |-
83-
const tag = "v" + process.env.NEW_VERSION;
84-
const major = tag.split(".")[0];
23+
github_token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
24+
expected_email: '72759630+google-github-actions-bot@users.noreply.github.com'
8525

86-
// Try to update the ref first. If that fails, it probably does not
87-
// exist yet, and we should create it.
88-
try {
89-
await github.rest.git.updateRef({
90-
owner: context.repo.owner,
91-
repo: context.repo.repo,
92-
ref: "tags/" + major,
93-
sha: context.sha,
94-
force: true,
95-
});
96-
core.info(`Updated ${major} to ${context.sha}`);
97-
} catch (err) {
98-
core.warning(`Failed to create tag ${major}: ${err}`);
26+
publish-release:
27+
runs-on: 'ubuntu-latest'
28+
needs:
29+
- 'create-release'
30+
steps:
31+
- name: 'Publish release'
32+
env:
33+
GH_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'
34+
RELEASE_VERSION: 'v${{ needs.create-release.outputs.version }}'
35+
REPO: '${{ github.repository }}'
36+
run: |-
37+
gh release edit "${RELEASE_VERSION}" \
38+
--repo "${REPO}" \
39+
--draft=false
9940
100-
await github.rest.git.createRef({
101-
owner: context.repo.owner,
102-
repo: context.repo.repo,
103-
ref: "refs/tags/" + major,
104-
sha: context.sha,
105-
});
106-
core.info(`Created ${major} at ${context.sha}`);
107-
}
41+
cleanup-failed-release:
42+
if: |-
43+
${{ always() && needs.create-release.outputs.created == 'true' && contains(fromJSON('["failure", "cancelled", "skipped"]'), needs.publish-release.result) }}
44+
runs-on: 'ubuntu-latest'
45+
needs:
46+
- 'create-release'
47+
- 'publish-release'
48+
steps:
49+
- name: 'Cleanup failed release'
50+
env:
51+
GH_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'
52+
RELEASE_VERSION: 'v${{ needs.create-release.outputs.version }}'
53+
REPO: '${{ github.repository }}'
54+
run: |-
55+
gh release delete "${RELEASE_VERSION}" \
56+
--repo "${REPO}" \
57+
--yes

0 commit comments

Comments
 (0)