name: Create Release

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:

jobs:
  create-release:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        GO_VERSION:
          - 1.25.5

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: ${{ matrix.GO_VERSION }}

      - name: APT Install
        id: aptInstall
        run: |
          sudo dpkg --add-architecture arm64

          sudo rm -f /etc/apt/sources.list.d/ubuntu.sources

          # Create proper deb822 format sources for both amd64 and arm64
          cat <<EOF | sudo tee /etc/apt/sources.list.d/amd64.sources
          Types: deb
          URIs: http://azure.archive.ubuntu.com/ubuntu/
          Suites: noble noble-updates noble-backports
          Components: main restricted universe multiverse
          Architectures: amd64

          Types: deb
          URIs: http://security.ubuntu.com/ubuntu/
          Suites: noble-security
          Components: main restricted universe multiverse
          Architectures: amd64
          EOF

          cat <<EOF | sudo tee /etc/apt/sources.list.d/arm64.sources
          Types: deb
          URIs: http://ports.ubuntu.com/ubuntu-ports/
          Suites: noble noble-updates noble-backports noble-security
          Components: main restricted universe multiverse
          Architectures: arm64
          EOF

          sudo apt-get update
          sudo apt-get -y install build-essential debhelper fakeroot crossbuild-essential-arm64

      - name: Build Debian packages
        id: make_debian
        run: |
          make debian
          make debian-arm64

      - name: Create changelog text
        id: changelog
        uses: loopwerk/tag-changelog@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Create release
        uses: ncipollo/release-action@v1
        with:
          artifacts: "release/*"
          body: ${{ steps.changelog.outputs.changes }}
          draft: true
          token: ${{ secrets.GITHUB_TOKEN }}
