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

permissions:
  contents: read

name: Release

jobs:
  build:
    name: Build Release Artifacts
    if: github.repository == 'cilium/cilium-cli'
    runs-on: ubuntu-24.04
    steps:
      - name: Cleanup Disk space in runner
        uses: cilium/cilium/.github/actions/disk-cleanup@95e477fdcfd35d438b135f4d981ee20ce3016ac3 # v1.19.4

      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Set up Go
        uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
        with:
          # renovate: datasource=golang-version depName=go
          go-version: 1.26.3

      - name: Generate the artifacts
        run: make release

      - name: Upload artifacts
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: release-artifacts
          path: release/*
          retention-days: 1

  release:
    name: Create Release
    if: github.repository == 'cilium/cilium-cli' && github.event_name == 'push'
    needs: build
    runs-on: ubuntu-24.04
    permissions:
      contents: write
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: release-artifacts
          path: release

      - name: Create Release
        uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          name: Release ${{ github.ref_name }}
          draft: true
          prerelease: false
          generate_release_notes: true
          files: 'release/*'
