name: Release
run-name: Release ${{ github.event.inputs.VERSION }}

on:
  workflow_dispatch:
    inputs:
      VERSION:
        description: The new version to release. (eg. `1.0.0`) Check the
          changelog for the latest version.

concurrency:
  group: '${{ github.event.inputs.VERSION }}'
  cancel-in-progress: true

jobs:
  docs:
    name: Release the gem
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    steps:
      - name: Prepare the environment
        uses: hausgold/actions/ci@v2
        with:
          clone_token: '${{ secrets.CLONE_TOKEN }}'
          settings_secret_key: '${{ secrets.SETTINGS_SECRET_KEY }}'
          settings: '${{ github.repository }}'
          target: ci/noop

      - name: Install the correct Node.js version
        uses: actions/setup-node@v6
        with:
          node-version: 25
          cache: 'npm'

      - name: Switch to SSH remotes for the Git repository
        run: git-ssh-remotes

      - name: Reconfigure NPM settings
        run: npm-auth-token-from-env ~/.npmrc

      - name: Enforce version '${{ github.event.inputs.VERSION }}'
        run: set-npm-package-version '${{ github.event.inputs.VERSION }}'

      - name: Prepare the Git release commit
        run: git-release-commit '${{ github.event.inputs.VERSION }}'

      - name: Push the release Git commit/tag and package to the registry
        run: make release

      - name: Build and upload application documentation
        run: api-docs && coverage --docs-only
        env:
          WORKFLOW_DISPATCH_TOKEN: '${{ secrets.WORKFLOW_DISPATCH_TOKEN }}'
          GITHUB_TAG: 'v${{ github.event.inputs.VERSION }}'
