name: ci
on:
  push:
    branches:
      - "**"

defaults:
  run:
    # NOTE: A bit stricter than the default bash options used by GitHub Actions
    # (bash --noprofile --norc -e -o pipefail {0})
    shell: bash --noprofile --norc -euo pipefail {0}

# NOTE: Set concurrency for the current workflow to 1
concurrency: ci-${{ github.ref }}-${{ github.workflow }}

jobs:
  build-and-release:
    timeout-minutes: 60
    runs-on: ubuntu-24.04
    permissions:
      id-token: write  # Required for OIDC
      contents: write
      pull-requests: write
      issues: write
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          node-version-file: ".node-version"
      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version-file: ".bun-version"

      - name: build and test
        run: make ci

      - name: conditionally pack
        if: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
        run: npm pack

      - name: conditionally semantic release
        if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: npm run semantic-release
