name: Auto Changelog (Release Drafter)

on:
  workflow_run:
    workflows: ["Docker Build, Publish & Test"]
    types: [completed]
    branches: [ main ]
  release:
    types: [published]

concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.workflow_run.head_branch || github.head_ref || github.ref_name }}
  cancel-in-progress: true

permissions:
  contents: write

jobs:
  update-draft:
    runs-on: ubuntu-latest
    if: ${{ github.event_name != 'workflow_run' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main') }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
        with:
          ref: ${{ github.event.workflow_run.head_sha || github.sha }}
      - name: Draft Release
        uses: release-drafter/release-drafter@5de93583980a40bd78603b6dfdcda5b4df377b32 # v7
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
