Skip to content

Commit d221528

Browse files
authored
Update release process (1/n) (#38)
1 parent 6900f1e commit d221528

1 file changed

Lines changed: 39 additions & 97 deletions

File tree

.github/workflows/draft-release.yml

Lines changed: 39 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -11,132 +11,74 @@ on:
1111
ACTIONS_BOT_TOKEN:
1212
required: true
1313

14-
env:
15-
PR_BRANCH: 'actions/draft-release-${{ github.ref_name }}'
16-
1714
jobs:
1815
draft-release:
1916
name: 'Draft Release'
2017
runs-on: 'ubuntu-latest'
21-
permissions:
22-
contents: 'write'
2318
steps:
2419
- uses: 'actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11' # ratchet:actions/checkout@v4
2520

2621
- uses: 'actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8' # ratchet:actions/setup-node@v4
2722
with:
2823
node-version: '22.x'
2924

30-
- name: 'Build and push'
25+
- name: 'Build'
26+
id: 'build'
3127
shell: 'bash'
3228
env:
3329
VERSION_STRATEGY: '${{ inputs.version_strategy }}'
3430
run: |-
35-
# configure username and email for git to show who made the changes
36-
git config user.name "google-github-actions-bot"
37-
git config user.email "github-actions-bot@google.com"
38-
39-
git checkout -b $PR_BRANCH
40-
41-
npm version $VERSION_STRATEGY --git-tag-version=false
42-
43-
NEW_VERSION=$(cat package.json | jq -r .version)
44-
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
31+
CURRENT_VERSION="$(jq -r .version ./package.json)"
32+
echo "::debug::computed current version: ${CURRENT_VERSION}"
33+
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_ENV
34+
35+
npm version "${VERSION_STRATEGY}" \
36+
--no-git-tag-version \
37+
--no-commit-hooks \
38+
--no-workspaces-update
39+
NEXT_VERSION="$(jq -r .version ./package.json)"
40+
echo "::debug::computed next version: ${NEXT_VERSION}"
41+
echo "next_version=${NEXT_VERSION}" >> $GITHUB_ENV
4542
4643
npm ci
4744
[[ "$(npm run --json | jq -r 'has("docs")')" == "true" ]] && npm run docs
4845
npm run build
4946
50-
git add .
51-
git commit -m "Release: v${NEW_VERSION}"
52-
git push origin $PR_BRANCH --force
53-
5447
- name: 'Generate release notes'
48+
id: 'generate-release-notes'
5549
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
50+
env:
51+
CURRENT_VERSION: '${{ steps.build.outputs.current_version }}'
52+
NEXT_VERSION: '${{ steps.build.outputs.next_version }}'
5653
with:
54+
github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
5755
script: |-
58-
let previousTagName = "";
59-
56+
let releaseNotes = '';
6057
try {
61-
const latestRelease = await github.rest.repos.getLatestRelease({
58+
const releaseNotesResponse = await github.rest.repos.generateReleaseNotes({
6259
owner: context.repo.owner,
6360
repo: context.repo.repo,
61+
tag_name: `v${process.env.NEXT_VERSION}`,
62+
previous_tag_name: `v${process.env.CURRENT_VERSION}`,
6463
});
65-
previousTagName = latestRelease.data.tag_name;
66-
} catch (err) {
67-
if (err["status"] !== 404) {
68-
core.setFailed(`Failed to load latest release: ${err}`);
69-
}
70-
71-
core.info(`No existing releases found`);
64+
releaseNotes = releaseNotesResponse.data.body;
65+
} catch(err) {
66+
core.warning('No existing releases found, assuming initial release');
67+
releaseNotes = 'Initial release'
7268
}
69+
core.setOutput('release_notes', releaseNotes)
7370
74-
try {
75-
const releaseNotesRequest = {
76-
owner: context.repo.owner,
77-
repo: context.repo.repo,
78-
tag_name: context.sha,
79-
target_commitish: context.sha,
80-
};
81-
82-
if (previousTagName) {
83-
releaseNotesRequest.previous_tag_name = previousTagName;
84-
}
85-
86-
const releaseNotes = await github.rest.repos.generateReleaseNotes(
87-
releaseNotesRequest
88-
);
89-
90-
core.exportVariable("RELEASE_NOTES", releaseNotes.data.body)
91-
} catch (err) {
92-
core.setFailed(`Failed to generate release notes: ${err}`);
93-
}
71+
# TODO(sethvargo): remove
72+
- name: 'debug'
73+
run: |-
74+
echo "::notice::${{ toJSON(github) }}"
9475
95-
- name: 'Create Pull Request'
96-
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
76+
- name: 'Create/Update Pull Request'
77+
uses: 'abcxyz/pkg/.github/actions/create-pull-request@main' # ratchet:exclude
9778
with:
98-
github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
99-
script: |-
100-
const tag = "v" + process.env.NEW_VERSION;
101-
102-
try {
103-
const listResponse = await github.rest.pulls.list({
104-
owner: context.repo.owner,
105-
repo: context.repo.repo,
106-
state: "open",
107-
head: context.repo.owner + ":" + process.env.PR_BRANCH,
108-
base: process.env.GITHUB_REF_NAME,
109-
});
110-
111-
core.isDebug() && console.log(listResponse);
112-
113-
if (!listResponse.data.length) {
114-
const createResponse = await github.rest.pulls.create({
115-
owner: context.repo.owner,
116-
repo: context.repo.repo,
117-
title: "Release: " + tag,
118-
body: process.env.RELEASE_NOTES,
119-
head: process.env.PR_BRANCH,
120-
base: process.env.GITHUB_REF_NAME,
121-
});
122-
123-
core.info(
124-
`Created PR #${createResponse.data.number} at ${createResponse.data.html_url}`
125-
);
126-
} else {
127-
const updateResponse = await github.rest.pulls.update({
128-
owner: context.repo.owner,
129-
repo: context.repo.repo,
130-
pull_number: listResponse.data[0].number,
131-
title: "Release: " + tag,
132-
body: process.env.RELEASE_NOTES,
133-
});
134-
135-
core.info(
136-
`Updated PR #${updateResponse.data.number} at ${updateResponse.data.html_url}`
137-
);
138-
}
139-
} catch (err) {
140-
console.error(err);
141-
core.setFailed(`Failed to create pull request: ${err}`);
142-
}
79+
token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
80+
base_branch: '${{ github.event.repository.default_branch }}' # TODO: pull from trigger branch instead (for release builds)
81+
head_branch: 'actions/draft-release-${{ github.ref_name }}'
82+
title: 'Release: v${{ steps.build.outputs.next_version }}'
83+
body: '${{ steps.generate-release-notes.outputs.release_notes }}'
84+
compute_paths: true

0 commit comments

Comments
 (0)