Skip to content

Commit 3c71380

Browse files
committed
Automate creating a PR for version bump
I wasn't able to make a PR that merged in the changes because of our branch protection rules. There are ways to bypass them but I think we'd have to create a specific app in order for us to target the bypass. Instead I thought an easier first step would be to automate creating a PR instead
1 parent 95c63f6 commit 3c71380

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

.github/workflows/bump-version.yml

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515

1616
permissions:
1717
contents: write
18+
pull-requests: write
1819

1920
jobs:
2021
bump-version:
@@ -37,15 +38,46 @@ jobs:
3738
git config user.email "github-actions[bot]@users.noreply.github.com"
3839
3940
- name: Bump version
40-
run: yarn version ${{ inputs.level }}
41+
id: bump_version
42+
run: |
43+
yarn version ${{ inputs.level }}
44+
VERSION=$(node -p 'require("./package.json").version')
45+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
4146
42-
- name: Commit and push
47+
- name: Commit and push
48+
env:
49+
VERSION: ${{ steps.bump_version.outputs.version }}
50+
BRANCH_NAME: actions/bump-version/v${{ steps.bump_version.outputs.version }}
4351
run: |
52+
if [ -z "$VERSION" ]; then
53+
echo "Version output is empty"
54+
exit 1
55+
fi
56+
4457
if git diff --quiet; then
4558
echo "No changes to commit"
4659
exit 1
4760
fi
4861
4962
git add -A
50-
git commit -m "Bump version (${{ inputs.level }}) for release"
51-
git push origin HEAD:${{ github.ref_name }}
63+
git commit -m "Bump version to v$VERSION"
64+
git push --force origin HEAD:$BRANCH_NAME
65+
66+
- name: Create PR
67+
env:
68+
GH_TOKEN: ${{ github.token }}
69+
BASE_BRANCH: main
70+
HEAD_BRANCH: actions/bump-version/v${{ steps.bump_version.outputs.version }}
71+
PR_TITLE: Bump version to v${{ steps.bump_version.outputs.version }}
72+
PR_BODY: |
73+
Version: v${{ steps.bump_version.outputs.version }}
74+
75+
Automated version bump generated by this workflow run:
76+
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
77+
run: |
78+
gh pr create \
79+
--repo "${{ github.repository }}" \
80+
--base "$BASE_BRANCH" \
81+
--head "$HEAD_BRANCH" \
82+
--title "$PR_TITLE" \
83+
--body "$PR_BODY"

0 commit comments

Comments
 (0)