name: Build documentation site to nist-pages

on:
  push:
    branches: ["nist-pages-docs"]
  workflow_dispatch:

permissions:
  contents: write
  pages: write
  id-token: write

concurrency:
  group: "pages"
  cancel-in-progress: false

env:
  BUILD_PATH: "."
  SITE_PATH: "https://pages.nist.gov/"
  BASE_PATH: "/macos_security"

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7
      - name: Setup PNPM
        uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
        with:
          version: 8
      - name: Setup Node
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
        with:
          node-version: "22"
          cache: pnpm
          cache-dependency-path: ${{ env.BUILD_PATH }}/pnpm-lock.yaml
      - name: Install dependencies
        run: pnpm install
        working-directory: ${{ env.BUILD_PATH }}
      - name: Build with Astro
        run: |
          pnpm astro build \
            --site "${{ env.SITE_PATH }}" \
            --base "${{ env.BASE_PATH }}"
        working-directory: ${{ env.BUILD_PATH }}
      - name: Upload to nist-pages
        uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ${{ env.BUILD_PATH }}/dist
          publish_branch: nist-pages
