Skip to content

Commit dd36ff0

Browse files
ci: 👷 自动发布构建。
1 parent f3c8deb commit dd36ff0

7 files changed

Lines changed: 277 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"types": [
3+
{"type": "feat", "section": "✨ 新功能"},
4+
{"type": "feature", "section": "✨ 新功能"},
5+
{"type": "fix", "section": "🐛 问题修复"},
6+
{"type": "perf", "section": "⚡ 性能优化"},
7+
{"type": "docs", "section": "📚 文档"},
8+
{"type": "style", "section": "🎨 样式调整"},
9+
{"type": "refactor", "section": "🔨 重构"},
10+
{"type": "test", "section": "🧪 测试"},
11+
{"type": "build", "section": "📦 构建系统"},
12+
{"type": "ci", "section": "🔄 CI/CD"},
13+
{"type": "chore", "section": "🧹 其他变更"}
14+
]
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
types: [
3+
{ type: 'feat', section: '✨ 新功能 Features' },
4+
{ type: 'feature', section: '✨ 新功能 Features' },
5+
{ type: 'fix', section: '🐛 问题修复 Bug Fixes' },
6+
{ type: 'perf', section: '⚡ 性能优化 Performance Improvements' },
7+
{ type: 'docs', section: '📚 文档 Documentation' },
8+
{ type: 'style', section: '🎨 样式调整 Style Changes' },
9+
{ type: 'refactor', section: '🔨 重构 Refactoring' },
10+
{ type: 'test', section: '🧪 测试 Tests' },
11+
{ type: 'build', section: '📦 构建系统 Build System' },
12+
{ type: 'ci', section: '🔄 CI/CD' },
13+
{ type: 'chore', section: '🧹 其他变更 Chore' }
14+
],
15+
commitUrlFormat: '{{host}}/{{owner}}/{{repository}}/commit/{{hash}}',
16+
compareUrlFormat: '{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}',
17+
issueUrlFormat: '{{host}}/{{owner}}/{{repository}}/issues/{{id}}',
18+
userUrlFormat: '{{host}}/{{owner}}/{{username}}'
19+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
4+
// 自定义配置
5+
const config = {
6+
types: [
7+
{ type: 'feat', section: '✨ 新功能 Features' },
8+
{ type: 'feature', section: '✨ 新功能 Features' },
9+
{ type: 'fix', section: '🐛 问题修复 Bug Fixes' },
10+
{ type: 'perf', section: '⚡ 性能优化 Performance Improvements' },
11+
{ type: 'docs', section: '📚 文档 Documentation' },
12+
{ type: 'style', section: '🎨 样式调整 Style Changes' },
13+
{ type: 'refactor', section: '🔨 重构 Refactoring' },
14+
{ type: 'test', section: '🧪 测试 Tests' },
15+
{ type: 'build', section: '📦 构建系统 Build System' },
16+
{ type: 'ci', section: '🔄 CI/CD' },
17+
{ type: 'chore', section: '🧹 其他变更 Chore' }
18+
]
19+
};
20+
21+
// 获取最新的标签
22+
let latestTag = '';
23+
try {
24+
latestTag = execSync('git describe --tags $(git rev-list --tags --max-count=1)', { encoding: 'utf8' }).trim();
25+
} catch (e) {
26+
// 如果没有标签,则使用初始标签
27+
latestTag = '';
28+
}
29+
30+
// 获取提交历史
31+
let commits;
32+
if (!latestTag) {
33+
commits = execSync('git log --pretty=format:"%s||%b||%an" --reverse HEAD', { encoding: 'utf8' });
34+
} else {
35+
commits = execSync(`git log --pretty=format:"%s||%b||%an" --reverse ${latestTag}..HEAD`, { encoding: 'utf8' });
36+
}
37+
38+
// 解析提交
39+
const commitList = commits.split('\n').filter(c => c.trim() !== '');
40+
41+
// 按类型分组提交
42+
const groupedCommits = {};
43+
commitList.forEach(commit => {
44+
const [subject, body, author] = commit.split('||');
45+
const match = subject.match(/^(feat|feature|fix|perf|docs|style|refactor|test|build|ci|chore)(?:\(.+\))?:\s*(.+)$/i);
46+
47+
let type = 'chore'; // 默认类型
48+
let message = subject;
49+
50+
if (match) {
51+
type = match[1].toLowerCase();
52+
message = match[2];
53+
}
54+
55+
// 查找对应的分组名
56+
const typeConfig = config.types.find(t => t.type === type);
57+
const sectionName = typeConfig ? typeConfig.section : '🧹 其他变更 Chore';
58+
59+
if (!groupedCommits[sectionName]) {
60+
groupedCommits[sectionName] = [];
61+
}
62+
63+
groupedCommits[sectionName].push({
64+
type,
65+
message,
66+
author: author || 'Unknown'
67+
});
68+
});
69+
70+
// 生成 changelog 内容
71+
let changelogContent = '## 更新日志\n\n';
72+
73+
Object.keys(groupedCommits).forEach(section => {
74+
if (groupedCommits[section].length > 0) {
75+
changelogContent += `### ${section}\n\n`;
76+
77+
groupedCommits[section].forEach(commit => {
78+
changelogContent += `- ${commit.message} (${commit.author})\n`;
79+
});
80+
81+
changelogContent += '\n';
82+
}
83+
});
84+
85+
// 输出到文件
86+
fs.writeFileSync('temp_changelog.md', changelogContent);
87+
console.log('Changelog generated successfully');

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
run: npm install -g yarn
2121
- name: Install Dependencies
2222
run: yarn
23+
- name: Install conventional-changelog
24+
run: npm install -g conventional-changelog-cli conventional-changelog-angular
2325
- name: Delete Unnecessary Files on Windows
2426
if: matrix.os == 'windows-latest'
2527
run: |
@@ -37,6 +39,30 @@ jobs:
3739
if: matrix.os != 'windows-latest'
3840
run: rm -rf README.md && rm -rf .git && rm -rf .github && rm -rf .gitignore && rm -rf .gitattributes && rm -rf .vscode && rm -rf readme && rm -rf installer && rm -rf changelog
3941
shell: bash
42+
- name: Generate changelog
43+
run: |
44+
# 生成 changelog
45+
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
46+
echo "Latest tag: $LATEST_TAG"
47+
48+
# 如果没有标签,则使用所有提交
49+
if [ -z "$LATEST_TAG" ]; then
50+
# 为首次发布创建初始标签
51+
git config --global user.name 'GitHub Action'
52+
git config --global user.email 'action@github.com'
53+
git tag v0.0.0
54+
LATEST_TAG="v0.0.0"
55+
fi
56+
57+
# 使用自定义脚本生成 changelog
58+
node .github/generate-conventional-changelog.js
59+
60+
# 复制 changelog 到输出目录(如果存在)
61+
if [ -f temp_changelog.md ]; then
62+
mkdir -p ./out/
63+
cp temp_changelog.md ./out/changelog.md
64+
fi
65+
4066
- name: Build with electron-forge
4167
run: "yarn make"
4268
- name: Upload Build Artifacts (Windows)

.github/workflows/release.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ QQ群:925490458
2424
## 技术栈
2525

2626
- [Electron](https://www.electronjs.org/)
27-
- [FluentUI](https://developer.microsoft.com/zh-cn/fluentui)
27+
- [FluentUI](https://developer.microsoft.com/zh-cn/fluentui)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@electron-forge/maker-deb": "^7.10.2",
1919
"@electron-forge/maker-squirrel": "^7.10.2",
2020
"@electron-forge/maker-zip": "^7.10.2",
21+
"conventional-changelog-cli": "^5.0.0",
2122
"electron": "^39.2.7"
2223
}
2324
}

0 commit comments

Comments
 (0)