Check news fragments in CI#
This guide shows you how to fail a pull request when a changed package has no news fragment. The check also writes a table of every area to the workflow run’s summary.
Add the workflow#
Create .github/workflows/changelog.yml.
name: Changelog check
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
jobs:
changelog:
# Dependabot pull requests never carry a news fragment.
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
# The check needs the history of both branches to find where the
# pull request started.
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Check for news fragments
id: news
env:
BASE_BRANCH: ${{ github.base_ref }}
run: |
git fetch --no-tags origin "${BASE_BRANCH}"
uvx repoplone@2.0.0a2 changelog check --compare-with "origin/${BASE_BRANCH}" --github >> "$GITHUB_OUTPUT"
- name: Report
if: ${{ always() && steps.news.outputs.summary }}
env:
SUMMARY: ${{ steps.news.outputs.summary }}
run: echo "$SUMMARY" >> "$GITHUB_STEP_SUMMARY"
--github writes the result as step outputs instead of a table.
The command exits with 1 when an area misses a fragment, which fails the check step.
The Report step runs anyway, because of always(), and copies the summary table to the run’s page.
Use the outputs in later steps#
The check step sets three outputs.
missingA JSON list of the areas that miss a fragment, such as
["fake.distribution"].areasA JSON list with one object per area:
name,path,news_folder,requires,has, andmissing.summaryA Markdown table of the areas, for the step summary or a pull request comment.
A later step can test the list of missing areas without parsing the table.
- name: Name the missing areas
if: ${{ always() && steps.news.outputs.missing != '[]' }}
env:
MISSING: ${{ steps.news.outputs.missing }}
run: |
echo "Add a news fragment to: $MISSING"
Require the check#
Make the check required in the repository’s branch protection rules or rulesets on GitHub. A pull request then cannot merge while a changed package misses its fragment.
See also
Add news fragments, for contributors who need to add one.
GitHub Actions outputs, for every output.
News fragments and changelogs, for how areas are matched.