-
Notifications
You must be signed in to change notification settings - Fork 195
343 lines (309 loc) · 12.8 KB
/
Copy pathrelease.yml
File metadata and controls
343 lines (309 loc) · 12.8 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
name: Release
on:
push:
tags:
- v*.*.*
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x64
os: ubuntu-latest
arch: x64
- name: linux-arm64
os: ubuntu-24.04-arm
arch: arm64
- name: mac-x64
os: macos-latest
arch: x64
- name: mac-arm64
os: macos-latest
arch: arm64
- name: win-x64
os: windows-latest
arch: x64
- name: win-arm64
os: windows-11-arm
arch: arm64
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Git clone repo
if: runner.os == 'Linux' || runner.os == 'macOS'
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_PASS: ${{ secrets.GIT_PASS }}
GIT_REPO_BASE: ${{ secrets.GIT_REPO_BASE }}
GIT_HOST: ${{ secrets.GIT_HOST }}
run: |
git clone -b main "https://${GIT_USER}:${GIT_PASS}@${GIT_HOST}/${GIT_REPO_BASE}/linkandroid-pro.git" code
- name: Git clone repo
if: runner.os == 'Windows'
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_PASS: ${{ secrets.GIT_PASS }}
GIT_REPO_BASE: ${{ secrets.GIT_REPO_BASE }}
GIT_HOST: ${{ secrets.GIT_HOST }}
shell: pwsh
run: |
git clone -b main "https://${env:GIT_USER}:${env:GIT_PASS}@${env:GIT_HOST}/${env:GIT_REPO_BASE}/linkandroid-pro.git" code
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Build Prepare (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config
- name: Build Prepare (macOS)
if: runner.os == 'macOS'
run: |
brew install python-setuptools
- name: Install fpm (Linux arm64)
if: runner.os == 'Linux' && runner.arch == 'ARM64'
run: |
sudo apt-get install -y ruby ruby-dev rubygems
sudo gem install fpm
# Replace cached x86 fpm with symlink to native arm64 system fpm
# (electron-builder always uses cached fpm, so we override it)
FPM_PATH=$(which fpm)
echo "System fpm: $FPM_PATH"
CACHE_DIR="$HOME/.cache/electron-builder/fpm/fpm-1.9.3-2.3.1-linux-x86"
rm -rf "$CACHE_DIR"
mkdir -p "$CACHE_DIR"
ln -sf "$FPM_PATH" "$CACHE_DIR/fpm"
- name: Cert Prepare (macOS)
if: runner.os == 'macOS'
env:
MACOS_CERTIFICATE: ${{ secrets.CORP_MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.CORP_MACOS_CERTIFICATE_PASSWORD }}
run: |
echo "find-identity"
security find-identity -p codesigning
echo "$MACOS_CERTIFICATE" | base64 --decode > certificate.p12
security create-keychain -p "" build.keychain
security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
security list-keychains -s build.keychain
security default-keychain -s build.keychain
security set-keychain-settings -t 3600 -u build.keychain
security unlock-keychain -p "" build.keychain
echo "find-identity"
security find-identity -v -p codesigning build.keychain
echo "find-identity"
security find-identity -p codesigning
echo "set-key-partition-list"
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "" -t private build.keychain
echo "export"
security export -k build.keychain -t certs -f x509 -p -o certificate.cer
echo "add-trusted-cert"
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain certificate.cer
echo "find-identity"
security find-identity -p codesigning
- name: Install Dependencies (Linux/macOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
working-directory: code
run: npm install
- name: Configure Windows build environment
if: runner.os == 'Windows'
shell: pwsh
run: |
"GYP_MSVS_VERSION=2022" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"npm_config_msvs_version=2022" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install Visual Studio Build Tools
if: runner.os == 'Windows'
shell: pwsh
run: |
$params = @(
"--add", "Microsoft.VisualStudio.Workload.VCTools",
"--includeRecommended"
)
if ($env:RUNNER_ARCH -eq 'ARM64') {
$params += @(
"--add", "Microsoft.VisualStudio.Component.VC.ARM64",
"--add", "Microsoft.VisualStudio.Component.VC.Tools.ARM64"
)
}
choco install visualstudio2022buildtools --params ($params -join ' ') -y
- name: Install Dependencies (Windows)
if: runner.os == 'Windows'
working-directory: code
shell: pwsh
run: npm install
- name: Build Release Files
working-directory: code
run: npm run build
env:
DEBUG: "electron-notarize:*"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_ARCH: ${{ matrix.arch == 'x64' && 'x64' || '' }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
- name: Set Build Name ( Linux / macOS )
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
DIST_FILE_NAME=${{ runner.os }}-${{ runner.arch }}-v$(date +%Y%m%d_%H%M%S)-${RANDOM}
echo ::add-mask::$DIST_FILE_NAME
echo DIST_FILE_NAME=$DIST_FILE_NAME >> $GITHUB_ENV
- name: Set Build Name ( Windows )
if: runner.os == 'Windows'
shell: pwsh
run: |
$arch = "${{ runner.arch }}"
$randomNumber = Get-Random -Minimum 10000 -Maximum 99999
$DIST_FILE_NAME = "Windows-$arch-v$(Get-Date -Format 'yyyyMMdd_HHmmss')-$randomNumber"
Write-Host "::add-mask::$DIST_FILE_NAME"
echo "DIST_FILE_NAME=$DIST_FILE_NAME" >> $env:GITHUB_ENV
- name: Upload Artifact (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
name: linkandroid-win-${{ matrix.arch }}
path: code/dist-release/*.exe
- name: Upload Artifact (macOS)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v4
with:
name: linkandroid-mac-${{ matrix.arch }}
path: code/dist-release/*.dmg
- name: Upload Artifact (Linux)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: linkandroid-linux-${{ matrix.arch }}
path: |
code/dist-release/*.AppImage
code/dist-release/*.deb
- name: Upload to OSS
id: oss-upload
uses: modstart/github-oss-action@master
with:
title: ${{ github.ref_name }}
key-id: ${{ secrets.OSS_2_KEY_ID }}
key-secret: ${{ secrets.OSS_2_KEY_SECRET }}
region: ${{ secrets.OSS_2_REGION }}
bucket: ${{ secrets.OSS_2_BUCKET }}
callbackTitle: 🎉LinkAndroid-${{ runner.os }}-Release-${{ github.ref_name }}
callback: ${{ secrets.REPORT_URL_ME }}
assets: |
code/dist-release/*.exe:apps/{random}.bin:{name}.exe
code/dist-release/*.dmg:apps/{random}.bin:{name}.dmg
code/dist-release/*.AppImage:apps/{random}.bin:{name}.AppImage
code/dist-release/*.deb:apps/{random}.bin:{name}.deb
- name: Save OSS Downloads for Notify
shell: bash
env:
OSS_DOWNLOADS: ${{ steps.oss-upload.outputs.downloads }}
run: |
if [ -n "${OSS_DOWNLOADS}" ]; then
# No echo of the value needed; output is masked by core.setSecret
echo "${OSS_DOWNLOADS}" > "oss-downloads-${{ matrix.name }}.json"
else
echo "{}" > "oss-downloads-${{ matrix.name }}.json"
fi
- name: Upload OSS Downloads Artifact
uses: actions/upload-artifact@v4
with:
name: oss-downloads-${{ matrix.name }}
path: oss-downloads-${{ matrix.name }}.json
# ── Release ────────────────────────────────────────────────────────────────────
release:
name: Create Release
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
pattern: linkandroid-*
path: _artifacts
merge-multiple: false
- name: Create Release and Upload Assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG=${GITHUB_REF#refs/tags/}
# Delete any existing release for this tag (handles force-push)
gh release delete "$TAG" --yes 2>/dev/null || true
# Create release (draft, idempotent)
gh release create "$TAG" \
--title "$TAG" \
--draft \
--prerelease=false \
--notes "" \
2>/dev/null || true
# Upload all artifacts (with pre-release tag stripped from version)
FULL_VERSION=$(node -p "require('./package.json').version")
CLEAN_VERSION=$(node -p "require('./package.json').version.replace(/-[a-zA-Z][a-zA-Z0-9.]*$/, '')")
find _artifacts/ -type f | while read f; do
base=$(basename "$f")
clean=$(echo "$base" | sed "s/$FULL_VERSION/$CLEAN_VERSION/")
echo "Uploading: $clean"
gh release upload "$TAG" "$f" --clobber
done
# ── Notify ────────────────────────────────────────────────────────────────────
notify:
name: Notify
needs: [release]
if: success()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Download OSS Downloads Artifacts
uses: actions/download-artifact@v4
with:
pattern: oss-downloads-*
path: _oss-downloads
merge-multiple: true
- name: Notify Webhook
run: |
# Merge all OSS download maps into a single JSON string
MERGED="{}"
for f in _oss-downloads/*.json; do
[ -f "$f" ] || continue
content=$(cat "$f")
[ -z "$content" ] && content="{}"
MERGED=$(node -e "
const a = JSON.parse(process.argv[1]);
const b = JSON.parse(process.argv[2]);
console.log(JSON.stringify(Object.assign(a, b)));
" "$MERGED" "$content")
done
echo "::add-mask::${MERGED}"
NAME="${{ github.event.repository.name }}"
TYPE=$(echo "${{ github.workflow }}" | tr '[:upper:]' '[:lower:]')
VERSION=$(node -p "require('./package.json').version")
PAYLOAD=$(node -e "
const p = {
event: process.argv[1],
param: { name: process.argv[1], type: process.argv[2], version: process.argv[3] },
data: { name: process.argv[1], type: process.argv[2], version: process.argv[3], downloads: process.argv[4] }
};
console.log(JSON.stringify(p));
" "$NAME" "$TYPE" "$VERSION" "$MERGED")
echo "::add-mask::${PAYLOAD}"
curl -X POST "${{ secrets.HOOK_URL }}" \
-H "Content-Type: application/json" \
-d "${PAYLOAD}"
- name: Clean up OSS Downloads Artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Deleting oss-downloads-* artifacts for run ${{ github.run_id }}..."
gh api "/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" \
--jq '.artifacts[] | select(.name | startswith("oss-downloads-")) | .id' \
| while read id; do
echo " deleting artifact id=$id"
gh api "/repos/${{ github.repository }}/actions/artifacts/$id" -X DELETE
done
echo "Cleanup done."