name: Changelog
on:
  push:
    branches:
      - main
  pull_request:
    # Important that we run on `labeled` and `unlabeled` to pick up `changelog/no-changelog` being added/removed
    # DEV: [opened, reopened, synchronize] is the default
    types: [opened, reopened, synchronize, labeled, unlabeled, ready_for_review]
jobs:
  validate:
    name: Validate changelog
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        # Include all history and tags
        with:
          persist-credentials: false
          fetch-depth: 0

      # Ensure a new reno release note was added in this PR.
      # Use `reno new <slug>` to add a new note to `releasenotes/notes`,
      #   or add `changelog/no-changelog` label if no release note is needed.
      - name: Ensure release note added
        # Only run this on pull requests
        if: github.event_name == 'pull_request'
        run: scripts/check-releasenotes

      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
        name: Install Python
        with:
          python-version: '3.8'

      - name: Install Dependencies
        run: pip install reno docutils

      - name: Lint changelog notes
        run: reno lint

      - name: Generate changelog
        run: |
          reno report | tee CHANGELOG.rst
          rst2html.py CHANGELOG.rst CHANGELOG.html

      - name: Upload CHANGELOG.rst
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
        with:
          name: changelog
          path: |
            CHANGELOG.rst
            CHANGELOG.html
