Publish a release #14
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
name: Publish a release | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
required: true | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
env: | |
PR_BRANCH: release-ci-${{ github.sha }} | |
jobs: | |
prepare_metadata: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.bump_version.outputs.version }} | |
release_sha: ${{ steps.merge_pr.outputs.sha }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Jan Buchar" | |
- name: Create branch | |
run: | | |
git switch -c ${{ env.PR_BRANCH }} | |
- name: Bump version in package.json | |
id: bump_version | |
run: | | |
npm version ${{ github.event.inputs.release_type }} | |
echo version=$( node -p "require('./package.json').version" ) >> "$GITHUB_OUTPUT" | |
git push --set-upstream origin ${{ env.PR_BRANCH }} | |
- name: Create PR | |
run: | | |
gh pr create \ | |
--base master \ | |
--head ${{ env.PR_BRANCH }} \ | |
--title "chore: Release ${{ steps.bump_version.outputs.version }} [skip-ci]" \ | |
--body "Automated pull request - update to ${{ steps.bump_version.outputs.version }}" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Approve and merge PR | |
id: merge_pr | |
run: | | |
gh pr review --approve ${{ env.PR_BRANCH }} | |
gh pr merge --squash --auto --delete-branch ${{ env.PR_BRANCH }} | |
echo sha=$( gh pr view --json mergeCommit ${{ env.PR_BRANCH }} | jq --raw-output .mergeCommit.oid ) >> "$GITHUB_OUTPUT" | |
env: | |
GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }} | |
gh_release: | |
runs-on: ubuntu-latest | |
needs: prepare_metadata | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Create release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: release-${{ needs.prepare_metadata.outputs.version }} | |
name: Release ${{ needs.prepare_metadata.outputs.version }} | |
target_commitish: ${{ needs.prepare_metadata.outputs.release_sha }} |