name: Create Release

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
    - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
  test:
    name: Lint, Test, Build
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        go: [ '1.17', '1.18' ]
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
      -
        name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go }}
      -
        name: golangci-lint
        uses: golangci/golangci-lint-action@v2
        with:
          version: 'v1.45.2'
          args: --timeout=30m
      -
        name: Test, Build
        id: lintTestBuild
        run: V=1 make

  create_release:
    name: Create Release
    needs: test
    runs-on: ubuntu-20.04
    steps:
      -
        name: Is Pre-release
        id: is_prerelease
        run: |
          set +e
          echo ${{ github.ref }} | grep "\-rc.*"
          OUT=$?
          if [ $OUT -eq 0 ]; then IS_PRERELEASE=true; else IS_PRERELEASE=false; fi
          echo "::set-output name=IS_PRERELEASE::${IS_PRERELEASE}"
      -
        name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          draft: false
          prerelease: ${{ steps.is_prerelease.outputs.IS_PRERELEASE }}
