name: Release It (test)
on:
  workflow_dispatch:

permissions:
  contents: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: git config
        run: |
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Use Latest Corepack
        run: |
          npm install -g corepack@latest
          corepack enable && corepack enable pnpm
          pnpm --version

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22.13.0
          cache: "pnpm"

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Release from Main (Stable)
        if: github.ref == 'refs/heads/main'
        run: if pnpm run should-semantic-release ; then  pnpm release-it --ci --verbose ; fi
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
          DOCKER_CHANNEL: latest # Updates the 'latest' tag on Docker Hub

      - name: Release from Dev (Pre-release)
        if: github.ref == 'refs/heads/dev'
        run: if pnpm run should-semantic-release ; then pnpm release-it --verbose --preRelease=dev --ci ; fi
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
          DOCKER_CHANNEL: dev # Updates the 'dev' tag on Docker Hub
