Skip to content

Commit 0bb5b3c

Browse files
committed
build(workflow): support upload files to release page
1 parent eeb657e commit 0bb5b3c

File tree

5 files changed

+187
-53
lines changed

5 files changed

+187
-53
lines changed

.github/workflows/build-release.yml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
name: Build & Release
2+
3+
on:
4+
push:
5+
paths:
6+
- "**/*.c"
7+
- "**/*.h"
8+
- "**/CMakeLists.txt"
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: "build-release"
13+
cancel-in-progress: false
14+
15+
jobs:
16+
build:
17+
name: Build on ${{ matrix.platform }} (${{ matrix.arch }})
18+
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 60
20+
env:
21+
PROJECT_NAME: ${{ github.event.repository.name }}
22+
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- os: ubuntu-latest
28+
platform: Linux
29+
arch: x64
30+
31+
- os: ubuntu-24.04-arm
32+
platform: Linux
33+
arch: arm64
34+
35+
- os: macos-13
36+
platform: macOS
37+
arch: Intel
38+
39+
- os: macos-latest
40+
platform: macOS
41+
arch: arm64
42+
43+
- os: windows-latest
44+
platform: Windows
45+
arch: x64
46+
47+
- os: windows-11-arm
48+
platform: Windows
49+
arch: arm64
50+
51+
steps:
52+
- name: Checkout Git Repository
53+
uses: actions/checkout@v5
54+
with:
55+
submodules: "recursive"
56+
57+
- name: Get Project Name
58+
shell: bash
59+
run: |
60+
PROJECT_NAME=$(node -e "
61+
const fs = require('fs');
62+
try {
63+
const content = fs.readFileSync('CMakeLists.txt', 'utf8');
64+
const match = content.match(/project\s*\(\s*([^ )]+)/);
65+
console.log(match ? match[1] : 'DanmakuFactory');
66+
} catch (err) {
67+
console.log('DanmakuFactory');
68+
}
69+
")
70+
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV
71+
72+
- name: Build Project
73+
uses: threeal/[email protected]
74+
with:
75+
options: CMAKE_BUILD_TYPE=Release
76+
build-args: --config Release --target ${{ env.PROJECT_NAME }}
77+
78+
- name: Upload Artifact
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: package-${{ matrix.platform }}-${{ matrix.arch }}
82+
path: |
83+
build/**/${{ env.PROJECT_NAME }}
84+
build/**/${{ env.PROJECT_NAME }}.exe
85+
retention-days: 1
86+
compression-level: 9
87+
88+
release:
89+
name: Upload to GitHub Release
90+
runs-on: ubuntu-latest
91+
needs: build
92+
93+
permissions:
94+
contents: write
95+
96+
steps:
97+
- name: Checkout Code
98+
uses: actions/checkout@v5
99+
100+
- name: Download All Artifacts
101+
uses: actions/download-artifact@v5
102+
with:
103+
path: artifacts
104+
105+
- name: Prepare Release Assets
106+
shell: bash
107+
run: |
108+
# 创建 release-assets 目录
109+
mkdir -p release-assets
110+
111+
# 遍历所有 package-* 目录
112+
for package_dir in artifacts/package-*; do
113+
# 跳过不存在的匹配
114+
[ -d "$package_dir" ] || continue
115+
116+
# 从目录名提取平台和架构 (格式: package-<platform>-<arch>)
117+
package_name=$(basename "$package_dir")
118+
platform_arch="${package_name#package-}"
119+
120+
# 分割平台和架构 (处理可能的多段架构名,如 "macOS-Intel")
121+
IFS='-' read -ra parts <<< "$platform_arch"
122+
platform="${parts[0]}"
123+
arch="${parts[@]:1}" # 处理可能有多个连字符的情况
124+
125+
# 确定源文件路径
126+
if [ "$platform" = "Windows" ]; then
127+
# Windows 有额外的 Release 目录
128+
src_file="$package_dir/Release/DanmakuFactory.exe"
129+
extension=".exe"
130+
else
131+
src_file="$package_dir/DanmakuFactory"
132+
extension=""
133+
fi
134+
135+
# 检查文件是否存在(处理 Windows 的其他可能路径)
136+
if [ ! -f "$src_file" ] && [ "$platform" = "Windows" ]; then
137+
src_file="$package_dir/DanmakuFactory.exe"
138+
fi
139+
140+
# 跳过不存在的文件
141+
[ -f "$src_file" ] || {
142+
echo "⚠️ 跳过: $package_dir (文件不存在)"
143+
continue
144+
}
145+
146+
# 构建目标文件名 (替换空格为连字符,确保文件名合法)
147+
clean_arch=$(echo "$arch" | tr ' ' '-')
148+
dest_file="release-assets/DanmakuFactory-dev-${platform}-${clean_arch}-CLI${extension}"
149+
150+
# 复制并重命名文件
151+
cp "$src_file" "$dest_file"
152+
echo "✅ 复制: $src_file → $dest_file"
153+
done
154+
155+
# 验证结果
156+
echo -e "\n生成的发布资产:"
157+
ls -lh release-assets/
158+
159+
- name: Update Draft tag
160+
run: |
161+
git tag Draft ${{ github.sha }}
162+
git push origin Draft -f
163+
env:
164+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165+
166+
- name: Upload to GitHub Release
167+
uses: softprops/action-gh-release@v2
168+
with:
169+
tag_name: Draft
170+
name: Continuous Draft Build
171+
body: |
172+
Automated Draft build from commit ${{ github.sha }}
173+
prerelease: true
174+
files: release-assets/*
175+
176+
env:
177+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"yzhang.markdown-all-in-one",
44
"llvm-vs-code-extensions.vscode-clangd",
5-
"sonarsource.sonarlint-vscode"
5+
"sonarsource.sonarlint-vscode",
6+
"esbenp.prettier-vscode",
67
]
78
}

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
},
99
"cmake.configureOnOpen": true,
1010
"cmake.generator": "Ninja",
11-
"sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\compile_commands.json"
11+
"sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\compile_commands.json",
12+
"[yaml]": {
13+
"editor.defaultFormatter": "esbenp.prettier-vscode",
14+
},
1215
}

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ project(DanmakuFactory LANGUAGES C)
44

55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66

7-
if (MSVC)
7+
if(MSVC)
88
add_compile_options(/wd4819)
99
add_compile_options(/wd4996)
1010
endif()
1111

1212
add_subdirectory(pcre2)
1313

14-
add_executable (DanmakuFactory JsonFile.c main.c XmlFile.c
15-
AssFile/AssFile.c AssFile/AssStringProcessing.c Config/Config.c
16-
List/DanmakuFactoryList.c String/DanmakuFactoryString.c TemplateFile/TemplateFile.c)
14+
add_executable(DanmakuFactory JsonFile.c main.c XmlFile.c
15+
AssFile/AssFile.c AssFile/AssStringProcessing.c Config/Config.c
16+
List/DanmakuFactoryList.c String/DanmakuFactoryString.c TemplateFile/TemplateFile.c)
1717

1818
target_link_libraries(DanmakuFactory PRIVATE pcre2-8)
1919

0 commit comments

Comments
 (0)