---
name: CI-Copr
permissions: {}

on:
  release:
    types:
      - prereleased
      - released
  workflow_call:
    secrets:
      COPR_BETA_WEBHOOK_TOKEN:
        required: false
      COPR_STABLE_WEBHOOK_TOKEN:
        required: false
      COPR_CLI_CONFIG:
        required: false
      GH_BOT_TOKEN:
        required: false
      VIRUSTOTAL_API_KEY:
        required: false

concurrency:
  group: "_${{ github.workflow }}-${{ github.ref }}"
  cancel-in-progress: true

jobs:
  call-copr-ci:
    permissions:
      contents: read
    uses: LizardByte/copr-ci/.github/workflows/copr-ci.yml@master
    with:
      copr_pr_webhook_token: "05fc9b07-a19b-4f83-89b2-ae1e7e0b5282"
      github_org_owner: LizardByte
      copr_ownername: lizardbyte
      auto_update_package: true
      job_timeout: 90
    secrets:
      COPR_BETA_WEBHOOK_TOKEN: ${{ secrets.COPR_BETA_WEBHOOK_TOKEN }}
      COPR_STABLE_WEBHOOK_TOKEN: ${{ secrets.COPR_STABLE_WEBHOOK_TOKEN }}
      COPR_CLI_CONFIG: ${{ secrets.COPR_CLI_CONFIG }}

  release:
    name: Release
    if:
      github.event_name == 'release' &&
      startsWith(github.repository, 'LizardByte/') &&
      github.event.release.prerelease == true
    needs:
      - call-copr-ci
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - name: Download build artifacts
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c  # v8.0.1
        with:
          path: artifacts
          pattern: build-*
          merge-multiple: true

      - name: Debug artifacts
        run: ls -l artifacts

      - name: Update GitHub Release
        uses: LizardByte/actions/actions/release_create@4125866b7b655a6fe038b0e22a43a4c5d259af79  # v2026.417.35446
        with:
          allowUpdates: true
          body: ${{ github.event.release.body }}
          deleteOtherPreReleases: false
          generateReleaseNotes: false
          name: ${{ github.event.release.name }}
          prerelease: true
          tag: ${{ github.event.release.tag_name }}
          token: ${{ secrets.GITHUB_TOKEN }}  # use built-in token to avoid repeating workflow triggers
          virustotal_api_key: ${{ secrets.VIRUSTOTAL_API_KEY }}
