name: Bump version

on:
  workflow_run:
    workflows: ["Lint"]
    branches: [master]
    types:
      - completed

jobs:
  tag-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.PAT_TOKEN }}
      - uses: actions/setup-node@v3
        with:
          node-version: 18
      - name: determine-version
        run: |
          VERSION=$(npx semantic-release --branches master --dry-run | { grep -i 'the next release version is' || test $? = 1; } | sed -E 's/.* ([[:digit:].]+)$/\1/')
          echo "VERSION=$VERSION" >> $GITHUB_ENV
        id: version
      - uses: rickstaa/action-create-tag@v1
        continue-on-error: true
        env:
          GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
        with:
          tag: v${{ env.VERSION }}
          message: "Releasing v${{ env.VERSION }}"
          github_token: ${{ secrets.PAT_TOKEN }}