name: Build app
on:
  workflow_dispatch:
  release:
    types: [ created ]

jobs:
  build:
    #    if: ${{ startsWith(github.ref, 'refs/tags/v') }}
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2

      - name: Install node
        uses: actions/setup-node@v2
        with:
          node-version: 16

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      #      - uses: actions/cache@v2
      #        id: cache
      #        with:
      #          path: node_modules
      #          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
      #          restore-keys: |
      #            ${{ runner.os }}-node-

      - name: Install Dependencies
        #        if: steps.cache.outputs.cache-hit != 'true'
        run: npm i

      - name: Build app
        run: |
          node env_writer.js
          npx ng build --configuration=production,tauri
        env:
          TW_CLIENT: ${{ secrets.TW_CLIENT }}
          SERVER_HOST: ${{ secrets.SERVER_HOST }}
          BUILD_ENV: tauri
      #
      - uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          files: D:\a\simple-obs-stt\simple-obs-stt\src-tauri\target\release\bundle/msi/**.msi
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
