name: Build Release
on:
  push:
    tags:
      - v*
jobs:
  create-release:
    runs-on: 'ubuntu-latest'
    outputs:
      upload_url: ${{ steps.create-release.outputs.upload_url }}
    steps:
    - name: Create Release
      id: create-release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: Release ${{ github.ref }}
        draft: false
        prerelease: true
  build:
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.experimental }}
    needs: create-release
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        platform:
          - 'linux-x64'
          - 'linuxmusl-x64'
          - 'linux-armv6'
          - 'linux-armv7'
          - 'linux-arm64v8'
          - 'win32-ia32'
          - 'win32-x64'
          - 'win32-arm64v8'
        experimental: [false]
        include:
          - os: macos-10.15
            platform: 'darwin-x64'
            experimental: true
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Install dependencies (macOS)
      run: |
        pip3 install meson==0.55.3 ninja
        brew install advancecomp automake brotli nasm pkg-config
      if: matrix.platform == 'darwin-x64'
    - name: Build ${{ matrix.platform }}
      id: build-release
      run: |
        ./build.sh $(cat LIBVIPS_VERSION) ${{ matrix.platform }}
        echo "::set-output name=asset_file_name_gz::libvips-$(cat LIBVIPS_VERSION)-${{ matrix.platform }}.tar.gz"
        echo "::set-output name=asset_file_name_br::libvips-$(cat LIBVIPS_VERSION)-${{ matrix.platform }}.tar.br"
    - name: Upload Release Asset (.tar.gz)
      id: upload-release-asset-gz
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ needs.create-release.outputs.upload_url }}
        asset_path: ${{ steps.build-release.outputs.asset_file_name_gz }}
        asset_name: ${{ steps.build-release.outputs.asset_file_name_gz }}
        asset_content_type: application/gzip
    - name: Upload Release Asset (.tar.br)
      id: upload-release-asset-br
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ needs.create-release.outputs.upload_url }}
        asset_path: ${{ steps.build-release.outputs.asset_file_name_br }}
        asset_name: ${{ steps.build-release.outputs.asset_file_name_br }}
        asset_content_type: application/x-brotli
