name: Release

on:
  push:
    tags:
      - "v*"

permissions: read-all

jobs:
  release:
    runs-on: ubuntu-24.04
    steps:
      - name: Free disk space
        uses: jlumbroso/free-disk-space@main
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: "1.24"
      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USER }}
          password: ${{ secrets.DOCKER_PASS }}
      - name: Login to AWS Public ECR
        uses: docker/login-action@v3
        with:
          registry: public.ecr.aws
          username: ${{ secrets.AWS_ACCESS_KEY_ID }}
          password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      - name: Import GPG key
        id: import_gpg
        uses: crazy-max/ghaction-import-gpg@v6
        with:
          gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
          passphrase: ${{ secrets.GPG_PASSPHRASE }}
      - name: Setup Syft
        uses: anchore/sbom-action/download-syft@v0
      - name: Release Docker images and CLI tool binaries
        uses: goreleaser/goreleaser-action@v6
        with:
          version: latest
          args: release --clean --timeout 60m
        env:
          GITHUB_TOKEN: ${{ secrets.GHT_RELEASE }}
          GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
      - name: Set up Helm
        uses: azure/setup-helm@v4
      - name: Checkout Helm charts repo
        uses: actions/checkout@v4
        with:
          repository: artifacthub/helm-charts
          path: helm-charts
          token: ${{ secrets.GHT_RELEASE }}
      - name: Extract tag name
        id: extract_tag_name
        run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
      - name: Release Helm chart
        run: |
          mkdir tmp && cd tmp
          helm package -u ../charts/artifact-hub
          helm repo index --merge ../helm-charts/index.yaml --url https://artifacthub.github.io/helm-charts .
          mv * ../helm-charts
          cd ../helm-charts
          git config user.name artifacthubio
          git config user.email hub@artifacthub.io
          git add .
          git commit -m "Add Artifact Hub chart package ${{steps.extract_tag_name.outputs.tag}}"
          git push
