Repository navigation
101 lines (90 loc) · 3.69 KB
/
Copy pathchangelog.yml
File metadata and controls
101 lines (90 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: changelog
on:
push:
tags:
- "v*"
# Serialize with the `release` workflow; both fire on the same tag push
# and contend for the working tree.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
jobs:
regenerate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# The tag push triggered this run; check out the *tag commit*
# so git-cliff can see the release's commit history.
ref: ${{ github.ref }}
# Full history + tags are required: without them git-cliff sees
# only the tag's top commit and emits a near-empty section.
fetch-depth: 0
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff@2
- name: Inspect current CHANGELOG.md
id: head
run: |
if [ -f CHANGELOG.md ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Regenerate CHANGELOG.md
if: steps.head.outputs.exists == 'true'
run: |
set -euo pipefail
# On a `v*` tag push, regenerate the whole file from tags
# using `git-cliff --output CHANGELOG.md`. Why --output and
# not --prepend:
# --prepend inserts a new [Unreleased] section above the
# configured header_marker, but does not re-render the
# existing tag sections. After many tag pushes the
# body would drift unless someone manually renames
# [Unreleased] -> [X.Y.Z].
# --output fully rebuilds the file from tags, so the
# freshly-pushed tag's section appears with the correct
# date and its tagged commits, and a fresh empty
# [Unreleased] sits at the top for the next release
# cycle.
# This is the release-event behavior the rest of the repo
# expects (the GitHub Release body is one source of
# release highlights; CHANGELOG.md is the audit record).
cp CHANGELOG.md CHANGELOG.md.before
git-cliff --output CHANGELOG.md
if ! diff -q CHANGELOG.md.before CHANGELOG.md > /dev/null; then
rm -f CHANGELOG.md.before
echo "diff=true" >> "$GITHUB_OUTPUT"
else
mv CHANGELOG.md.before CHANGELOG.md
echo "diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Open PR
if: steps.head.outputs.exists == 'true'
uses: peter-evans/create-pull-request@v6
with:
title: "chore(changelog): regenerate CHANGELOG.md for ${{ github.ref_name }}"
commit-message: "chore(changelog): regenerate for ${{ github.ref_name }}"
branch: "changelog/${{ github.ref_name }}"
base: main
# `push-to-fork` is intentionally unset: the action treats
# any non-empty value as a fork-target repo name and runs
# its parent-fork probe, which 404s on this workflow because
# the upstream IS espetro/dinov2.cpp and there is no
# separate fork to push to.
body: |
Auto-generated by `.github/workflows/changelog.yml` after
publishing the **${{ github.ref_name }}** tag.
No edits intended; review by running
git-cliff --output CHANGELOG.md
git diff CHANGELOG.md
and confirming only the `[Unreleased] -> [${{ github.ref_name }}]`
section + correct `YYYY-MM-DD` date changed.
add-paths: CHANGELOG.md
token: ${{ secrets.GITHUB_TOKEN }}