-
Notifications
You must be signed in to change notification settings - Fork 271
359 lines (306 loc) · 13.5 KB
/
Copy pathrelease.yml
File metadata and controls
359 lines (306 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
name: Build/release
on:
push:
tags:
- 'v*'
jobs:
build_artifacts:
name: Build ${{ matrix.os }} ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
env:
ELECTRON_BUILDER_HTTP_TIMEOUT: 6000000
ELECTRON_MIRROR: 'https://npmmirror.com/mirrors/electron/'
strategy:
fail-fast: false
matrix:
include:
# macOS ARM64
- os: macos-latest
arch: arm64
os_build_arg: mac
addon_name: addon-macos-arm64.node
build_args: '--arm64'
artifact_suffix: macos-arm64
# macOS Intel
- os: macos-15-intel
arch: x64
os_build_arg: mac
addon_name: addon-macos-x64.node
build_args: '--x64'
artifact_suffix: macos-x64
# Windows x64 (通用版本,不包含 CUDA)
- os: windows-2022
arch: x64
os_build_arg: win
addon_name: addon-windows-x64.node
artifact_suffix: windows-x64
# Linux x64 (通用版本,不包含 CUDA)
- os: ubuntu-22.04
arch: x64
os_build_arg: linux
addon_name: addon-linux-x64.node
artifact_suffix: linux-x64
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node@v4
with:
node-version: 20.14.0
- name: Download addon
shell: bash
run: |
mkdir -p temp-artifacts
# 下载主 addon 文件
curl -L -o "temp-artifacts/${{ matrix.addon_name }}" \
"https://github.com/buxuku/whisper.cpp/releases/download/latest/${{ matrix.addon_name }}"
# macOS ARM64 需要额外下载 CoreML 版本
if [[ "${{ matrix.os_build_arg }}" == "mac" && "${{ matrix.arch }}" == "arm64" ]]; then
curl -L -o "temp-artifacts/addon-macos-arm64-coreml.node" \
"https://github.com/buxuku/whisper.cpp/releases/download/latest/addon-macos-arm64-coreml.node"
fi
- name: Prepare macOS addon
if: matrix.os_build_arg == 'mac'
env:
BUILD_PLATFORM: 'darwin'
BUILD_ARCH: '${{ matrix.arch }}'
run: |
cp temp-artifacts/${{ matrix.addon_name }} extraResources/addons/addon.node
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
cp temp-artifacts/addon-macos-arm64-coreml.node extraResources/addons/addon.coreml.node
fi
node scripts/inject-build-info.js
- name: Prepare Windows addon
if: matrix.os_build_arg == 'win'
env:
BUILD_PLATFORM: 'win32'
BUILD_ARCH: '${{ matrix.arch }}'
run: |
Copy-Item -Path "temp-artifacts/${{ matrix.addon_name }}" -Destination "extraResources/addons/addon.node"
node scripts/inject-build-info.js
- name: Prepare Linux addon
if: matrix.os_build_arg == 'linux'
env:
BUILD_PLATFORM: 'linux'
BUILD_ARCH: '${{ matrix.arch }}'
run: |
cp temp-artifacts/${{ matrix.addon_name }} extraResources/addons/addon.node
node scripts/inject-build-info.js
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Compile application code
run: yarn build # Assumes 'yarn build' compiles TS to JS, e.g., into the 'app' directory
- name: Build Electron app
shell: bash
run: |
if [[ "${{ matrix.os_build_arg }}" == "mac" ]]; then
export BUILD_PLATFORM="darwin"
elif [[ "${{ matrix.os_build_arg }}" == "win" ]]; then
export BUILD_PLATFORM="win32"
else
export BUILD_PLATFORM="linux"
fi
export BUILD_ARCH=${{ matrix.arch }}
yarn run electron-builder --${{ matrix.os_build_arg }} --${{ matrix.arch }} ${{ matrix.build_args || '' }} --publish never
- name: Stage Artifacts
shell: bash
run: |
mkdir staging
cp dist/*.{dmg,exe,AppImage,zip,tar.gz,deb,snap} staging/ 2>/dev/null || true # Copy main packages
cp dist/*latest*.yml staging/ 2>/dev/null || true # Copy generated YML
ls -R staging # List files for debugging
- name: Upload application package artifact
uses: actions/upload-artifact@v4
with:
name: app-pkg-${{ matrix.artifact_suffix }}
path: |
staging/*.dmg
staging/*.exe
staging/*.AppImage
staging/*.zip
staging/*.tar.gz
staging/*.deb
staging/*.snap
if-no-files-found: error # Important: fail if no package found
- name: Upload update YAML artifact
uses: actions/upload-artifact@v4
with:
name: update-yaml-${{ matrix.artifact_suffix }}
path: staging/*latest*.yml
if-no-files-found: error # Important: fail if no YML found
publish_release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs: build_artifacts
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write # Required for softprops/action-gh-release
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x # Or your preferred Node version for the script
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
path: all_build_artifacts # This will download each artifact into its own subdirectory
- name: List downloaded artifacts for debugging
run: ls -R all_build_artifacts
- name: Create YAML merge script
run: |
cat <<'EOF' > merge-yaml-and-prepare-release.js
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const artifactsDownloadDir = path.join('.', 'all_build_artifacts');
const finalReleaseAssetsDir = path.join('.', 'final_release_assets');
fs.mkdirSync(finalReleaseAssetsDir, { recursive: true });
const platformYamlData = { mac: [], windows: [], linux: [] };
let packageVersion = process.env.GITHUB_REF_NAME.startsWith('v') ? process.env.GITHUB_REF_NAME.substring(1) : process.env.GITHUB_REF_NAME;
fs.readdirSync(artifactsDownloadDir).forEach(artifactSubDir => {
const artifactPath = path.join(artifactsDownloadDir, artifactSubDir);
fs.readdirSync(artifactPath).forEach(file => {
const filePath = path.join(artifactPath, file);
if (file.endsWith('.yml')) {
console.log(`Processing YAML: ${filePath} from ${artifactSubDir}`);
try {
const ymlContent = yaml.load(fs.readFileSync(filePath, 'utf8'));
if (!packageVersion && ymlContent.version) packageVersion = ymlContent.version; // Fallback if GITHUB_REF_NAME is not a version tag
let platformKey = '';
if (artifactSubDir.includes('-macos-') || file.includes('-mac')) platformKey = 'mac';
else if (artifactSubDir.includes('-windows-') || file.includes('-windows') || file.includes('-win')) platformKey = 'windows';
else if (artifactSubDir.includes('-linux-') || file.includes('-linux')) platformKey = 'linux';
if (platformKey && ymlContent.files && Array.isArray(ymlContent.files)) {
ymlContent.files.forEach(fileEntry => {
// Ensure the URL is just the filename for the release asset
fileEntry.url = path.basename(fileEntry.url);
platformYamlData[platformKey].push(fileEntry);
});
} else {
console.warn(`Could not determine platform or parse files for ${filePath}`);
}
} catch (e) {
console.error(`Error processing YAML file ${filePath}:`, e);
}
} else {
console.log(`Copying package: ${file} to ${finalReleaseAssetsDir}`);
fs.copyFileSync(filePath, path.join(finalReleaseAssetsDir, file));
}
});
});
const releaseDate = new Date().toISOString();
for (const platform of ['mac', 'windows', 'linux']) {
if (platformYamlData[platform].length > 0) {
// Sort files to ensure deterministic order, e.g., by URL
platformYamlData[platform].sort((a, b) => a.url.localeCompare(b.url));
let outputFileName = `latest-${platform}.yml`;
if (platform === 'windows') {
outputFileName = 'latest.yml';
}
const finalYaml = {
version: packageVersion,
files: platformYamlData[platform],
path: outputFileName, // Use the determined output file name
releaseDate: releaseDate,
};
const yamlPath = path.join(finalReleaseAssetsDir, outputFileName);
fs.writeFileSync(yamlPath, yaml.dump(finalYaml));
console.log(`Generated ${yamlPath} for ${platform} with ${finalYaml.files.length} entries.`);
}
}
console.log('Final release assets prepared in:', finalReleaseAssetsDir);
EOF
- name: Install script dependencies
run: npm install js-yaml
- name: Run YAML merge script
run: node merge-yaml-and-prepare-release.js
env:
GITHUB_REF_NAME: ${{ github.ref_name }} # Pass tag to script
- name: List final assets for debugging
run: ls -R final_release_assets
- name: Check if beta release
id: check_beta
run: |
if [[ "${{ github.ref_name }}" == *"beta"* ]]; then
echo "is_beta=true" >> $GITHUB_OUTPUT
else
echo "is_beta=false" >> $GITHUB_OUTPUT
fi
- name: Publish Release
uses: softprops/action-gh-release@v2 # Updated to a newer version
with:
# token: ${{ secrets.GITHUB_TOKEN }} # Provided by default
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
# body: | # Optional: Add release notes here
# Automated release for version ${{ github.ref_name }}
draft: ${{ steps.check_beta.outputs.is_beta == 'true' }}
prerelease: ${{ steps.check_beta.outputs.is_beta == 'true' }}
files: |
final_release_assets/*
update_homebrew_tap:
name: Update Homebrew Tap
runs-on: ubuntu-latest
needs: publish_release
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref_name, 'beta')
steps:
- name: Extract version from tag
id: version
run: |
VERSION="${GITHUB_REF_NAME#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Download macOS DMG files and calculate SHA256
id: sha256
run: |
VERSION="${{ steps.version.outputs.version }}"
# Download ARM64 DMG
echo "Downloading ARM64 DMG..."
curl -L -o "SmartSub_Mac_${VERSION}_arm64.dmg" \
"https://github.com/buxuku/SmartSub/releases/download/v${VERSION}/SmartSub_Mac_${VERSION}_arm64.dmg"
# Download x64 DMG
echo "Downloading x64 DMG..."
curl -L -o "SmartSub_Mac_${VERSION}_x64.dmg" \
"https://github.com/buxuku/SmartSub/releases/download/v${VERSION}/SmartSub_Mac_${VERSION}_x64.dmg"
# Calculate SHA256
SHA256_ARM64=$(shasum -a 256 "SmartSub_Mac_${VERSION}_arm64.dmg" | awk '{print $1}')
SHA256_X64=$(shasum -a 256 "SmartSub_Mac_${VERSION}_x64.dmg" | awk '{print $1}')
echo "SHA256 ARM64: $SHA256_ARM64"
echo "SHA256 x64: $SHA256_X64"
echo "sha256_arm64=$SHA256_ARM64" >> $GITHUB_OUTPUT
echo "sha256_x64=$SHA256_X64" >> $GITHUB_OUTPUT
- name: Checkout Homebrew Tap
uses: actions/checkout@v4
with:
repository: buxuku/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- name: Update Cask file
run: |
VERSION="${{ steps.version.outputs.version }}"
SHA256_ARM64="${{ steps.sha256.outputs.sha256_arm64 }}"
SHA256_X64="${{ steps.sha256.outputs.sha256_x64 }}"
CASK_FILE="homebrew-tap/Casks/smartsub.rb"
# Update version
sed -i "s/version \".*\"/version \"${VERSION}\"/" "$CASK_FILE"
# Update SHA256 for Intel (x64) - appears first in on_intel block
sed -i "/on_intel do/,/end/ s/sha256 \"[a-f0-9]*\"/sha256 \"${SHA256_X64}\"/" "$CASK_FILE"
# Update SHA256 for ARM - appears in on_arm block
sed -i "/on_arm do/,/end/ s/sha256 \"[a-f0-9]*\"/sha256 \"${SHA256_ARM64}\"/" "$CASK_FILE"
echo "Updated Cask file:"
cat "$CASK_FILE"
- name: Commit and Push changes
run: |
cd homebrew-tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Casks/smartsub.rb
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Update smartsub to ${{ steps.version.outputs.version }}"
git push
echo "Successfully updated homebrew-tap"
fi