# .github/workflows/build.yml — auto-build native binaries on every version bump
# Save this file at .github/workflows/build.yml in your JG Music Tools repo.
# Then every push to main triggers Windows + Mac + Linux + Android builds.

name: Build Native Binaries

on:
  push:
    branches: [main]
    tags: ['v*']
  workflow_dispatch:

jobs:
  windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '20' }
      - run: npm ci
      - run: npm run build:win
      - uses: actions/upload-artifact@v4
        with:
          name: windows-build
          path: dist/*.exe

  mac:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '20' }
      - run: npm ci
      - run: npm run build:mac
      - uses: actions/upload-artifact@v4
        with:
          name: mac-build
          path: dist/*.dmg

  linux:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '20' }
      - run: npm ci
      - run: npm run build:linux
      - uses: actions/upload-artifact@v4
        with:
          name: linux-build
          path: dist/*.AppImage

  android:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { distribution: 'temurin', java-version: '17' }
      - uses: actions/setup-node@v4
        with: { node-version: '20' }
      - uses: android-actions/setup-android@v3
      - run: npm ci
      - run: npx cap sync android
      - run: cd android && ./gradlew assembleRelease
      - name: Sign APK
        env:
          KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
          KEYSTORE_PASS: ${{ secrets.ANDROID_KEYSTORE_PASS }}
        run: |
          echo $KEYSTORE_BASE64 | base64 -d > release.keystore
          $ANDROID_HOME/build-tools/34.0.0/apksigner sign --ks release.keystore --ks-pass pass:$KEYSTORE_PASS android/app/build/outputs/apk/release/app-release-unsigned.apk
      - uses: actions/upload-artifact@v4
        with:
          name: android-build
          path: android/app/build/outputs/apk/release/*.apk
