---
myst:
  html_meta:
    "description": "Check on every pull request that each changed package has a news fragment, with repoplone changelog check in GitHub Actions."
    "property=og:description": "Check on every pull request that each changed package has a news fragment, with repoplone changelog check in GitHub Actions."
    "property=og:title": "Check news fragments in CI"
    "keywords": "Plone, repoplone, towncrier, news fragment, GitHub Actions, CI, pull request"
---

(how-to-check-news-in-ci)=

# 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.

(how-to-check-news-in-ci-workflow)=

## Add the workflow

Create `.github/workflows/changelog.yml`.

```yaml
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.

(how-to-check-news-in-ci-outputs)=

## Use the outputs in later steps

The check step sets three outputs.

`missing`
: A JSON list of the areas that miss a fragment, such as `["fake.distribution"]`.

`areas`
: A JSON list with one object per area: `name`, `path`, `news_folder`, `requires`, `has`, and `missing`.

`summary`
: A 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.

```yaml
- 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"
```

(how-to-check-news-in-ci-protect)=

## 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.

```{seealso}
- {doc}`add-news-fragments`, for contributors who need to add one.
- {doc}`/reference/github-outputs`, for every output.
- {doc}`/explanation/news-fragments`, for how areas are matched.
```
