name: Release

on:
  push:
    branches:
      - main
  pull_request:

env:
  NODE_NO_WARNINGS: 1
  CI: true
  NPM_CONFIG_PROVENANCE: true

jobs:
  dependencies:
    if: github.event_name == 'pull_request' && github.event.pull_request.title != 'Upcoming Release Changes'
    name: Dependencies
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}-dependencies
      cancel-in-progress: true
    uses: the-guild-org/shared-config/.github/workflows/changesets-dependencies.yml@v1
    with:
      node-version-file: .node-version
    secrets:
      githubToken: ${{ secrets.BOT_GITHUB_TOKEN }}
  snapshot:
    name: Snapshot
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}-release-snapshot
      cancel-in-progress: true
    permissions:
      contents: read
      id-token: write
      pull-requests: write
    uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@v1
    with:
      npmTag: alpha
      buildScript: build
      node-version-file: .node-version
    secrets:
      githubToken: ${{ secrets.BOT_GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}
  stable:
    if: github.ref == 'refs/heads/main'
    concurrency: ${{ github.workflow }}-${{ github.ref }}-release-stable
    name: Stable
    permissions:
      contents: read
      id-token: write
      pull-requests: write
    uses: the-guild-org/shared-config/.github/workflows/release-stable.yml@v1
    with:
      node-version-file: .node-version
      releaseScript: run release
      versionScript: run version
    secrets:
      githubToken: ${{ secrets.BOT_GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}
