# This workflow will prebuild native binaries for supported NodeJS versions, and add them to the Github release that triggered the workflow

name: Add native binaries to release

on:
  release:
    types: [created]

jobs:
  augment-release:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node-version: [18.x, 20.x, 22.x, 24.x]
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Add msbuild to PATH
        if: matrix.os == 'windows-latest'
        uses: microsoft/setup-msbuild@v1.1
      - name: Install node-gyp
        if: matrix.os == 'windows-latest'
        shell: powershell
        run: |
          npm install --global npm@latest
          npm install --global node-gyp@latest
      - name: build using node-pre-gyp
        run: |
          npm install --build-from-source
          npx node-pre-gyp package
      - name: Upload native binaries for Node ${{ matrix.node-version }} for ${{ matrix.os }}
        uses: csexton/release-asset-action@v2
        with:
          pattern: "build/stage/*.tar.gz"
          github-token: ${{ secrets.GITHUB_TOKEN }}
          release-url: ${{ github.event.release.upload_url }}

  alpine-release:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20, 22, 24]
    container: node:${{ matrix.node-version }}-alpine3.20
    steps:
      - uses: actions/checkout@v2
      - name: install build deps
        run: |
          apk add g++ make python3
      - name: build using node-pre-gyp
        run: |
          npm install
          npx node-pre-gyp rebuild
          npx node-pre-gyp package
      - name: Upload native binaries for Node ${{ matrix.node-version }} for alpine
        uses: csexton/release-asset-action@v2
        with:
          pattern: "build/stage/*.tar.gz"
          github-token: ${{ secrets.GITHUB_TOKEN }}
          release-url: ${{ github.event.release.upload_url }}
