name: CI (MacStadium)
on:
  - push
  - pull_request
permissions: {}
jobs:
  CI:
    permissions:
      contents: write # for npx prebuild to make release
    name: Node.js ${{ matrix.nodejs_version }} ${{ matrix.nodejs_arch }} ${{ matrix.prebuild && '- prebuild' }}
    runs-on: macos-m1
    strategy:
      fail-fast: false
      matrix:
        include:
          - nodejs_version: 14
            nodejs_arch: x64
          - nodejs_version: 18
            nodejs_arch: arm64
            prebuild: true
    defaults:
      run:
        shell: /usr/bin/arch -arch arm64e /bin/bash -l {0}
    steps:
      - name: Dependencies (Node.js)
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs_version }}
          architecture: ${{ matrix.nodejs_arch }}
      - name: Checkout
        uses: actions/checkout@v3
      - name: Install
        run: npm install --build-from-source --unsafe-perm
      - name: Test
        run: npm test
      - name: Prebuild
        if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
        env:
          prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
        run: npx prebuild --runtime napi --target 7
