name: Build Electron App

on: 
  push:
    branchs: [master]
  pull_request:
    branchs: [master]

jobs:
  build:
    runs-on: ${{matrix.os}}

    strategy:
      matrix:
        os: [macos-latest, windows-latest]
    
    steps:
      - uses: actions/check@v2

      - name: Install Node.js NPM Yarn
        uses: actions/setup-node@v1
        with:
          node-version: 12.16.3

      - name: Get npm cache directory
        id: npm-cache
        run: |
          echo "::set-output name=dir::$(npm config get cache)"
      - uses: actions/cache@v1
        with:
          path: ${{ steps.npm-cache.outputs.dir }}
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v1
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Build/release
        uses: samuelmeuli/action-electron-builder@v1
        with:
          github_token: ${{secrets.github_token}}
          release: ${{startWith(github.ref, 'refs/tags/v')}}
          use_vue_cli: true
      
      - uses: actions/uplad-artifact@v2
        with:
          name: ReleaseApp-mac
          path: dist_electron/*.dmg
          if-no-files-found: ignore
      
      - uses: actions/uplad-artifact@v2
        with:
          name: ReleaseApp-win
          path: dist_electron/*.exe
          if-no-files-found: ignore