name: Publish release artifacts

on:
  release:
    types: [created]

jobs:
  release:
    name: Publish binaries
    runs-on: ubuntu-latest
    steps:
    - name: Setup Go
      uses: actions/setup-go@v2
      with:
        go-version: '1.17'
    - name: Checkout code
      uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Build Project binaries
      env:
        CGO_ENABLED: 0
      run: |
        make xc
    - name: Upload binaries to release
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: dist/aws*
        tag: ${{ github.ref }}
        overwrite: true
        file_glob: true

  docker_build:
    runs-on: ubuntu-20.04
    name: Docker Build

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Generate image tags
      shell: bash
      run: echo "##[set-output name=tags;]quay.io/rebuy/aws-nuke:${GITHUB_REF#refs/tags/},docker.io/rebuy/aws-nuke:${GITHUB_REF#refs/tags/}"
      id: generate_tags

    - name: Set up QEMU
      id: qemu
      uses: docker/setup-qemu-action@v1
      with:
        platforms: arm64

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
      with:
        install: true

    - name: Login to Docker Hub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}

    - name: Login to Quay.io
      uses: docker/login-action@v1
      with:
        registry: quay.io
        username: ${{ secrets.QUAY_USERNAME }}
        password: ${{ secrets.QUAY_PASSWORD }}

    - name: Build and push
      uses: docker/build-push-action@v2
      with:
        context: .
        push: true
        tags: ${{ steps.generate_tags.outputs.tags }}
        platforms: linux/amd64,linux/arm64
