Skip to content

agronholm/release-notes

Repository files navigation

Build Status

yaml

This is a GitHub action that extracts release notes from a changelog file, converts them to the Markdown format and outputs the path to the resulting document.

Here's what it does:

  1. Reads the input file line by line until it finds a line that matches the version pattern regex, and the matched version is the one it's looking for
  2. Reads lines to memory until it encounters another version or the end of the file
  3. Joins the lines together as a snippet and converts it to the Markdown format
  4. Exports the Markdown document
  5. Sets the changelog output to the contents of the generated Markdown document

Configuration options:

  • path (required): the path to the changelog to parse
  • version_pattern: the regular expression to use for finding lines that contain version numbers. The first group within the expression is used to capture the version itself. The default value is ^\*\*([0-9][^*]*)\*\* which would match a line like **1.2.3** or **4.0.1a7** at the beginning of the line.
  • header: Text to prepend to the beginning of the generated changelog (in the same format as the changelog itself)
  • footer: Text to append to the end of the generated changelog (in the same format as the changelog itself)

The following example is triggered by pushing a version tag (X.Y.Z). It assumes a changelog file names CHANGES.rst in the project root. Sample configuration (.github/workflows/release.yml):

name: Create a release

on:
  push:
    tags:
      - "[0-9]+.[0-9]+.[0-9]+"
      - "[0-9]+.[0-9]+.[0-9]+.post[0-9]+"
      - "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+"
      - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v3
    - id: changelog
      uses: agronholm/release-notes@v1
      with:
        path: CHANGES.rst
    - uses: ncipollo/release-action@v1
      with:
        body: ${{ steps.changelog.outputs.changelog }}