name: Test & Release
on:
  push:
jobs:
  release:
    name: Test & Release
    runs-on: ubuntu-latest
    permissions:
      # https://github.com/semantic-release/semantic-release/issues/2469
      contents: write # create releases
      issues: write # issue comments and labels
      pull-requests: write # ditto
      id-token: write # The OIDC ID token is used for authentication with JSR.

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Use pnpm
        uses: pnpm/action-setup@v4

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

      - name: Install dependencies
        run: pnpm install

      - uses: oven-sh/setup-bun@v2
      - uses: denoland/setup-deno@v2
        with:
          deno-version: v2.x

      - name: Run CI script (tests)
        run: npm run ci

      - name: Prepare packages for next step (remove after non-sha release)
        run: cd /home/runner/work/_actions/gaelgirodon/ci-badges-action && npm i -D @actions/core @actions/github @actions/glob

      - name: Upload coverage to gist
        uses: gaelgirodon/ci-badges-action@4059134f9f9e113d77dd4f05a47db8b62c09848c
        with:
          gist-id: 26d0f88b04b6883e1a6bba5b9b344fab
          token: ${{ secrets.GH_TOKEN_GISTS }}

      - name: Save runtime tests result to gist
        uses: exuanbo/actions-deploy-gist@v1
        with:
          token: ${{ secrets.GH_TOKEN_GISTS }}
          gist_id: f66f0ad9395e4019ec5209719377650b
          file_path: ./tests/runtimes/results.yaml

      - name: Release if relevant
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release
