Skip to content

Commit 9a6cdc2

Browse files
authored
build: release and publish pipelines (#5)
Use [release-plz](https://release-plz.dev/) to start automatizing the release process: 1. `Release` job can be manually triggered to create a new PR containing the new versions and changelog for the next release. 2. `Publish` job can be manually triggered to create a new Github release and push the corresponding artifacts on crates.io.
1 parent 0f4b365 commit 9a6cdc2

File tree

4 files changed

+189
-0
lines changed

4 files changed

+189
-0
lines changed

.github/workflows/publish.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
# Release unpublished packages.
8+
release-plz-release:
9+
name: Publish artifacts
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
contents: write
14+
concurrency:
15+
group: publish
16+
cancel-in-progress: true
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: "Install parse-changelog"
24+
uses: taiki-e/install-action@parse-changelog
25+
26+
- name: "Run release-plz"
27+
id: release-plz
28+
uses: release-plz/action@8724d33cd97b8295051102e2e19ca592962238f5 # v0.5.108
29+
with:
30+
command: release
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
34+
35+
- name: "Generate Github release body"
36+
env:
37+
RELEASES: ${{ steps.release-plz.outputs.releases }}
38+
RELEASES_CREATED: ${{ steps.release-plz.outputs.releases_created }}
39+
run: |
40+
set -e
41+
echo "releases: $RELEASES" # example: [{"package_name":"my-package","prs":[{"html_url":"https://github.com/user/proj/pull/1439","number":1439}],"tag":"v0.1.0","version":"0.1.0"}]
42+
echo "releases_created: $RELEASES_CREATED" # example: true
43+
44+
release_tag=$(echo "$RELEASES" | jq -r '.[] | select(.package_name == "canhttp") | .tag')
45+
echo "release_tag: $release_tag"
46+
echo "RELEASE_TAG=$release_tag" >> "$GITHUB_ENV"
47+
48+
release_version=$(echo "$RELEASES" | jq -r '.[] | select(.package_name == "canhttp") | .version')
49+
echo "release_version: $release_version"
50+
echo "RELEASE_VERSION=$release_version" >> "$GITHUB_ENV"
51+
52+
notes=$(parse-changelog canister/CHANGELOG.md "$release_version")
53+
54+
CHANGELOG="$notes" envsubst < release_notes.md >> ${{ github.workspace }}-RELEASE.txt
55+
56+
- name: "Create Github release"
57+
uses: softprops/action-gh-release@v2
58+
with:
59+
draft: true
60+
tag_name: ${{ env.RELEASE_TAG}}
61+
body_path: ${{ github.workspace }}-RELEASE.txt

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
# Create a PR with the new versions and changelog, preparing the next release.
8+
release-plz-pr:
9+
name: Release-plz PR
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
contents: write
14+
concurrency:
15+
group: release-plz-${{ github.ref }}
16+
cancel-in-progress: false
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Run release-plz
23+
uses: release-plz/action@8724d33cd97b8295051102e2e19ca592962238f5 # v0.5.108
24+
with:
25+
command: release-pr
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

cliff.toml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[changelog]
5+
# template for the changelog header
6+
header = """
7+
# Changelog\n
8+
All notable changes to this project will be documented in this file.
9+
10+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
11+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n
12+
"""
13+
# template for the changelog body
14+
# https://keats.github.io/tera/docs/#introduction
15+
body = """
16+
{% if version -%}
17+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
18+
{% else -%}
19+
## [Unreleased]
20+
{% endif -%}
21+
{% for group, commits in commits | group_by(attribute="group") %}
22+
### {{ group | upper_first }}
23+
{% for commit in commits %}
24+
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
25+
{% endfor %}
26+
{% endfor %}\n
27+
"""
28+
# template for the changelog footer
29+
footer = """
30+
{% for release in releases -%}
31+
{% if release.version -%}
32+
{% if release.previous.version -%}
33+
[{{ release.version | trim_start_matches(pat="v") }}]: \
34+
https://github.com/dfinity/canhttp\
35+
/compare/{{ release.previous.version }}..{{ release.version }}
36+
{% endif -%}
37+
{% else -%}
38+
[unreleased]: https://github.com/dfinity/canhttp\
39+
/compare/{{ release.previous.version }}..HEAD
40+
{% endif -%}
41+
{% endfor %}
42+
"""
43+
# remove the leading and trailing whitespace from the templates
44+
trim = true
45+
46+
[git]
47+
# parse the commits based on https://www.conventionalcommits.org
48+
conventional_commits = true
49+
# filter out the commits that are not conventional
50+
filter_unconventional = false
51+
# regex for parsing and grouping commits
52+
commit_parsers = [
53+
{ message = "^[a|A]dd", group = "Added" },
54+
{ message = "^[s|S]upport", group = "Added" },
55+
{ message = "^[r|R]emove", group = "Removed" },
56+
{ message = "^.*: add", group = "Added" },
57+
{ message = "^.*: support", group = "Added" },
58+
{ message = "^.*: remove", group = "Removed" },
59+
{ message = "^.*: delete", group = "Removed" },
60+
{ message = "^test", group = "Fixed" },
61+
{ message = "^fix", group = "Fixed" },
62+
{ message = "^.*: fix", group = "Fixed" },
63+
{ message = "^.*", group = "Changed" },
64+
]
65+
# filter out the commits that are not matched by commit parsers
66+
filter_commits = false
67+
# sort the tags topologically
68+
topo_order = false
69+
# sort the commits inside sections by oldest/newest order
70+
sort_commits = "newest"

release-plz.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[workspace]
2+
# path of the git-cliff configuration
3+
changelog_config = "cliff.toml"
4+
5+
# enable changelog updates
6+
changelog_update = true
7+
8+
# update dependencies with `cargo update`
9+
dependencies_update = true
10+
11+
# Enable git releases for all packages by default
12+
git_release_enable = true
13+
14+
# Enable git tags for all packages by default
15+
git_tag_enable = true
16+
17+
# creates the git release as draft
18+
git_release_draft = true
19+
20+
# If true, creates the release PR as a draft.
21+
pr_draft = true
22+
23+
# labels for the release PR
24+
pr_labels = ["release"]
25+
26+
# disallow updating repositories with uncommitted changes
27+
allow_dirty = false
28+
29+
# disallow packaging with uncommitted changes
30+
publish_allow_dirty = false

0 commit comments

Comments
 (0)