Skip to content

Commit 6c5b8c2

Browse files
authored
Add workflow for creating release PR's (#360)
Add a workflow for creating release PR's. This way we don't have to do it locally, and we guarantee the `npm` version used to generate the version bump is consistent and stays in-sync with the repo instead of whatever the dev happened to have on their local computer.
1 parent c40140b commit 6c5b8c2

File tree

3 files changed

+91
-24
lines changed

3 files changed

+91
-24
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Release - Bump Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: "Version Type?"
8+
required: true
9+
type: choice
10+
options:
11+
- major
12+
- minor
13+
- patch
14+
default: "minor"
15+
16+
jobs:
17+
Create-PR-To-Bump-Fetch-Metadata-Version:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
# Ensure we start from main in case the workflow is run from a branch
24+
ref: "main"
25+
token: ${{ secrets.DEPENDABOT_AUTOMATION_PAT }}
26+
27+
- uses: actions/setup-node@v3 # bin/bump-version needs npm
28+
with:
29+
node-version-file: .nvmrc
30+
31+
- name: Bump the version
32+
# Currently we don't run via `schedule` trigger since this repo isn't active enough.
33+
# However, if that ever changes, it will run with no inputs, so version_type will default to 'minor'
34+
run: |
35+
NEW_VERSION=$(bin/bump-version ${{ github.event.inputs.version_type || 'minor' }})
36+
echo "New version is: $NEW_VERSION"
37+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
38+
39+
- name: Configure the git user
40+
run: |
41+
git config user.name "github-actions[bot]"
42+
# Specifying the full email allows the avatar to show up: https://github.com/orgs/community/discussions/26560
43+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
44+
45+
- name: Create a branch and commit the changes
46+
run: |
47+
# Using an idempotent branch name ensures no duplicate PR's are created
48+
# if the action is re-run before the previous PR is merged.
49+
# The branch name is purposefully different from the release tag to
50+
# avoid ambiguity when selecting git refs.
51+
git checkout -b "bump-to-${{ env.NEW_VERSION }}"
52+
git add package.json package-lock.json
53+
echo "Creating commit / PR linking to the releases notes URL."
54+
echo "This URL will 404 until the release is actually tagged, which you should do as soon as the PR is merged."
55+
git commit -m "${{ env.NEW_VERSION }}" -m "Release notes: https://github.com/${{ github.repository }}/releases/tag/${{ env.NEW_VERSION }}"
56+
57+
- name: Push the branch
58+
run: |
59+
echo "Pushing branch to remote. If this fails, check if a branch/PR already exists for this version."
60+
git config push.autoSetupRemote true
61+
git push
62+
63+
- name: Create a PR from the branch with the commit
64+
run: |
65+
PR_URL=$(gh pr create --fill) # `fill` re-uses the title / body from the commit
66+
echo "PR created at URL: $PR_URL"
67+
echo "PR_URL=$PR_URL" >> $GITHUB_ENV
68+
env:
69+
GH_TOKEN: ${{ secrets.DEPENDABOT_AUTOMATION_PAT }}
70+
71+
- name: Set summary
72+
run: |
73+
echo ":rocket: PR created at URL: ${{ env.PR_URL }}" >> $GITHUB_STEP_SUMMARY
74+
echo "" >> $GITHUB_STEP_SUMMARY
75+
echo "After the PR is approved/merged, create a new release tagged as \`${{ env.NEW_VERSION }}\`, _making sure to point it at the merge commit_:" >> $GITHUB_STEP_SUMMARY
76+
echo "* You can do this via the web UI - use the \`Generate release notes\` button and then edit as needed: https://github.com/${{ github.repository }}/releases/new?tag=${{ env.NEW_VERSION }}&title=${{ env.NEW_VERSION }}" >> $GITHUB_STEP_SUMMARY
77+
echo "* Or via the GitHub CLI:" >> $GITHUB_STEP_SUMMARY
78+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
79+
echo " gh release create ${{ env.NEW_VERSION }} --title ${{ env.NEW_VERSION }} --generate-notes --draft" >> $GITHUB_STEP_SUMMARY
80+
echo " > https://github.com/${{ github.repository }}/releases/tag/untagged-XXXXXX" >> $GITHUB_STEP_SUMMARY
81+
echo " # Use the generated URL to review/edit the release notes." >> $GITHUB_STEP_SUMMARY
82+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
83+
echo "Once the release is tagged, move the floating \`v1\` tag to point at this release." >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,13 @@ jobs:
193193

194194
## Tagging a new release
195195

196-
1. Checkout and update `main`, then use the `bin/bump-version` script to create a release PR
197-
```bash
198-
git checkout main
199-
git pull
200-
bin/bump-version minor # major | minor | patch
201-
```
202-
2. Merge the PR after getting it reviewed
203-
3. Create a new release tagged as `v1.X.X` format:
204-
- Either via the web UI: https://github.com/dependabot/fetch-metadata/releases/new
205-
- Or via the CLI:
206-
```bash
207-
gh release create v1.X.X --generate-notes --draft
208-
> https://github.com/dependabot/fetch-metadata/releases/tag/untagged-XXXXXX
209-
# Use the generated URL to review/edit the release notes, and then publish it.
210-
```
196+
Publish a new release by running the [`Release - Bump Version`](https://github.com/dependabot/fetch-metadata/actions/workflows/release-bump-version.yml) workflow and following the instructions on the job summary.
197+
198+
In a nutshell the process will be:
199+
200+
1. Run the action to generate a version bump PR.
201+
2. Merge the PR.
202+
3. Tag that merge commit as a new release using the format `v1.2.3`. The job summary contains a URL pre-populated with the correct version for the title and tag.
211203
4. Update the `v1` tracking tag to point to the new version
212204
```bash
213205
git fetch --all --tags

bin/bump-version

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@ usage() { echo "Usage: $0 [ major | minor | patch ]" 1>&2; exit 1; }
44

55
version_type=$1
66
if [ "$version_type" == "major" ] || [ "$version_type" == "minor" ] || [ "$version_type" == "patch" ]; then
7-
new_version=$(npm version "$version_type" --no-git-tag-version)
7+
new_version=$(npm version "$version_type" --no-git-tag-version) || exit
88
echo "$new_version"
9-
10-
git checkout -b "${new_version}"-release-notes
11-
git add package.json package-lock.json
12-
echo "Creating commit / PR linking to the releases notes URL."
13-
echo "This URL will 404 until the release is actually tagged, which you should do as soon as the PR is merged."
14-
git commit -m "${new_version}" -m "Release notes: https://github.com/dependabot/fetch-metadata/releases/tag/v${new_version}"
15-
gh pr create --fill # `fill` re-uses the title / body from the commit
16-
echo "PR created for ${new_version}"
179
else
1810
usage
1911
fi

0 commit comments

Comments
 (0)