name: Build Jrebel Server

on:
  push:
    branches:
      - master
    tags:
      - '*'

jobs:
  build-job:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: 1.16
    - name: Config Linux amd64
      run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64
    - name: Build Linux amd64
      run: go build -o build-bin/jrebel-license-active-server-linux_amd64 ./
      
    - name: Config MacOS amd64
      run: CGO_ENABLED=0 GOOS=darwin GOARCH=amd64
    - name: Build MacOS amd64
      run: go build -o build-bin/jrebel-license-active-server-darwin_amd64 ./
          
    - name: Config Windows amd64
      run: CGO_ENABLED=0 GOOS=windows GOARCH=amd64
    - name: Build Windows amd64
      run: go build -o build-bin/jrebel-license-active-server-windows_amd64.exe ./  
      
    - name: Upload Bin
      uses: actions/upload-artifact@v2
      if: startsWith(github.ref, 'refs/tags/')
      with:
        name: exec file
        path: |
          build-bin/jrebel-license-active-server-linux_amd64
          build-bin/jrebel-license-active-server-darwin_amd64
          build-bin/jrebel-license-active-server-windows_amd64.exe
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}            
    - name: Release
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: |
          build-bin/jrebel-license-active-server-linux_amd64
          build-bin/jrebel-license-active-server-darwin_amd64
          build-bin/jrebel-license-active-server-windows_amd64.exe
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}