name: changelog

on:
  pull_request:
    types: [labeled, unlabeled, opened, reopened, synchronize]

permissions:
  contents: read

jobs:
  check-changelog-entry:
    name: changelog entry
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          # `towncrier check` runs `git diff --name-only origin/main...`, which
          # needs a non-shallow clone.
          fetch-depth: 0

      - name: Check changelog
        if: contains(github.event.pull_request.labels.*.name, 'skip news') != true
        run: |
          if ! pipx run towncrier check --compare-with origin/${{ github.base_ref }}; then
          echo "Please see https://landlab.readthedocs.io/en/master/development/contribution/index.html?highlight=towncrier#news-entries for guidance."
            false
          fi