name: Release Operator
on:
  workflow_dispatch:

jobs:
  build-and-release:
    name: Release Operator, build and push newest image
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          fetch-depth: 0

      - name: Set up env vars
        run: |
          echo "GO111MODULE=on" >> $GITHUB_ENV
          echo "GO_VERSION=v$(sed -n 's/GO_VERSION=//p' config.base.env | tr -d '\n' | tr -d '"')" >> $GITHUB_ENV
          echo "GOPATH=/home/runner/go" >> $GITHUB_ENV

      - name: Prepare go environment
        uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5
        with:
          go-version: ${{ env.GO_VERSION }}

      - name: Ensure Golang runtime dependencies
        run: make go-dependencies

      - name: Configure Git
        run: |
          git config user.name "$GITHUB_ACTOR"
          git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

      - name: Tag the release
        run: make tag

      - name: Set version for release tag name
        run: |
          echo "VERSION=$(cat VERSION.txt)" >> $GITHUB_ENV

      - name: Release
        uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # v2
        with:
          tag_name: ${{ env.VERSION }}

      - name: Login to Quay.io
        uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
        with:
          registry: quay.io
          username: ${{ secrets.QUAYIO_USERNAME }}
          password: ${{ secrets.QUAYIO_TOKEN }}

      - name: Build and push the image to Quay.io
        run: |
          git reset --hard
          make container-runtime-release
