name: Manual Release Update/Rebuild

permissions:
  actions: read
  contents: write
  packages: write

on:
  workflow_dispatch:
    inputs:
      tag:
        description: 'Tag to rebuild'
        required: true

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: test
        run: |
          echo "tag is ${{ github.event.inputs.tag }}"

      - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # pin@v3
        with:
          ref: ${{ github.event.inputs.tag }}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # pin@v2

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # pin@v2

      - name: Build
        id: build
        run: |
          make info
          make release
          VERSION=$(make echo-version)
          PACKAGE_VERSION=$(make echo-package-version)
          echo "Version $VERSION, Package version $PACKAGE_VERSION"

      - name: Upload release artifacts
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          tag_name="${{ github.event.inputs.tag }}"
          echo "tag_name=$tag_name"
          gh release upload "${tag_name}" release/*.{tgz,zip,rpm,deb,gz}
