name: Changelog
on:
  push:
    branches:
      - master
  pull_request:
    # Important that we run on `labeled` and `unlabeled` to pick up `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@v2
        # Include all history and tags
        with:
          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 `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@v2
        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@v2
        with:
          name: changelog
          path: |
            CHANGELOG.rst
            CHANGELOG.html
