# This workflow bumps the package.json version and creates a PR

name: Update package version

on:
  workflow_dispatch:
    inputs:
      segment:
        description: 'Semver segment to update'
        required: true
        default: 'patch'
        type: choice
        options:
        - minor
        - patch

jobs:
  update-version:
    name: Update package version
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
        with:
          node-version: 20
          cache: 'npm'
      - run: echo "Updating ${{ inputs.segment }} version"
      - name: Update version
        run: npm --no-git-tag-version version ${{ inputs.segment }}
      - uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
        with:
          base: 'main'
          branch: 'version/automated'
          title: 'Update package version (automated)'
          commit-message: 'Update package version'
          body: 'Automated update to ${{ inputs.segment }} version'
          token: ${{ secrets.DISPATCH_TOKEN }}
