name: release

on:
  push:
    tags:
      - "v*"

jobs:
  build-mac:
    runs-on: macos-latest
    steps:
      - name: Code checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.17
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2.8.0
        with:
          version: v0.184.0
          args: release -f .goreleaser/mac.yml --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}

  build-linux:
    runs-on: ubuntu-latest
    steps:
      - name: Code checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      -
        name: Docker Login
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
        run: |
          echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.17
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          version: v0.184.0
          args: release -f .goreleaser/linux.yml --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
      - name: Upload to Bintray
        if: ${{ false }}  # Disable this step until a replacement is found
        run: |
          scripts/publish-deb-to-bintray.sh
          scripts/publish-rpm-to-bintray.sh
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
          BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
          BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}

  build-windows:
    runs-on: windows-latest
    steps:
      - name: Code checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.17
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          version: v0.184.0
          args: release -f .goreleaser/windows.yml --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}

  upload-to-virustotal:
    needs: [build-windows]
    runs-on: ubuntu-latest
    steps:
      - name: Code checkout
        uses: actions/checkout@v2
      - name: Upload to VirusTotal
        run: scripts/upload-zip-to-virustotal.sh
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
          VIRUSTOTAL_API_KEY: ${{ secrets.VIRUSTOTAL_API_KEY }}
