.github/workflows/bump.yml #2
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: | |
workflow_dispatch: | |
inputs: | |
type: | |
description: 'Select the type of version bump' | |
required: true | |
type: choice | |
default: 'patch' | |
options: | |
- patch | |
- minor | |
- major | |
jobs: | |
bump: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
steps: | |
- name: Set up checkout | |
uses: actions/checkout@v4 | |
- name: Set up node | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
cache: npm | |
- name: Set up cache | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
- name: Set up node_modules | |
run: npm ci | |
- name: Set up SHA | |
run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV | |
- name: Set up old version | |
run: echo "OLD_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Set up github | |
run: | | |
git config --global user.name 'github-actions' | |
git config --global user.email '[email protected]' | |
git switch -c release-${{ inputs.type }}-${{ env.SHORT_SHA }} | |
- name: Bump | |
run: | | |
npm version ${{ inputs.type }} -m "release(${{ inputs.type }}): v%s" | |
- name: Set up new version | |
run: echo "NEW_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Push | |
run: | | |
git push --set-upstream origin release-${{ inputs.type }}-${{ env.SHORT_SHA }} | |
- name: Create pull request | |
run: | | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${{ github.repository }}/pulls \ | |
-f "title=release(${{ inputs.type }}): v${{ env.NEW_VERSION }}" \ | |
-f "body=Bump \`${{ github.repository }}\` from v${{ env.OLD_VERSION }} to v${{ env.NEW_VERSION }} :tada:" \ | |
-f "head=${{ github.repository_owner }}:release-${{ inputs.type }}-${{ env.SHORT_SHA }}" \ | |
-f "base=main" |