Automatically update CHANGELOG file when a new release is published
Tags: actionshackathon21, github, opensource
Published: 2021-11-15 20:16:46

---
title: Automatically update CHANGELOG file when a new release is published
published: true
description: My submission to the GitHub Actions x DEV Hackathon 2021!
tags: actionshackathon21, github, opensource
---

### My Workflow

My submission to the Hackathon: an Action that automatically keeps the `CHANGELOG.md` up-to-date with the release notes of a project.

When a new release is published, the Action takes the name and body text of the release and adds them at the right place within the `CHANGELOG.md` file.

If the changelog follows the ["Keep a Changelog"](https://keepachangelog.com/en/1.0.0/)-format and has an "Unreleased" heading with a link to GitHub's compare view, the Action will to a bit of magic. At first, it will update the compare URL of the "Unreleased" heading to point to the new release and `HEAD`. 
It will then also use that URL to build another compare URL, to allow users to compare the previous release to the latest release (eg. compare `v1.0.0` to `v1.1.0`).

With the recent overhaul of the "Releases" feature on GitHub and the adding of the "Auto Generate Release Notes"-button, I hope this Action will help increase the adoption of changelogs and will reduce the burden to keep those changelogs up-to-date.

### Submission Category: 

Maintainer Must-Haves


### Yaml File or Link to Code

Workflow to use this Action.

```yaml
# .github/workflows/update-changelog.yaml
name: "Update Changelog"

on:
  release:
    types: [released]

jobs:
  update:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: main

      - name: Update Changelog
        uses: stefanzweifel/changelog-updater-action@v1
        with:
          latest-version: ${{ github.event.release.name }}
          release-notes: ${{ github.event.release.body }}

      - name: Commit updated CHANGELOG
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          branch: main
          commit_message: Update CHANGELOG
          file_pattern: CHANGELOG.md
```

{% github https://github.com/stefanzweifel/changelog-updater-action %}


### Additional Resources / Info

Open Source projects using this Action. 
Mostly my own projects, as I just released the Action. However, [Spatie](https://spatie.be/open-source), a huge contributor to open source PHP packages recently added the workflow to their PHP package template; which makes me super proud ♥️

- https://github.com/spatie/package-skeleton-laravel (A very popular PHP package template)
- https://github.com/stefanzweifel/git-auto-commit-action
- https://github.com/stefanzweifel/php-changelog-updater
- https://github.com/stefanzweifel/commonmark-mark-extension

---

I've written a couple of posts on my blog / dev.to profile on the motivation to create this Action:

- [Introducing the changelog-updater Action ](https://dev.to/_stefanzweifel/introducing-the-changelog-updater-action-3c8i)
- [Dear Maintainer, Please Keep a Changelog ](https://dev.to/_stefanzweifel/dear-maintainer-please-keep-a-changelog-5gnp)
- [How the "changelog-updater" Action works ](https://dev.to/_stefanzweifel/how-the-changelog-updater-action-works-4021)