Skip to content

Commit

Permalink
Auto-generate changelog from Git tags
Browse files Browse the repository at this point in the history
This project uses Git tags to indicate releases, and has been providing
annotated and signed Git tags with informative tag messages. These tags
can be used to auto-generate a changelog.

This commit will add a CHANGELOG.md, a corresponding docs/changelog.md,
and a GitHub Actions job that will update the changelog on each Git tag.

Future changelog updates will be made with automated PRs due to branch
protection. GitHub Actions can't push to protected branches.

Branch protection rules currently require signed commits. By default,
bots can't sign commits. Setting up bot commit signing is involved, and
requires storing a private key on GitHub. The commit signing requirement
could be disabled, but this would create the possibility of unauthorized
changes being committed. Having bots open PRs avoids this issue, because
GitHub will sign the merge with their key. Note that, in order for the
merged commit to show up as verified, the `Co-authored-by` trailers must
be removed before squashing and merging.

A downside of updating the changelog with PRs is that changelog PRs
could go unmerged if maintainers forget to merge them. PR auto-merge
could help with this, but then other unwanted PRs could be merged also,
so auto-merge is currently disabled.

Note that PRs or commits created from a GitHub Actions workflow don't
trigger further workflows. This means the changelog PR won't trigger
the required status checks, so an admin will have to bypass these checks
in order to merge the PR.

This commit will enable the `MagicLink` Python Markdown extension
(`pymdownx.magiclink`). This extension will "magic link" (autolink)
GitHub references (add hyperlinks to the text on the page).

This extension is not officially supported by Material for MkDocs, but
it appears to work well, and it helps add links to the changelog.

https://facelessuser.github.io/pymdown-extensions/extensions/magiclink/
https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/
https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls
  • Loading branch information
br3ndonland committed Jan 5, 2023
1 parent 7fbb89f commit c7aa765
Show file tree
Hide file tree
Showing 5 changed files with 856 additions and 18 deletions.
50 changes: 48 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ on:
pull_request:
push:
branches: [develop, main]
tags:
- "[0-9]+.[0-9]+.[0-9]+*"
tags: ["[0-9]+.[0-9]+.[0-9]+*"]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -103,3 +102,50 @@ jobs:
echo "Versions do not match." && exit 1
fi
poetry publish --build -u __token__ -p ${{ secrets.PYPI_TOKEN }}
changelog:
if: github.ref_type == 'tag'
needs: [ci]
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: develop
- name: Generate changelog from Git tags
run: |
echo '# Changelog
' >CHANGELOG.md
echo '# Changelog
[View on GitHub](https://github.com/br3ndonland/fastenv/blob/develop/CHANGELOG.md)
' >docs/changelog.md
GIT_LOG_FORMAT='## %(subject) - %(taggerdate:short)
%(contents:body)
Tagger: %(taggername) %(taggeremail)
Date: %(taggerdate:iso)
```text
%(contents:signature)```
'
git tag -l --sort=-taggerdate:iso --format="$GIT_LOG_FORMAT" >>CHANGELOG.md
git tag -l --sort=-taggerdate:iso --format="$GIT_LOG_FORMAT" >>docs/changelog.md
- name: Format changelog with Prettier
run: npx -s -y prettier@'^2' --write CHANGELOG.md docs/changelog.md
- name: Create pull request with updated changelog
uses: peter-evans/create-pull-request@v4
with:
add-paths: |
CHANGELOG.md
docs/changelog.md
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
branch: create-pull-request/${{ github.ref_name }}
commit-message: Update changelog for version ${{ github.ref_name }}
title: Update changelog for version ${{ github.ref_name }}
Loading

0 comments on commit c7aa765

Please sign in to comment.