---
name: rssguard

on:
  push:
    branches: ["master", "version-4"]
    tags: ["*"]

jobs:
  build-rssguard:
    name: "${{ matrix.os }}; webengine = ${{ matrix.use_webengine }}"
    runs-on: "${{ matrix.os }}"
    strategy:
      matrix:
        os: [windows-2019, ubuntu-18.04, macos-10.15]
        use_webengine: ["ON", "OFF"]
        include:
          - os: windows-2019
            script_name: .\resources\scripts\github-actions\build-windows.ps1
          - os: ubuntu-18.04
            script_name: ./resources/scripts/github-actions/build-linux-mac.sh
          - os: macos-10.15
            script_name: ./resources/scripts/github-actions/build-linux-mac.sh
    steps:         
      - name: Checkout source code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          submodules: true
         
      - name: Delete old development binaries
        uses: mknejp/delete-release-assets@v1
        if: strategy.job-index == 0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          tag: devbuild
          fail-if-no-assets: false
          fail-if-no-release: false
          assets: | 
            *.AppImage
            *.dmg
            *.exe
            *.7z
            
      - name: Update "devbuild" tag
        uses: richardsimko/update-tag@v1.0.5
        if: strategy.job-index == 0
        with:
          tag_name: devbuild
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         
      - name: Prepare environment and compile application
        run: ${{ matrix.script_name }} "${{ matrix.os }}" "${{ matrix.use_webengine }}"
        env:
          GMAIL_CLIENT_ID: ${{ secrets.GMAIL_CLIENT_ID }}
          GMAIL_CLIENT_SECRET: ${{ secrets.GMAIL_CLIENT_SECRET }}
          INOREADER_CLIENT_ID: ${{ secrets.INOREADER_CLIENT_ID }}
          INOREADER_CLIENT_SECRET: ${{ secrets.INOREADER_CLIENT_SECRET }}
          FEEDLY_CLIENT_ID: ${{ secrets.FEEDLY_CLIENT_ID }}
          FEEDLY_CLIENT_SECRET: ${{ secrets.FEEDLY_CLIENT_SECRET }}

      - name: Release development binaries
        uses: softprops/action-gh-release@v1
        with:
          prerelease: true
          name: "Development builds"
          tag_name: "devbuild"
          files: |
            .\rssguard-build\rssguard-*win64.exe
            .\rssguard-build\rssguard-*win64.7z
            ./rssguard-build/rssguard-*mac64.dmg
            ./rssguard-build/rssguard-*linux64.AppImage
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          
      - name: Release stable binaries
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          prerelease: false
          files: |
            .\rssguard-build\rssguard-*win64.exe
            .\rssguard-build\rssguard-*win64.7z
            ./rssguard-build/rssguard-*mac64.dmg
            ./rssguard-build/rssguard-*linux64.AppImage
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
