ajour 0.7.0

A World of Warcraft addon manager
name: "Release to draft"

on:
  workflow_dispatch:
    inputs:
      tag:
        description: 'Specify tag to create'
        required: true

jobs:
  
  build:
    name: Build
    strategy:
      matrix:
        target:
          - target: windows-wgpu
            os: windows-latest
            make: make binary
            binary_path: target/release/ajour.exe
          - target: windows-opengl
            os: windows-latest
            make: make binary OPENGL=1
            binary_path: target/release/ajour.exe

          - target: linux-wgpu
            os: ubuntu-16.04
            make: make appimage
            binary_path: ajour.AppImage
          - target: linux-opengl
            os: ubuntu-16.04
            make: make appimage OPENGL=1
            binary_path: ajour-opengl.AppImage

          - target: macos-wgpu
            os: macos-latest
            make: make dmg MACOS=1
            binary_path: target/release/osx/ajour.dmg
          - target: macos-opengl
            os: macos-latest
            make: make dmg OPENGL=1 MACOS=1
            binary_path: target/release/osx/ajour-opengl.dmg
          - target: macos-wgpu-tar
            os: macos-latest
            make: make tar MACOS=1
            binary_path: target/release/ajour.tar.gz
          - target: macos-opengl-tar
            os: macos-latest
            make: make tar OPENGL=1 MACOS=1
            binary_path: target/release/ajour.tar.gz

    runs-on: ${{ matrix.target.os }}

    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true

      - name: Do we need linuxdeploy?
        if: ${{ matrix.target.os == 'ubuntu-16.04' }} 
        run: |
          wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
          chmod +x linuxdeploy-x86_64.AppImage

      - name: Do we need GNU tar? # Fix for macos caching, https://github.com/actions/cache/issues/403
        if: ${{ matrix.target.os == 'macos-latest' }}
        run: |
          brew install gnu-tar
          echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH

      - name: Build
        run: ${{ matrix.target.make }}

      - name: Code signing
        if: ${{ matrix.target.os == 'windows-latest' }}
        env: 
          codesign_cert: ${{ secrets.CODESIGN_CERT }}
          codesign_cert_password: ${{ secrets.CODESIGN_CERT_PASSWORD }}
        run: |
          [IO.File]::WriteAllBytes("codesign_cert.pfx", [Convert]::FromBase64String($env:codesign_cert))
          & 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\signtool.exe' sign `
          /fd sha256 /tr http://timestamp.sectigo.com /td sha256 /f "codesign_cert.pfx" `
          /p $env:codesign_cert_password ${{ matrix.target.binary_path }}

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: ${{ matrix.target.target }}
          path: ${{ matrix.target.binary_path }}

  create-release:
    needs: build
    name: Create Release
    outputs:
      upload_url: ${{ steps.create-release.outputs.upload_url }}
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    steps:
      - name: Create Release
        id: create-release
        uses: actions/create-release@v1
        with:
          tag_name: ${{ github.event.inputs.tag }}
          release_name: ${{ github.event.inputs.tag }}
          draft: true
          prerelease: false

  add-assets:
    needs: create-release
    name: Add Assets

    strategy:
      matrix:
        target:
          - artifact: windows-wgpu
            artifact_name: ajour.exe
            asset_name: ajour.exe
            asset_type: application/x-dosexec
          - artifact: windows-opengl
            artifact_name: ajour.exe
            asset_name: ajour-opengl.exe
            asset_type: application/x-dosexec

          - artifact: linux-wgpu
            artifact_name: ajour.AppImage
            asset_name: ajour.AppImage
            asset_type: application/x-executable
          - artifact: linux-opengl
            artifact_name: ajour-opengl.AppImage
            asset_name: ajour-opengl.AppImage
            asset_type: application/x-executable

          - artifact: macos-wgpu
            artifact_name: ajour.dmg
            asset_name: ajour.dmg
            asset_type: application/octet-stream
          - artifact: macos-opengl
            artifact_name: ajour-opengl.dmg
            asset_name: ajour-opengl.dmg
            asset_type: application/octet-stream
          - artifact: macos-wgpu-tar
            artifact_name: ajour.tar.gz
            asset_name: ajour-macos.tar.gz
            asset_type: application/gzip
          - artifact: macos-opengl-tar
            artifact_name: ajour.tar.gz
            asset_name: ajour-opengl-macos.tar.gz
            asset_type: application/gzip

    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    steps:
      - name: Download artifact
        uses: actions/download-artifact@v2
        with:
          name: ${{ matrix.target.artifact }}
          path: ${{ matrix.target.artifact }}

      - name: Upload asset
        uses: actions/upload-release-asset@v1
        with:
          upload_url: ${{ needs.create-release.outputs.upload_url }}
          asset_path: ./${{ matrix.target.artifact }}/${{ matrix.target.artifact_name }}
          asset_name: ${{ matrix.target.asset_name }}
          asset_content_type: ${{ matrix.target.asset_type }}