1+ name : Release
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ release_version :
7+ description : ' Release Version (e.g., v1.2.0)'
8+ required : true
9+ default : ' v1.0.0'
10+ release_title :
11+ description : ' Release Title'
12+ required : true
13+ default : ' New Release'
14+ build_run_id :
15+ description : ' Build Run ID to download artifacts from'
16+ required : true
17+ default : ' '
18+
19+ jobs :
20+ release :
21+ runs-on : ubuntu-latest
22+ steps :
23+ - name : Checkout repository
24+ uses : actions/checkout@v4
25+ with :
26+ fetch-depth : 0 # 获取所有历史记录以便生成changelog
27+
28+ - name : Setup Node.js
29+ uses : actions/setup-node@v4
30+ with :
31+ node-version : ' 18'
32+
33+ - name : Install conventional-changelog
34+ run : |
35+ npm install -g conventional-changelog-cli conventional-changelog-angular
36+
37+ - name : Generate changelog
38+ id : changelog
39+ run : |
40+ # 生成 changelog
41+ LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
42+ echo "Latest tag: $LATEST_TAG"
43+
44+ # 如果没有标签,则使用所有提交
45+ if [ -z "$LATEST_TAG" ]; then
46+ # 为首次发布创建初始标签
47+ git config --global user.name 'GitHub Action'
48+ git config --global user.email 'action@github.com'
49+ git tag v0.0.0
50+ LATEST_TAG="v0.0.0"
51+ fi
52+
53+ # 使用自定义脚本生成 changelog
54+ node .github/generate-conventional-changelog.js
55+
56+ # 检查是否生成了有效的 changelog
57+ if [ -f temp_changelog.md ] && [ -s temp_changelog.md ]; then
58+ echo "Custom changelog generated successfully"
59+ else
60+ echo "Custom changelog generation failed, using manual approach"
61+ if [ "$LATEST_TAG" = "v0.0.0" ]; then
62+ COMMITS=$(git log --pretty=format:"- %h %s (%an)" --reverse HEAD)
63+ else
64+ COMMITS=$(git log --pretty=format:"- %h %s (%an)" --reverse $LATEST_TAG..HEAD)
65+ fi
66+ echo "$COMMITS" > temp_changelog.md
67+ fi
68+
69+ # 读取changelog内容并设置输出
70+ CHANGELOG_CONTENT=$(cat temp_changelog.md)
71+ echo "changelog_content<<EOF" >> $GITHUB_OUTPUT
72+ echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
73+ echo "EOF" >> $GITHUB_OUTPUT
74+
75+ - name : Download build artifacts
76+ uses : actions/download-artifact@v4
77+ with :
78+ github-token : ${{ secrets.GITHUB_TOKEN }}
79+ run-id : ${{ github.event.inputs.build_run_id }}
80+ merge-multiple : true
81+ path : ./downloaded_artifacts
82+
83+ - name : Display downloaded artifacts
84+ run : |
85+ echo "Downloaded artifacts:"
86+ find ./downloaded_artifacts -type f
87+
88+ - name : Organize assets for release
89+ run : |
90+ mkdir -p ./release_assets
91+ find ./downloaded_artifacts -name "*.exe" -o -name "*.deb" -o -name "*.rpm" -o -name "*.zip" -o -name "*.dmg" -o -name "*.nupkg" -o -name "*.AppImage" | xargs -I {} cp {} ./release_assets/
92+ echo "Release assets prepared:"
93+ ls -la ./release_assets/
94+
95+ - name : Create Release
96+ id : create_release
97+ uses : actions/create-release@v1
98+ env :
99+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
100+ with :
101+ tag_name : ${{ github.event.inputs.release_version }}
102+ release_name : ${{ github.event.inputs.release_title }}
103+ body : |
104+ ## Changelog
105+
106+ ${{ steps.changelog.outputs.changelog_content }}
107+
108+ ## Assets
109+ 本次发布使用的构建产物来自构建运行 #${{ github.event.inputs.build_run_id }}:
110+
111+ 此版本包含以下文件:
112+ draft : false
113+ prerelease : false
114+
115+ - name : Upload release assets
116+ run : |
117+ # 上传所有release assets
118+ for file in ./release_assets/*; do
119+ if [ -f "$file" ]; then
120+ asset_name=$(basename "$file")
121+ echo "Uploading $asset_name..."
122+
123+ # 使用GitHub CLI上传资产
124+ gh release upload ${{ github.event.inputs.release_version }} "$file" --repo ${{ github.repository }} || echo "Failed to upload $asset_name"
125+ fi
126+ done
127+ env :
128+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments