name: Build - Mac M1

on:
  workflow_dispatch:
  # push:
  #   tags:
  #     - v*

env:
  ACTIONS_ALLOW_UNSECURE_COMMANDS: true

jobs:
  build-macos:
    runs-on: macos-11
    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3
      - name: Install OpenSSL
        run: |
          wget https://mac.r-project.org/bin/darwin20/arm64/openssl-1.1.1o-darwin.20-arm64.tar.xz
          tar -xf openssl-1.1.1o-darwin.20-arm64.tar.xz -C /tmp
          rm -rf openssl-1.1.1o-darwin.20-arm64.tar.xz
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - name: Build
        run: |
          npm install --ignore-scripts
          node_modules/.bin/prebuild -r napi --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_OSX_ARCHITECTURES="arm64"
        env:
          CI: true
          OPENSSL_ROOT_DIR: /tmp/opt/R/arm64
          OPENSSL_LIBRARIES: /tmp/opt/R/arm64/lib
