Skip to content

Commit 57825ba

Browse files
authored
Merge pull request #27 from automagik-dev/feat/workit-autorelease-fix
ci: git-cliff for release notes + RELEASE_PLEASE_TOKEN
2 parents 2c5a748 + c1af5a5 commit 57825ba

2 files changed

Lines changed: 110 additions & 36 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88
inputs:
99
tag:
10-
description: "Tag to (re)release (e.g. v0.1.0)"
10+
description: "Tag to (re)release (e.g. v2.260227.1)"
1111
required: true
1212
type: string
1313

@@ -49,63 +49,62 @@ jobs:
4949
goreleaser:
5050
needs: [test, worker]
5151
runs-on: macos-latest
52+
env:
53+
GH_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
5254
steps:
5355
- name: Checkout
5456
uses: actions/checkout@v4
5557
with:
5658
fetch-depth: 0
59+
token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
5760

5861
- name: Setup Go
5962
uses: actions/setup-go@v5
6063
with:
6164
go-version-file: go.mod
6265
cache: true
6366

64-
- name: Stash GoReleaser config
65-
run: cp .goreleaser.yaml /tmp/.goreleaser.yaml
67+
- name: Resolve tag
68+
id: tag
69+
run: |
70+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
71+
echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
72+
else
73+
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
74+
fi
6675
6776
- name: Checkout release tag
68-
if: ${{ github.event_name == 'workflow_dispatch' }}
69-
run: git checkout ${{ inputs.tag }}
77+
run: git checkout ${{ steps.tag.outputs.tag }}
7078

71-
- name: Generate changelog-backed release notes
72-
shell: bash
79+
- name: Find previous release tag
80+
id: prev
7381
run: |
74-
set -euo pipefail
75-
tag="${{ github.ref_name }}"
76-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
77-
tag="${{ inputs.tag }}"
78-
fi
79-
version="${tag#v}"
80-
notes_file="/tmp/release-notes.md"
81-
awk -v ver="$version" '
82-
$0 ~ "^## "ver" " {print "## "ver; in_section=1; next}
83-
in_section && /^## / {exit}
84-
in_section {print}
85-
' CHANGELOG.md | sed '/^$/d' > "$notes_file"
86-
if [[ ! -s "$notes_file" ]]; then
87-
echo "missing release notes section for $version in CHANGELOG.md" >&2
88-
exit 1
89-
fi
90-
echo "RELEASE_NOTES_FILE=$notes_file" >> "$GITHUB_ENV"
82+
PREV=$(git tag --list 'v*' --sort=-version:refname | grep -v "^${{ steps.tag.outputs.tag }}$" | head -1)
83+
echo "tag=${PREV:-}" >> "$GITHUB_OUTPUT"
84+
echo "Previous tag: ${PREV:-none}"
85+
86+
- name: Generate release notes with git-cliff
87+
uses: orhun/git-cliff-action@e16f179f0be49ecdfe63753837f20b9531642772 # v4.7.0
88+
id: cliff
89+
with:
90+
config: cliff.toml
91+
args: ${{ steps.prev.outputs.tag && format('{0}..{1}', steps.prev.outputs.tag, steps.tag.outputs.tag) || steps.tag.outputs.tag }}
92+
env:
93+
GITHUB_REPO: ${{ github.repository }}
94+
95+
- name: Stash GoReleaser config
96+
run: cp .goreleaser.yaml /tmp/.goreleaser.yaml
9197

9298
- name: GoReleaser
9399
uses: goreleaser/goreleaser-action@v6
94100
with:
95101
distribution: goreleaser
96102
version: latest
97-
args: release --clean --config /tmp/.goreleaser.yaml
103+
args: release --clean --config /tmp/.goreleaser.yaml --release-notes /tmp/release-notes.md
98104
env:
99-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
GITHUB_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
100106

101-
- name: Apply generated notes to release
102-
shell: bash
107+
- name: Write cliff notes to file and update release
103108
run: |
104-
set -euo pipefail
105-
tag="${{ github.ref_name }}"
106-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
107-
tag="${{ inputs.tag }}"
108-
fi
109-
gh release edit "$tag" --notes-file "$RELEASE_NOTES_FILE"
110-
env:
111-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
echo "${{ steps.cliff.outputs.content }}" > /tmp/release-notes.md
110+
gh release edit "${{ steps.tag.outputs.tag }}" --notes-file /tmp/release-notes.md

‎cliff.toml‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[changelog]
2+
header = ""
3+
body = """
4+
{%- macro render_group(name, commits) -%}
5+
{%- set found = commits | filter(attribute="group", value=name) -%}
6+
{%- if found | length > 0 %}
7+
### {{ name }}
8+
{% for commit in found -%}
9+
- **{{ commit.scope | default(value="core") }}:** {{ commit.message | split(pat="\n") | first | trim }} ([`{{ commit.id | truncate(length=7, end="") }}`](https://github.com/automagik-dev/workit/commit/{{ commit.id }}))
10+
{% endfor %}
11+
{%- endif -%}
12+
{%- endmacro -%}
13+
14+
{{ self::render_group(name="🚀 Features", commits=commits) -}}
15+
{{ self::render_group(name="🐛 Bug Fixes", commits=commits) -}}
16+
{{ self::render_group(name="⚡ Performance", commits=commits) -}}
17+
{{ self::render_group(name="♻️ Refactoring", commits=commits) -}}
18+
{{ self::render_group(name="🧪 Testing", commits=commits) -}}
19+
{{ self::render_group(name="📚 Documentation", commits=commits) -}}
20+
{{ self::render_group(name="⚙️ CI/CD", commits=commits) -}}
21+
{{ self::render_group(name="🔧 Miscellaneous", commits=commits) -}}
22+
23+
{%- set_global contributors = [] -%}
24+
{%- for commit in commits -%}
25+
{%- set author = commit.author.name | default(value="") -%}
26+
{%- if author != "" and author != "github-actions[bot]" -%}
27+
{%- if contributors is not containing(author) -%}
28+
{%- set_global contributors = contributors | concat(with=author) -%}
29+
{%- endif -%}
30+
{%- endif -%}
31+
{%- endfor -%}
32+
33+
{%- if contributors | length > 0 %}
34+
### 👥 Contributors
35+
{% for name in contributors -%}
36+
{%- if name == "Cezar Vasconcelos" -%}
37+
- [@vasconceloscezar](https://github.com/vasconceloscezar)
38+
{% elif name == "Felipe Rosa" -%}
39+
- [@namastex888](https://github.com/namastex888)
40+
{% elif name == "Automagik Genie" -%}
41+
- [@automagik-genie](https://github.com/automagik-genie) 🤖
42+
{% else -%}
43+
- {{ name }}
44+
{% endif -%}
45+
{%- endfor -%}
46+
{%- endif -%}
47+
"""
48+
trim = true
49+
50+
[git]
51+
conventional_commits = true
52+
filter_unconventional = true
53+
# Ignore intermediate version tags within the commit range to prevent
54+
# duplicate section headers. The range boundaries are set by the workflow.
55+
ignore_tags = ".*"
56+
sort_commits = "newest"
57+
58+
# Escape @ mentions in commit messages so GitHub doesn't linkify them as users
59+
commit_preprocessors = [
60+
{ pattern = "@([a-zA-Z])", replace = "@\u200B${1}" },
61+
]
62+
63+
commit_parsers = [
64+
{ message = "^feat", group = "🚀 Features" },
65+
{ message = "^fix", group = "🐛 Bug Fixes" },
66+
{ message = "^refactor", group = "♻️ Refactoring" },
67+
{ message = "^perf", group = "⚡ Performance" },
68+
{ message = "^test", group = "🧪 Testing" },
69+
{ message = "^doc", group = "📚 Documentation" },
70+
{ message = "^ci", group = "⚙️ CI/CD" },
71+
{ message = "^chore\\(version\\)", skip = true },
72+
{ message = "^chore", group = "🔧 Miscellaneous" },
73+
{ message = "^Merge", skip = true },
74+
{ message = ".*", group = "🔧 Miscellaneous" },
75+
]

0 commit comments

Comments
 (0)