name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
      -
        name: Unshallow
        run: git fetch --prune --unshallow
      -
        name: Set up Go
        uses: actions/setup-go@v1
        with:
          go-version: 1.14
      - 
        name: Get tag
        uses: olegtarasov/get-tag@v2
        id: tag
      -
        name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v1
        with:
          version: latest
          args: release --skip-publish
      -
        name: Generate Plugin manifest
        run: ./hack/release/generate-plugin-manifest.sh ${{steps.tag.outputs.tag}}
      - 
        name: OLM RedHat bundle
        run: ./hack/generate-olm-bundle.sh ${{steps.tag.outputs.tag}}
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          body_path: dist/CHANGELOG.md
          files: |
            dist/datadog-plugin.yaml
            dist/*.zip
        env:
          COMMIT_TAG: ${{steps.tag.outputs.tag}}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
