name: "Create Tagged Release"

on:
  workflow_dispatch:
    inputs:
      release_version:
        description: 'Version number of the release'
        required: true
      prerelease:
        description: 'Mark as pre-release (RC versions)'
        required: false
        type: boolean
        default: false

permissions:
  contents: write
  pages: write
  id-token: write
        
jobs:
  gh_tagged_release:
    name: Create tagged release
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest

    steps:
      - name: Checkout project
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #7.0.1

      - name: Setup Git
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com

      - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86
        name: Install pnpm
        with:
          version: 9
          run_install: false
      - name: Install Node.js
        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020
        with:
            node-version: 24
            cache: 'pnpm'
      - name: Install dependencies
        run: pnpm install --frozen-lockfile --ignore-scripts

      - name: Set app version (Unix)
        run: npm version ${{ github.event.inputs.release_version }} --no-git-tag-version

      - name: Build Project
        run: pnpm run build

      - uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d #v6.0.0
      - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 #7.0.0
        with:
          python-version: 3.x
      - run: "pip install --only-binary :all: zensical==0.0.52"
        working-directory: docs
      - run: zensical build --clean
        working-directory: docs
      - uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 #5.0.0
        with:
          path: docs/site
      - uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 #5.0.0

      - name: "Create Github release (full)"
        uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 #v2
        id: expander_card_release
        with:
          body: "Release version ${{ github.event.inputs.release_version }}."
          tag_name: ${{ github.event.inputs.release_version }}
          target_commitish: "main"
          draft: false
          prerelease: ${{ github.event.inputs.prerelease }}
          files: dist/*
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN  }}

      - name: "Notify issues of release their fix is contained in"
        if: ${{ !github.event.inputs.prerelease }}
        uses: apexskier/github-release-commenter@e7813a9625eabd79a875b4bc4046cfcae377ab34 # v1.4.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          comment-template: |
            Release {release_link} addresses this.
