name: Build artifacts to link to release

on:
  push:
    tags:
      - '*'

jobs:
  build-linux:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '12'
      - name: Install npm modules
        run: npm ci
      - name: Make envfile
        run: echo ${{ secrets.SENTRY_DSN }} | base64 -d > .env
      - name: Build and publish artifact
        run: npm_config_yes=true npx electron-builder -p always
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Get version
        id: package-version
        uses: martinbeentjes/npm-get-version-action@master
      - name: Create Sentry release
        uses: getsentry/action-release@v1
        env:
          SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
          SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
          SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
        with:
          environment: production
          version: ${{ steps.package-version.outputs.current-version }}
  build-windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '12'
      - name: Install npm modules
        run: npm ci
      - name: Make envfile
        run: |
          echo ${{ secrets.SENTRY_DSN }} > env.b64
          certutil -decode env.b64 .env
          del env.b64
      - name: Build and publish artifact
        run: env npm_config_yes=true npx electron-builder -p always
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and publish portable artifact
        run: env npm_config_yes=true npx electron-builder --win portable -p always
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  build-mac:
    runs-on: macos-11
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '12'
      - name: Install npm modules
        run: npm ci
      - name: Make envfile
        run: echo ${{ secrets.SENTRY_DSN }} | base64 -d > .env
      - name: Build and publish artifact
        run: npm_config_yes=true npx electron-builder -p always
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
