Skip to content

Commit a92af99

Browse files
ci: 添加 GitHub Release 和自动生成 changelog 到发布流程
1 parent cfe1552 commit a92af99

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

.github/workflows/publish-npm.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ on:
66
- 'v*'
77

88
permissions:
9-
contents: read
9+
contents: write
1010
packages: write
11+
id-token: write
1112

1213
jobs:
1314
publish:
@@ -51,3 +52,36 @@ jobs:
5152
npm publish --tag "$TAG" --access public
5253
env:
5354
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
55+
56+
- name: Generate changelog
57+
id: changelog
58+
run: |
59+
PREV_TAG=$(git tag --sort=-version:refname | head -2 | tail -1)
60+
if [ "$PREV_TAG" = "$GITHUB_REF_NAME" ]; then
61+
PREV_TAG=""
62+
fi
63+
64+
if [ -n "$PREV_TAG" ]; then
65+
COMMITS=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h)" --no-merges)
66+
else
67+
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges -20)
68+
fi
69+
70+
{
71+
echo "commits<<EOF"
72+
echo "$COMMITS"
73+
echo "EOF"
74+
} >> "$GITHUB_OUTPUT"
75+
76+
- name: Create GitHub Release
77+
uses: softprops/action-gh-release@v2
78+
with:
79+
name: ${{ github.ref_name }}
80+
body: |
81+
## What's Changed
82+
83+
${{ steps.changelog.outputs.commits }}
84+
85+
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.ref_name }}^...${{ github.ref_name }}
86+
draft: false
87+
prerelease: ${{ contains(github.ref_name, 'rc') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }}

0 commit comments

Comments
 (0)