name: Generate Artifacts
on:
  push:
    tags: [ v* ]

jobs:
  build-artifacts:
    runs-on: ${{ matrix.platform }}

    strategy:
      fail-fast: false
      matrix:
        #        platform: [ ubuntu-latest, macos-latest, windows-latest ]
        platform: [ macos-latest ]

    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: 'aarch64-apple-darwin,x86_64-apple-darwin'
      - name: Cache Rust
        uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            ./src-tauri/target
          key: ${{ runner.os }}-cargo-${{ hashFiles('src-tauri/Cargo.lock') }}
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - name: install dependencies (ubuntu only)
        if: matrix.platform == 'ubuntu-latest'
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
      - name: Install dependencies
        run: npm ci
      - name: Run tests
        run: npm test
      # Pin dev version to get non-default targets
      # https://github.com/tauri-apps/tauri-action/issues/356
      - uses: tauri-apps/tauri-action@dev
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
          TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
          ENABLE_CODE_SIGNING: ${{ secrets.APPLE_CERTIFICATE }}
          APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
          APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
          APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
          APPLE_ID: ${{ secrets.APPLE_ID }}
          APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
        with:
          tagName: 'v__VERSION__'
          releaseName: 'Release __VERSION__'
          releaseBody: 'See the assets to download this version and install.'
          releaseDraft: false
          prerelease: false
          args: '--target universal-apple-darwin'
