Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Commit 230c0c3

Browse files
committed
chore: add auto release file
1 parent 4fac35b commit 230c0c3

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Generate release body
22+
id: release_body
23+
shell: bash
24+
run: |
25+
set -euo pipefail
26+
27+
git fetch --tags --force
28+
29+
current_tag="${GITHUB_REF_NAME}"
30+
31+
prev_tag="$(git tag --sort=-creatordate | grep -vx "$current_tag" | head -n 1 || true)"
32+
33+
if [ -n "${prev_tag:-}" ]; then
34+
range="${prev_tag}..${current_tag}"
35+
header="New commits: ${prev_tag}..${current_tag}"
36+
else
37+
range="${current_tag}"
38+
header="New commits: first time to ${current_tag}"
39+
fi
40+
41+
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
42+
43+
tmp="$(mktemp)"
44+
git log --no-merges --pretty=format:'%s|%h|%H' ${range} > "$tmp" || true
45+
46+
map_section_title() {
47+
case "$1" in
48+
feat) echo "feature: " ;;
49+
fix) echo "fix bug: " ;;
50+
docs) echo "documents: " ;;
51+
style) echo "style: " ;;
52+
refactor) echo "refactor: " ;;
53+
perf) echo "performance: " ;;
54+
test) echo "test: " ;;
55+
chore) echo "chore: " ;;
56+
revert) echo "revert: " ;;
57+
esac
58+
}
59+
60+
body_file="$(mktemp)"
61+
echo "# Release ${current_tag}" >> "$body_file"
62+
echo "" >> "$body_file"
63+
echo "${header}" >> "$body_file"
64+
echo "" >> "$body_file"
65+
66+
types=(feat fix docs style refactor perf test chore revert)
67+
total_count=0
68+
69+
for t in "${types[@]}"; do
70+
entries="$(awk -F'|' -v t="^${t}([^)]+)?: " -v repo_url="$repo_url" '
71+
$1 ~ t {
72+
# $1=subject, $2=short, $3=full
73+
printf("- %s ([%s](%s/commit/%s))\n", $1, $2, repo_url, $3)
74+
}' "$tmp")"
75+
76+
if [ -n "$entries" ]; then
77+
total_count=$((total_count+1))
78+
echo "## $(map_section_title "$t")" >> "$body_file"
79+
echo "$entries" >> "$body_file"
80+
echo "" >> "$body_file"
81+
fi
82+
done
83+
84+
{
85+
echo "body<<EOF"
86+
cat "$body_file"
87+
echo "EOF"
88+
} >> "$GITHUB_OUTPUT"
89+
90+
- name: Create GitHub Release
91+
uses: softprops/action-gh-release@v2
92+
with:
93+
tag_name: ${{ github.ref_name }}
94+
name: Release ${{ github.ref_name }}
95+
body: ${{ steps.release_body.outputs.body }}
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)