# Origin config by @Kilerd

name: Build Canary Version

on:
  push:
    branches: [ main ]

jobs:
  release:
    name: Release on ${{ matrix.platform }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        platform: [macos-x86_64, linux_glibc-x86_64, windows-i686, windows-x86_64]
        include:
        
          - platform: macos-x86_64
            target: x86_64-apple-darwin
            os: macos-latest
            bin: lolicon

          - platform: linux_glibc-x86_64
            target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            bin: lolicon
            
          - platform: windows-i686
            target: i686-pc-windows-msvc
            os: windows-latest
            bin: lolicon.exe
            
          - platform: windows-x86_64
            target: x86_64-pc-windows-msvc
            os: windows-latest
            bin: lolicon.exe
            
    steps:
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          target: ${{ matrix.target }}
          toolchain: stable
          override: true

      - name: Checkout code
        uses: actions/checkout@v1

      - name: Run code build
        uses: actions-rs/cargo@v1
        with:
          toolchain: stable
          command: build
          args: --release --target ${{ matrix.target }}

      - name: Prepare assets
        shell: bash
        run: |
          mv target/${{ matrix.target }}/release/${{ matrix.bin }} .
          if [[ ${{ matrix.target }} != x86_64-apple-darwin ]]
          then strip ${{ matrix.bin }}
          fi
          
          tar -cvf ${{ matrix.target }}.tar LICENSE.txt ${{ matrix.bin }}
          
      - name: Declare some variables # https://stackoverflow.com/a/61699863
        id: vars
        shell: bash
        run: |
          echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

      - name: Pre-Release
        uses: softprops/action-gh-release@v1
        with:
          files: ${{ matrix.target }}.tar
          tag_name: 0.1.0-${{ steps.vars.outputs.sha_short }}
          prerelease: true
