name: Create Version Tag

on:
  push:
    branches:
      - main
      - "prerelease-*"

jobs:
  version-check:
    runs-on: ubuntu-latest
    outputs:
      tag_created: ${{ steps.tag.outputs.tag_created }}
      tag_name: ${{ steps.tag.outputs.tag_name }}
    steps:
      - uses: actions/checkout@v4
      - name: Run version check
        id: tag
        uses: https://git.cyborggrizzly.com/bearmetal/ci-actions/version-check@v1

  build-release:
    if: needs.version-check.outputs.tag_created == 'true'
    needs: version-check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Build and release binaries
        uses: https://git.cyborggrizzly.com/bearmetal/ci-actions/deno-release@main
        with:
          entrypoint: main.ts
          compile-flags: "--allow-read --allow-write --allow-env --allow-net --include asciiart.txt"
        env:
          GITEA_TOKEN: ${{ secrets.GIT_PAT }}

  publish-release:
    needs: build-release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Deno
        uses: denoland/setup-deno@v1
        with:
          deno-version: 2.3.1

      - name: Publish to JSR
        run: deno publish --token ${{ secrets.JSR_PAT }}
