name: Release Announce

on:
  workflow_run:
    workflows: [Release]
    types: [completed]

permissions:
  contents: read

concurrency:
  group: ecc-discord-announcement-delivery
  cancel-in-progress: false

jobs:
  announce:
    if: github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      discussions: write
    steps:
      - name: Checkout trusted default branch
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          ref: ${{ github.event.repository.default_branch }}
          persist-credentials: false
      - name: Create announcement and send it to Discord
        run: node scripts/discord/release-announce.mjs
        env:
          ANNOUNCEMENT_KIND: release
          DISCORD_ANNOUNCE_WEBHOOK_URL: ${{ secrets.DISCORD_ANNOUNCE_WEBHOOK_URL }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_REPOSITORY: ${{ github.repository }}
          RELEASE_TAG: ${{ github.event.workflow_run.head_branch }}
