Skip to content

Commit beca5b9

Browse files
authored
CI: Add git-cliff step during publish (solana-labs#7203)
* CI: Add git-cliff step during publish #### Problem The publish step is great, but there's still some manual work to add the changelog and correct title for the created release. #### Summary of changes Use git-cliff to generate the release notes. This comes with a very simple cliff.toml which will do minimal processing, since we don't follow conventional commits in the repo. Here's a test run for the given input: ``` $ git-cliff -c ci/cliff.toml "pod-v0.3.0"..master --include-path "libraries/pod/**" --github-repo "solana-labs/solana-program-library" ``` Output: ``` ## What's new - Publish pod v0.3.2 by @github-actions[bot] - [token-2022] Upgrade to `zk-sdk` (solana-labs#7148) by @samkim-crypto - Implement `Default` for `PodOption` (solana-labs#7083) by @joncinque - Bump to 0.3.1 (solana-labs#7075) by @febo - Improve `PodOption` type (solana-labs#7076) by @febo - Add `PodU128` type (solana-labs#7012) by @febo - Add `PodOption` type (solana-labs#6886) by @febo - Use `bytemuck_derive` explicitly (solana-labs#6928) by @joncinque ``` * Don't always run the step * Make the YAML valid * Trim each commit line to just the first line
1 parent 52e63f5 commit beca5b9

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

.github/workflows/publish-rust.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ jobs:
141141
steps:
142142
- name: Git Checkout
143143
uses: actions/checkout@v4
144+
with:
145+
fetch-depth: 0 # get the whole history for git-cliff
144146

145147
- name: Set env vars
146148
run: |
@@ -201,8 +203,23 @@ jobs:
201203
if: github.event.inputs.dry_run != 'true'
202204
run: git push origin --follow-tags
203205

206+
- name: Generate a changelog
207+
if: github.event.inputs.create_release == 'true'
208+
uses: orhun/git-cliff-action@v3
209+
with:
210+
config: "ci/cliff.toml"
211+
args: |
212+
"${{ steps.publish.outputs.old_git_tag }}"..master
213+
--include-path "${{ inputs.package_path }}/**"
214+
--github-repo "${{ github.repository }}"
215+
env:
216+
OUTPUT: TEMP_CHANGELOG.md
217+
GITHUB_REPO: ${{ github.repository }}
218+
204219
- name: Create GitHub release
205220
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
206221
uses: ncipollo/release-action@v1
207222
with:
208223
tag: ${{ steps.publish.outputs.new_git_tag }}
224+
bodyFile: TEMP_CHANGELOG.md
225+
name: ${{ steps.publish.outputs.release_title }}

ci/cliff.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# git-cliff configuration file
2+
# https://git-cliff.org/docs/configuration
3+
#
4+
# Lines starting with "#" are comments.
5+
# Configuration options are organized into tables and keys.
6+
# See documentation for more information on available options.
7+
8+
[changelog]
9+
header = """
10+
## What's new
11+
"""
12+
# template for the changelog body
13+
# https://tera.netlify.app/docs
14+
body = """
15+
{% for group, commits in commits | group_by(attribute="group") %}\
16+
{% for commit in commits %}
17+
- {{ commit.message | upper_first | split(pat="\n") | first | trim }}\
18+
{% if commit.github.username %} by @{{ commit.github.username }}{%- endif %}\
19+
{% endfor %}\
20+
{% endfor %}
21+
"""
22+
# remove the leading and trailing whitespace from the template
23+
trim = true
24+
footer = """
25+
"""
26+
postprocessors = [ ]
27+
[git]
28+
# parse the commits based on https://www.conventionalcommits.org
29+
conventional_commits = true
30+
# filter out the commits that are not conventional
31+
filter_unconventional = false
32+
# process each line of a commit as an individual commit
33+
split_commits = false
34+
# regex for preprocessing the commit messages
35+
commit_preprocessors = []
36+
# regex for parsing and grouping commits
37+
commit_parsers = [
38+
{ message = "^build\\(deps\\)", skip = true },
39+
{ message = "^build\\(deps-dev\\)", skip = true },
40+
{ message = "^ci", skip = true },
41+
{ body = ".*", group = "Changes" },
42+
]
43+
# protect breaking changes from being skipped due to matching a skipping commit_parser
44+
protect_breaking_commits = false
45+
# filter out the commits that are not matched by commit parsers
46+
filter_commits = false
47+
# glob pattern for matching git tags
48+
tag_pattern = "v[0-9]*"
49+
# regex for skipping tags
50+
skip_tags = ""
51+
# regex for ignoring tags
52+
ignore_tags = ""
53+
# sort the tags topologically
54+
topo_order = false
55+
# sort the commits inside sections by oldest/newest order
56+
sort_commits = "newest"
57+
# limit the number of commits included in the changelog.
58+
# limit_commits = 42

ci/publish-rust.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ DRY_RUN=$3
2020
# Go to the directory
2121
cd "${PACKAGE_PATH}"
2222

23+
# Get the old version, used with git-cliff
24+
old_version=$(readCargoVariable version "Cargo.toml")
25+
2326
# Publish the new version.
2427
if [[ -n ${DRY_RUN} ]]; then
2528
cargo release ${LEVEL}
@@ -37,10 +40,14 @@ new_version=$(readCargoVariable version "Cargo.toml")
3740
package_name=$(readCargoVariable name "Cargo.toml")
3841
tag_name="$(echo $package_name | sed 's/spl-//')"
3942
new_git_tag="${tag_name}-v${new_version}"
43+
old_git_tag="${tag_name}-v${old_version}"
44+
release_title="SPL ${tag_name} - v${new_version}"
4045

4146
# Expose the new version to CI if needed.
4247
if [[ -n $CI ]]; then
4348
echo "new_git_tag=${new_git_tag}" >> $GITHUB_OUTPUT
49+
echo "old_git_tag=${old_git_tag}" >> $GITHUB_OUTPUT
50+
echo "release_title=${release_title}" >> $GITHUB_OUTPUT
4451
fi
4552

4653
# Soft reset the last commit so we can create our own commit and tag.

0 commit comments

Comments
 (0)