1+ name : build-and-release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+
8+ env :
9+ NODE_VERSION : ' 22' # 使用 Node.js 22 版本
10+
11+ jobs :
12+ build-and-release :
13+ runs-on : ubuntu-latest
14+ permissions :
15+ contents : write # 需要写入权限来创建发布
16+
17+ steps :
18+ - name : Checkout repository
19+ uses : actions/checkout@v4
20+ with :
21+ fetch-depth : 0 # 获取所有历史记录
22+
23+ - name : Setup Node.js 22
24+ uses : actions/setup-node@v4
25+ with :
26+ node-version : ${{ env.NODE_VERSION }}
27+ cache : ' npm'
28+
29+ - name : Install 7zip
30+ run : |
31+ sudo apt-get update
32+ sudo apt-get install -y p7zip-full
33+
34+ - name : Install dependencies
35+ run : npm ci
36+
37+ - name : Run packageJS script
38+ run : npm run packageJS
39+
40+ - name : Run packageJS-green script
41+ run : npm run packageJS-green
42+
43+ - name : Find generated 7z files
44+ run : |
45+ # 在上级目录查找生成的 7z 文件
46+ cd ..
47+ echo "Generated files:"
48+ ls -la *.7z || echo "No 7z files found"
49+ # 将文件列表保存到环境变量中
50+ echo "FILES=$(ls *.7z 2>/dev/null | tr '\n' ' ')" >> $GITHUB_ENV
51+
52+ - name : Create Release
53+ id : create_release
54+ uses : actions/create-release@v1
55+ env :
56+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57+ with :
58+ tag_name : ${{ github.ref_name }}
59+ release_name : Release ${{ github.ref_name }}
60+ draft : false
61+ prerelease : false
62+
63+ - name : Upload Release Assets
64+ env :
65+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
66+ run : |
67+ # 切换到上级目录
68+ cd ..
69+ # 上传所有找到的 7z 文件
70+ for file in $FILES; do
71+ echo "Uploading $file..."
72+ curl -s \
73+ -H "Authorization: token $GITHUB_TOKEN" \
74+ -H "Content-Type: application/octet-stream" \
75+ --data-binary @"$file" \
76+ "${{ steps.create_release.outputs.upload_url }}?name=$file"
77+ echo "Uploaded $file"
78+ done
79+
80+ - name : Verify upload
81+ run : |
82+ echo "Uploaded files: $FILES"
0 commit comments