name: release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  id-token: write

jobs:
  release:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
      - name: Release
        uses: goreleaser/goreleaser-action@v7
        with:
          distribution: goreleaser
          version: "~> v2"
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/setup-node@v6
        with:
          node-version: 24
          registry-url: https://registry.npmjs.org
          package-manager-cache: false
      - name: Prepare npm packages
        run: node packaging/npm/scripts/prepare-packages.mjs --dist dist --out dist/npm --version "${GITHUB_REF_NAME#v}"
      - name: Smoke test npm packages
        run: node packaging/npm/scripts/smoke-test.mjs --packages-dir dist/npm
      - name: Publish npm packages
        run: node packaging/npm/scripts/publish.mjs --packages-dir dist/npm
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
