name: Test CI

on:
  workflow_dispatch:
    inputs:
      os:
        description: "Runs on OS"
        required: true
        default: windows-latest
        type: choice
        options:
          - windows-latest
          - ubuntu-latest
          - macos-latest
          - ubuntu-18.04
          - ubuntu-20.04
          - ubuntu-22.04
          - macos-10.15
          - macos-11
          - macos-12
          - windows-2019
          - windows-2022

env:
  CARGO_INCREMENTAL: 0
  RUST_BACKTRACE: short

jobs:
  release:
    runs-on: ${{ github.event.inputs.os }}
    if: startsWith(github.repository, 'wonfen')
    steps:
      - name: System Version
        run: |
          echo ${{ github.event.inputs.os }}

      - name: Checkout repository
        uses: actions/checkout@v4

      - name: install Rust stable
        uses: dtolnay/rust-toolchain@stable

      - name: Rust Cache
        uses: Swatinem/rust-cache@v2
        with:
          workspaces: src-tauri

      - name: Install Node
        uses: actions/setup-node@v4
        with:
          node-version: "16"
          cache: "yarn"

      - name: Install Dependencies (ubuntu only)
        if: startsWith(github.event.inputs.os, 'ubuntu-')
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf

      - name: Yarn install and check
        run: |
          yarn install --network-timeout 1000000 --frozen-lockfile
          yarn run check

      - name: Tauri build
        uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
          TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
        with:
          tagName: alpha
          releaseName: "Clash Verge Alpha"
          releaseBody: "Alpha Version (include debug)"
          releaseDraft: false
          includeUpdaterJson: false
