Skip to content

Commit 28b72e9

Browse files
committed
ci(release): add github workflow to automatically update changelog and publish release
1 parent f4a38ac commit 28b72e9

File tree

4 files changed

+246
-0
lines changed

4 files changed

+246
-0
lines changed

.github/workflows/changelog.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: Update Changelog
3+
4+
on:
5+
workflow_call:
6+
push:
7+
branches:
8+
- main
9+
paths-ignore:
10+
- CHANGELOG.md
11+
12+
permissions:
13+
contents: write
14+
issues: read
15+
pull-requests: read
16+
17+
jobs:
18+
update-changelog:
19+
name: Update CHANGELOG.md
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Generate a changelog
28+
uses: orhun/git-cliff-action@v4
29+
id: git-cliff
30+
with:
31+
config: cliff.toml
32+
args: -vv
33+
env:
34+
OUTPUT: CHANGELOG.md
35+
GITHUB_REPO: ${{ github.repository }}
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Commit & push changelog
39+
run: |
40+
if git diff --quiet; then
41+
echo "No changes to CHANGELOG.md"
42+
exit 0
43+
fi
44+
45+
git config user.name "github-actions[bot]"
46+
git config user.email "github-actions[bot]@users.noreply.github.com"
47+
git add CHANGELOG.md
48+
git commit -m "docs(changelog): CHANGELOG.md automated update after push on main"
49+
git push origin main
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: Release
3+
4+
on:
5+
push:
6+
tags:
7+
- "v*.*.*"
8+
9+
permissions:
10+
contents: write
11+
issues: read
12+
pull-requests: read
13+
14+
jobs:
15+
ci:
16+
uses: ./.github/workflows/ci.yaml
17+
secrets: inherit
18+
19+
update-changelog:
20+
uses: ./.github/workflows/changelog.yaml
21+
needs:
22+
- ci
23+
secrets: inherit
24+
25+
generate-changelog:
26+
name: Generate a changelog
27+
runs-on: ubuntu-latest
28+
needs:
29+
- ci
30+
outputs:
31+
release_body: ${{ steps.git-cliff.outputs.content }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
- name: Generate a changelog
37+
uses: orhun/git-cliff-action@v4
38+
id: git-cliff
39+
with:
40+
config: cliff.toml
41+
args: -vv --latest --strip header
42+
env:
43+
OUTPUT: CHANGES.md
44+
GITHUB_REPO: ${{ github.repository }}
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
build-publish:
48+
name: Build and Publish release
49+
needs:
50+
- update-changelog
51+
- generate-changelog
52+
runs-on: ${{ matrix.build.os }}
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
build:
57+
- name: linux-x64-glibc
58+
os: ubuntu-latest
59+
target: x86_64-unknown-linux-gnu
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Cache
63+
uses: actions/cache@v4
64+
with:
65+
path: |
66+
~/.cargo/registry
67+
~/.cargo/git
68+
target
69+
key: ${{ matrix.build.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
70+
- name: Build binary
71+
run: cargo build --release --locked --target ${{ matrix.build.target }}
72+
- name: Set the release version
73+
shell: bash
74+
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
75+
- name: Prepare release assets
76+
run: |
77+
mkdir -p release/
78+
cp {LICENSE,README.md,CHANGELOG.md} release/
79+
cp "target/${{ matrix.build.target }}/release/leetcode-cli" release/
80+
mv release/ leetcode-cli-${{ env.RELEASE_VERSION }}/
81+
- name: Create
82+
shell: bash
83+
run: |
84+
tar -czvf leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}.tar.gz \
85+
leetcode-cli-${{ env.RELEASE_VERSION }}/
86+
shasum -a 512 leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}.tar.gz \
87+
> leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}.tar.gz.sha512
88+
- name: Upload the binary releases
89+
id: upload-release
90+
uses: softprops/action-gh-release@v2
91+
with:
92+
files: |
93+
leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}*
94+
body: ${{ needs.generate-changelog.outputs.release_body }}
95+
draft: false
96+
prerelease: false

CHANGELOG.md

Whitespace-only changes.

cliff.toml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[remote.github]
2+
owner = "coding-kelps"
3+
repo = "leetcode-cli"
4+
5+
[changelog]
6+
header = """
7+
# Changelog
8+
9+
All notable changes to this project will be documented in this file.
10+
11+
"""
12+
body = """
13+
{%- macro remote_url() -%}
14+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
15+
{%- endmacro -%}
16+
17+
{% macro print_commit(commit) -%}
18+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
19+
{% if commit.breaking %}[**breaking**] {% endif %}\
20+
{{ commit.message | upper_first }} - \
21+
([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))\
22+
{% endmacro -%}
23+
24+
{% if version %}\
25+
{% if previous.version %}\
26+
## [{{ version | trim_start_matches(pat="v") }}]\
27+
({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }}
28+
{% else %}\
29+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
30+
{% endif %}\
31+
{% else %}\
32+
## [unreleased]
33+
{% endif %}\
34+
35+
{% for group, commits in commits | group_by(attribute="group") %}
36+
### {{ group | striptags | trim | upper_first }}
37+
{% for commit in commits
38+
| filter(attribute="scope")
39+
| sort(attribute="scope") %}
40+
{{ self::print_commit(commit=commit) }}
41+
{%- endfor %}
42+
{% for commit in commits %}
43+
{%- if not commit.scope -%}
44+
{{ self::print_commit(commit=commit) }}
45+
{% endif -%}
46+
{% endfor -%}
47+
{% endfor -%}
48+
{%- if github -%}
49+
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
50+
## New Contributors ❤️
51+
{% endif %}\
52+
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
53+
* @{{ contributor.username }} made their first contribution
54+
{%- if contributor.pr_number %} in \
55+
[#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
56+
{%- endif %}
57+
{%- endfor -%}
58+
{%- endif %}
59+
60+
61+
"""
62+
63+
footer = """
64+
<!-- generated by git-cliff -->
65+
"""
66+
trim = true
67+
68+
[contributors]
69+
# drop any contributor whose username matches one of these literals or regexes
70+
ignore = [
71+
"github-actions\\[bot\\]"
72+
]
73+
74+
[git]
75+
conventional_commits = true
76+
filter_unconventional = true
77+
split_commits = false
78+
79+
commit_parsers = [
80+
{ field = "author.email", pattern = "github-actions\\[bot\\]@users.noreply.github.com", skip = true},
81+
{ message = "^feat", group = "<!-- 0 -->⛰️ Features" },
82+
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
83+
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
84+
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
85+
{ message = "^refactor\\(clippy\\)", skip = true },
86+
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
87+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
88+
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
89+
{ message = "^build", group = "<!-- 7 -->🔨 Build" },
90+
{ message = "^ci", group = "<!-- 8 -->⚙️ Miscellaneous Tasks" },
91+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
92+
]
93+
protect_breaking_commits = false
94+
filter_commits = false
95+
tag_pattern = "v[0-9].*"
96+
skip_tags = "beta|alpha"
97+
ignore_tags = "rc"
98+
topo_order = false
99+
sort_commits = "newest"

0 commit comments

Comments
 (0)