name: pr
on:
  pull_request: {}

concurrency:
  group: pr-${{ github.event.pull_request.number }}
  cancel-in-progress: true

env:
  HIVE_TOKEN: ${{ secrets.HIVE_TOKEN }}

jobs:
  # Database Types Diff Check
  # We are committing the database types located under the "storage" package, to make it easier to maintain.
  # This workflow validates that the types are up to date in the repository, and fails in case of a change that is not committed.
  db-types:
    uses: ./.github/workflows/db-types-diff.yaml

  # GraphQL Breaking Changes Check
  # This workflow validates that the GraphQL schema is not breaking, and fails in case of a breaking change.
  # To allow a GraphQL breaking change in a PR, you may add the "non-breaking" label to the PR.
  graphql-breaking-changes:
    uses: ./.github/workflows/graphql-schema-check.yaml
    secrets:
      hiveToken: ${{ secrets.HIVE_TOKEN }}

  # Build all packages and applications, and creates Docker images
  build:
    name: build
    uses: ./.github/workflows/build-and-dockerize.yaml
    with:
      dockerize: ${{ !github.event.pull_request.head.repo.fork }}
      imageTag: ${{ github.event.pull_request.head.sha }}
      publishLatest: false
      targets: 'build'
      uploadJavaScriptArtifacts: true
    secrets: inherit

  # Run db migrations tests
  db-migration-tests:
    name: test
    uses: ./.github/workflows/tests-db-migrations.yaml

  # Unit tests using Vitest
  unit-tests:
    name: test
    uses: ./.github/workflows/tests-unit.yaml

  # Integration tests that are based on Docker images created during build step.
  integration-tests:
    name: test
    needs: build
    uses: ./.github/workflows/tests-integration.yaml
    secrets:
      stripeTestPublicKey: ${{ secrets.TEST_STRIPE_PUBLIC_KEY }}
      stripeTestSecretKey: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
    with:
      imageTag: ${{ github.event.pull_request.head.sha }}

  # e2e tests using Cypress, runs Hive from pre-built Docker images.
  e2e:
    name: test
    needs: build
    uses: ./.github/workflows/tests-e2e.yaml
    with:
      imageTag: ${{ github.event.pull_request.head.sha }}

  # Changeset Validation
  # Validates that changesets reference valid packages that exist in the monorepo
  changeset-validation:
    uses: ./.github/workflows/changeset-validation.yaml

  # ESLint and Prettier
  code-style:
    uses: ./.github/workflows/lint.yaml

  # TypeScript Typecheck and compiler checks
  typescript:
    uses: ./.github/workflows/typescript-typecheck.yaml

  # Release alpha version on NPM for Hive libraries
  alpha:
    uses: ./.github/workflows/release-alpha.yaml
    if: ${{ github.event.pull_request.title != 'Upcoming Release Changes' }}
    secrets: inherit

  # Release RC version on NPM for Hive libraries
  release-candidate:
    uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@main
    if: ${{ github.event.pull_request.title == 'Upcoming Release Changes' }}
    with:
      npmTag: rc
      restoreDeletedChangesets: true
      buildScript: build:libraries
      packageManager: pnpm
      nodeVersion: '24.13'
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}
