Skip to content

Commit b3e45e9

Browse files
authored
chore: add release workflow (#4)
1 parent d3c8b35 commit b3e45e9

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-24.04
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Determine next version
18+
id: version
19+
run: |
20+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
21+
if [ -z "$LATEST_TAG" ]; then
22+
echo "next=v0.1.0" >> "$GITHUB_OUTPUT"
23+
echo "initial=true" >> "$GITHUB_OUTPUT"
24+
else
25+
echo "latest=$LATEST_TAG" >> "$GITHUB_OUTPUT"
26+
echo "initial=false" >> "$GITHUB_OUTPUT"
27+
fi
28+
29+
- name: Calculate bumped version
30+
if: steps.version.outputs.initial == 'false'
31+
uses: orhun/git-cliff-action@v4
32+
id: bump
33+
with:
34+
args: --bumped-version
35+
36+
- name: Check if version changed
37+
if: steps.version.outputs.initial == 'false'
38+
id: check
39+
env:
40+
BUMP_CONTENT: ${{ steps.bump.outputs.content }}
41+
LATEST: ${{ steps.version.outputs.latest }}
42+
run: |
43+
NEXT=$(echo "$BUMP_CONTENT" | tr -d '[:space:]')
44+
if [ "$NEXT" = "$LATEST" ] || [ -z "$NEXT" ]; then
45+
echo "skip=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "next=$NEXT" >> "$GITHUB_OUTPUT"
48+
echo "skip=false" >> "$GITHUB_OUTPUT"
49+
fi
50+
51+
- name: Resolve version
52+
id: resolve
53+
env:
54+
IS_INITIAL: ${{ steps.version.outputs.initial }}
55+
INITIAL_NEXT: ${{ steps.version.outputs.next }}
56+
CHECK_NEXT: ${{ steps.check.outputs.next }}
57+
CHECK_SKIP: ${{ steps.check.outputs.skip }}
58+
run: |
59+
if [ "$IS_INITIAL" = "true" ]; then
60+
echo "next=$INITIAL_NEXT" >> "$GITHUB_OUTPUT"
61+
echo "skip=false" >> "$GITHUB_OUTPUT"
62+
else
63+
echo "next=$CHECK_NEXT" >> "$GITHUB_OUTPUT"
64+
echo "skip=$CHECK_SKIP" >> "$GITHUB_OUTPUT"
65+
fi
66+
67+
- name: Generate changelog
68+
if: steps.resolve.outputs.skip == 'false'
69+
uses: orhun/git-cliff-action@v4
70+
id: changelog
71+
with:
72+
args: --unreleased --strip header --tag ${{ steps.resolve.outputs.next }}
73+
74+
- name: Create tag and release
75+
if: steps.resolve.outputs.skip == 'false'
76+
env:
77+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
CHANGELOG: ${{ steps.changelog.outputs.content }}
79+
TAG: ${{ steps.resolve.outputs.next }}
80+
run: |
81+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
82+
echo "Tag $TAG already exists"
83+
exit 0
84+
fi
85+
git tag "$TAG"
86+
git push origin "$TAG"
87+
gh release create "$TAG" --title "$TAG" --notes "$CHANGELOG"

cliff.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[changelog]
2+
header = """
3+
# Changelog\n
4+
All notable changes to this project will be documented in this file.\n
5+
"""
6+
body = """
7+
{% if version %}\
8+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
9+
{% else %}\
10+
## [unreleased]
11+
{% endif %}\
12+
{% for group, commits in commits | group_by(attribute="group") %}
13+
### {{ group | striptags | trim | upper_first }}
14+
{% for commit in commits %}
15+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
16+
{{ commit.message | upper_first }}\
17+
{% endfor %}
18+
{% endfor %}\n
19+
"""
20+
trim = true
21+
22+
[git]
23+
conventional_commits = true
24+
filter_unconventional = true
25+
split_commits = false
26+
commit_parsers = [
27+
{ message = "^feat", group = "Features" },
28+
{ message = "^fix", group = "Bug Fixes" },
29+
{ message = "^docs", group = "Documentation" },
30+
{ message = "^refactor", group = "Refactor" },
31+
{ message = "^test", group = "Testing" },
32+
{ message = "^chore\\(release\\)", skip = true },
33+
{ message = "^chore", group = "Miscellaneous" },
34+
{ message = "^ci", skip = true },
35+
]
36+
protect_breaking_commits = false
37+
tag_pattern = "v[0-9].*"
38+
sort_commits = "oldest"

0 commit comments

Comments
 (0)