name: Publish release

on:
  release:
    types:
      - published

jobs:
  publish-release:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2.4.0
      with:
        submodules: true

    - name: Fetch git tags
      run: |
        git fetch --prune --unshallow --tags

    - uses: actions/setup-go@v2
      with:
        go-version: ^1.17

    - uses: actions/setup-node@v2.5.0
      with:
        node-version: '10'

    - name: Export BRANCH variable
      uses: ./.github/actions/setup-branch

    - name: Install tools
      run: make install-ci

    - name: Build binaries
      id: build-binaries
      run: make build-all-platforms

    - name: Package binaries
      id: package-binaries
      run: bash scripts/package-deploy.sh
      if: steps.build-binaries.outcome == 'success'

    - name: Upload binaries
      uses: svenstaro/upload-release-action@2.2.1
      with:
        file: deploy/*.tar.gz
        file_glob: true
        tag: ${{ github.ref }}
        repo_token: ${{ secrets.GITHUB_TOKEN }}
      if: steps.package-binaries.outcome == 'success'

    - uses: docker/setup-qemu-action@v1

    - name: Build and upload all docker images
      run: bash scripts/build-upload-docker-images.sh
      env:
        DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
        QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

    - name: Build, test, and publish all-in-one image
      run: bash scripts/build-all-in-one-image.sh
      env:
        DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
        QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

    - name: Build, test, and publish hotrod image
      run: bash scripts/hotrod-integration-test.sh
      env:
        DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
        QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
