Release version 4.0.0 #72
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- main | |
name: Update versions and create release PR | |
jobs: | |
is_merged: | |
name: Check that PR was merged and not closed | |
if: > | |
github.event.pull_request.merged == true | |
&& ( contains(github.event.pull_request.labels.*.name, 'major') | |
|| contains(github.event.pull_request.labels.*.name, 'minor') | |
|| contains(github.event.pull_request.labels.*.name, 'patch') | |
) | |
runs-on: ubuntu-latest | |
steps: | |
- run: | | |
echo "This is a canonical hack to run GitHub Actions on merged PRs" | |
echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges" | |
release: | |
name: Bump version and create PR | |
needs: is_merged | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Bump version | |
id: bump_version | |
env: | |
is_major: ${{ contains(github.event.pull_request.labels.*.name, 'major') }} | |
is_minor: ${{ contains(github.event.pull_request.labels.*.name, 'minor') }} | |
is_patch: ${{ contains(github.event.pull_request.labels.*.name, 'patch') }} | |
run: | | |
sudo apt-get install jq | |
echo "old_version=$(jq --raw-output '.version' package.json)" >> "$GITHUB_OUTPUT" | |
# Bump the version and commit the changes. | |
if [[ "$is_major" == "true" ]]; then | |
npm version major --no-git-tag-version | |
elif [[ "$is_minor" == "true" ]]; then | |
npm version minor --no-git-tag-version | |
elif [[ "$is_patch" == "true" ]]; then | |
npm version patch --no-git-tag-version | |
fi | |
new_version=$(jq --raw-output '.version' package.json) | |
sed -i "0,/## \[unreleased\]/{s//## [unreleased]\n\n## [$new_version]/}" CHANGELOG.md | |
echo "new_version=$new_version" >> "$GITHUB_OUTPUT" | |
- name: Create release PR | |
id: release_pr | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
# I use a personal access token with the `repo` scope. | |
# Actions performed with the default GITHUB_TOKEN do not trigger subsequent actions. | |
# See <https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow>. | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
branch: release/${{ steps.bump_version.outputs.new_version }} | |
delete-branch: true | |
base: main | |
title: Release version ${{ steps.bump_version.outputs.new_version }} | |
body: | | |
Update version to ${{ steps.bump_version.outputs.new_version }}. | |
Merge this PR to build and publish a new release. | |
labels: release | |
- name: Comment on PR with link to release PR | |
uses: peter-evans/create-or-update-comment@v2 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
A [PR][pr] to release these changes has been created, bumping the version from ${{ steps.bump_version.outputs.old_version }} to ${{ steps.bump_version.outputs.new_version }}. | |
[pr]: ${{ steps.release_pr.outputs.pull-request-url }} |