name: Release

# Mirrors targets::csharp's/targets::python's/targets::rust's release.yml:
# this project is a generated application tied to one specific API, not a
# reusable library, so "release" means attaching a compiled binary to a
# GitHub Release on a version tag rather than publishing to a package
# registry.

on:
  push:
    tags:
      - "v*"

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-go@v6.5.0
        with:
          go-version: "1.26"
      - run: go build -o {{ project_name }} ./cmd/{{ project_name }}
      - run: zip {{ project_name }}.zip {{ project_name }}
      - uses: softprops/action-gh-release@v3.0.1
        with:
          files: {{ project_name }}.zip
      # Publishes the Dockerfile's image to GHCR, versioned by the release
      # tag — a real, pullable artifact of the release, not just the CI
      # build-validation docker-build.yml does on every push/PR. Uses the
      # built-in GITHUB_TOKEN, so no extra secret is needed.
      - uses: docker/setup-buildx-action@v4.2.0
      - uses: docker/login-action@v4.4.0
        with:
          registry: ghcr.io
          username: {% raw %}${{ github.actor }}{% endraw %}
          password: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
      - name: Compute image name
        id: image
        # GHCR image names must be lowercase, but github.repository isn't
        # guaranteed to be (e.g. a mixed-case GitHub username/org).
        run: echo "name=ghcr.io/$(echo '{% raw %}${{ github.repository }}{% endraw %}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
      - uses: docker/build-push-action@v7.3.0
        with:
          context: .
          push: true
          tags: |
            {% raw %}${{ steps.image.outputs.name }}:${{ github.ref_name }}{% endraw %}
            {% raw %}${{ steps.image.outputs.name }}:latest{% endraw %}
