name: Release

on:
  release:
    types: [published]

jobs:
  release-linux:
    name: Release for Linux

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: yarn
      - name: Build
        run: |
          make install
          make clean
          make build
      - name: Package
        env:
          VERSION: ${{ github.event.release.name }}
        run: |
          make -e linux
      - uses: snapcore/action-publish@v1
        with:
          store_login: ${{ secrets.STORE_LOGIN }}
          snap: "build/Whalebird-${{ github.event.release.name }}-linux-amd64.snap"
          release: beta
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.tar.bz2"
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.AppImage"
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.deb"
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.rpm"
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.shasum"

  release-windows:
    name: Release for Windows

    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: yarn
      - name: Build
        run: |
          make install
          make clean
          make build
      - name: Package
        env:
          VERSION: ${{ github.event.release.name }}
        run: |
          make -e win32
          make -e win64
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.exe"
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.shasum"

  release-darwin:
    name: Release for MacOS

    runs-on: macos-11

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: yarn
      - name: Apple Codesigning
        uses: apple-actions/import-codesign-certs@v1
        with:
          p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
          p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
      - name: Build
        run: |
          make install
          make clean
          make build
      - name: Package
        env:
          VERSION: ${{ github.event.release.name }}
          APPLE_ID: ${{ secrets.APPLE_ID }}
          APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
          ASC_PROVIDER: ${{ secrets.ASC_PROVIDER }}
          TEAM_ID: ${{ secrets.ASC_PROVIDER }}
        run: |
          make -e mac
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.dmg"
      - uses: shogo82148/actions-upload-release-asset@v1
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: "build/Whalebird-*.shasum"
