name: Build

on:
  push:
    branches: [ master ]
    tags:
      - v0.*
      - v1
      - v1.*
    paths-ignore:
      - 'README.md'
      - '.github/**'
      - '.gitignore'
  pull_request:
    branches: [ master ]
    paths-ignore:
      - 'README.md'
      - '.github/**'
      - '.gitignore'

jobs:

  build:
    strategy:
      matrix:
        platform: [ubuntu-latest, macos-latest, windows-latest]
    name: Build
    runs-on: ${{ matrix.platform }}
    steps:

    - name: Set up Go 1.13
      uses: actions/setup-go@v1
      with:
        go-version: 1.13
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

    - name: Get Short SHA8
      id: vars
      run: |
        echo "::set-output name=sha_short::$(git rev-parse --short=8 ${{ github.sha }})"

    - name: Get dependencies
      run: go get -v -t -d ./...
        
    - name: Build
      run: go build -v .

    - name: Upload Artifacts
      if: matrix.platform == 'macos-latest'
      uses: actions/upload-artifact@v1.0.0
      id: macos_build
      with:
        name: boom-bot-${{ matrix.platform }}-${{ steps.vars.outputs.sha_short }}
        path: boom-bot

    - name: Upload Artifacts
      if: matrix.platform == 'windows-latest'
      uses: actions/upload-artifact@v1.0.0
      id: windows_build
      with:
        SHA8: 
        name: boom-bot-${{ matrix.platform }}-${{ steps.vars.outputs.sha_short }}
        path: boom-bot.exe

    - name: Upload Artifacts
      if: matrix.platform == 'ubuntu-latest'
      id: ubuntu_build
      uses: actions/upload-artifact@v1.0.0
      with:
        name: boom-bot-${{ matrix.platform }}-${{ steps.vars.outputs.sha_short }}
        path: boom-bot

    - name: Publish Docker Image
      if: success() && matrix.platform == 'ubuntu-latest'
      id: upload_docker
      uses: elgohr/Publish-Docker-Github-Action@master
      with:
        name: haukeness/boom-bot
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
        tag_semver: true
