name: container project - release build

permissions:
  contents: read

on:
  push:
    tags:
      - "[0-9]+\\.[0-9]+\\.[0-9]+"

jobs:
  build:
    name: Invoke build and release
    uses: ./.github/workflows/common.yml
    with:
      release: true
    secrets: inherit
    permissions:
      contents: read
      packages: read
      pages: write

  release:
    if: startsWith(github.ref, 'refs/tags/')
    name: Publish release
    timeout-minutes: 30
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: read
      pages: write
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          path: outputs

      - name: Verify artifacts exist
        run: |
          echo "Checking for expected artifacts..."
          ls -la outputs/container-package/
          test -e outputs/container-package/*.zip || (echo "Missing .zip file!" && exit 1)
          test -e outputs/container-package/*.pkg || (echo "Missing .pkg file!" && exit 1)

      - name: Create release
        uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3
        with:
          token: ${{ github.token }}
          name: ${{ github.ref_name }}-prerelease
          draft: true
          make_latest: false
          prerelease: true
          fail_on_unmatched_files: true
          files: |
            outputs/container-package/*.zip
            outputs/container-package/*.pkg
