code-baseline 1.6.0

Enforce architectural decisions AI coding tools keep ignoring
Documentation
name: Release npm packages

on:
  release:
    types: [published]

permissions:
  contents: write
  id-token: write

jobs:
  build:
    strategy:
      matrix:
        include:
          - target: aarch64-apple-darwin
            os: macos-latest
            npm-dir: cli-darwin-arm64
            binary: baseline
          - target: x86_64-apple-darwin
            os: macos-latest
            npm-dir: cli-darwin-x64
            binary: baseline
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            npm-dir: cli-linux-x64
            binary: baseline
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            npm-dir: cli-linux-arm64
            binary: baseline
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            npm-dir: cli-win32-x64
            binary: baseline.exe

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install cross-compilation tools (Linux ARM64)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Build
        env:
          RUSTFLAGS: "-C strip=symbols"
          CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
        run: cargo build --release --target ${{ matrix.target }}

      - name: Copy binary to npm package
        shell: bash
        run: |
          cp target/${{ matrix.target }}/release/${{ matrix.binary }} npm/${{ matrix.npm-dir }}/${{ matrix.binary }}
          chmod +x npm/${{ matrix.npm-dir }}/${{ matrix.binary }}

      - name: Upload binary as release asset
        shell: bash
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          ASSET_NAME="baseline-${{ matrix.target }}"
          if [[ "${{ matrix.binary }}" == *.exe ]]; then
            ASSET_NAME="${ASSET_NAME}.exe"
          fi
          cp npm/${{ matrix.npm-dir }}/${{ matrix.binary }} "${ASSET_NAME}"
          gh release upload "${{ github.ref_name }}" "${ASSET_NAME}" --clobber

      - name: Upload npm package artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.npm-dir }}
          path: npm/${{ matrix.npm-dir }}/

  publish:
    needs: build
    runs-on: ubuntu-latest
    environment: npm-publish

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "22"

      - name: Upgrade npm for trusted publishing
        run: npm install -g npm@latest

      - name: Download all platform artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts/

      - name: Copy binaries into npm packages
        run: |
          for dir in cli-darwin-arm64 cli-darwin-x64 cli-linux-x64 cli-linux-arm64 cli-win32-x64; do
            cp artifacts/${dir}/* npm/${dir}/
          done

      - name: Verify packages
        run: |
          for dir in cli-darwin-arm64 cli-darwin-x64 cli-linux-x64 cli-linux-arm64 cli-win32-x64; do
            echo "=== npm/${dir} ==="
            ls -la npm/${dir}/
          done

      - name: Publish platform packages
        run: |
          for dir in cli-darwin-arm64 cli-darwin-x64 cli-linux-x64 cli-linux-arm64 cli-win32-x64; do
            echo "Publishing @code-baseline/cli-${dir}..."
            npm publish ./npm/${dir} --access public --provenance
          done

      - name: Publish root CLI package
        run: npm publish ./npm/cli --access public --provenance