name: Build artifacts

on:
  workflow_dispatch:
  workflow_call:

env:
  GH_TOKEN: ${{ github.token }}

jobs:
  build-windows:
    name: Build Windows
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js 22
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: "npm"
      - name: Install npm dependencies
        run: npm ci
      - name: Build the production app
        shell: bash
        run: npm run build
      - name: Build the Electron app
        shell: bash
        run: npm run electron-win
      - name: Zip
        shell: bash
        run: cd .build; for i in bitburner-*; do 7z a "$i.zip" "$i"; done; cd ../;
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts-win
          include-hidden-files: true
          path: .build/*.zip
          if-no-files-found: error

  build-linux:
    name: Build Linux
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js 22
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: "npm"
      - name: Install npm dependencies
        run: npm ci
      - name: Build the production app
        run: npm run build
      - name: Build the Electron app
        run: npm run electron-linux
      - name: Zip
        run: cd .build; for i in bitburner-*; do zip -r "$i.zip" "$i"; done; cd ../;
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts-linux
          include-hidden-files: true
          path: .build/*.zip
          if-no-files-found: error

  build-mac:
    name: Build macOS
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js 22
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: "npm"
      - name: Install npm dependencies
        run: npm ci
      - name: Build the production app
        run: npm run build
      - name: Build the Electron app
        run: npm run electron-mac
      - name: Zip
        run: cd .build; for i in bitburner-*; do zip -r "$i.zip" "$i"; done; cd ../;
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts-mac
          include-hidden-files: true
          path: .build/*.zip
          if-no-files-found: error
