Skip to content

.github/workflows/bump.yml #4

.github/workflows/bump.yml

.github/workflows/bump.yml #4

Workflow file for this run

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.GITHUB_TOKEN }}
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 environment variables
run: |
echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
echo "OLD_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
- name: Bump
run: |
git config --global user.name 'github-actions'
git config --global user.email 'actions@github.com'
git switch -c release-${{ inputs.type }}-${{ env.SHORT_SHA }}
npm version ${{ inputs.type }} -m "release(${{ inputs.type }}): v%s"
- name: Set up environment variables
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"