Skip to content

Commit cdc8ad2

Browse files
4pmtongWendong-Fan
andauthored
enhance upload to s3 (#1111)
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent 8694116 commit cdc8ad2

2 files changed

Lines changed: 301 additions & 10 deletions

File tree

.github/workflows/build-view.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,99 @@ jobs:
230230
else
231231
find temp-linux-x64 -name "*.AppImage" -exec mv {} release/linux-x64/ \; || true
232232
fi
233+
234+
# Extract version for test builds
235+
- name: Extract version
236+
id: version
237+
run: |
238+
# Create a version using timestamp for test builds
239+
VERSION="test-$(date +%Y%m%d-%H%M%S)"
240+
echo "version=$VERSION" >> $GITHUB_OUTPUT
241+
echo "Extracted version for test build: $VERSION"
242+
243+
# Configure AWS credentials (skipped when AWS secrets are not configured)
244+
- name: Configure AWS credentials
245+
id: aws-check
246+
if: env.AWS_ACCESS_KEY_ID != ''
247+
env:
248+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
249+
uses: aws-actions/configure-aws-credentials@v4
250+
with:
251+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
252+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
253+
aws-region: ${{ secrets.AWS_REGION }}
254+
255+
# Upload to S3 - test directory
256+
- name: Upload to S3 (test build)
257+
if: steps.aws-check.outcome == 'success'
258+
run: |
259+
VERSION="${{ steps.version.outputs.version }}"
260+
BUCKET="${{ secrets.AWS_S3_BUCKET }}"
261+
262+
echo "Uploading test build $VERSION to S3 bucket: $BUCKET"
263+
264+
declare -a targets=(
265+
"release/mac-arm64 mac-arm64"
266+
"release/mac-intel mac-intel"
267+
"release/win-x64 win-x64"
268+
"release/linux-x64 linux-x64"
269+
)
270+
for t in "${targets[@]}"; do
271+
src_dir="${t%% *}"
272+
path_suffix="${t##* }"
273+
if [ -d "$src_dir" ] && [ "$(ls -A "$src_dir")" ]; then
274+
echo "Uploading $path_suffix files..."
275+
aws s3 sync "$src_dir/" "s3://$BUCKET/test-builds/$VERSION/$path_suffix/" \
276+
--content-type "binary/octet-stream" \
277+
--metadata-directive REPLACE \
278+
--cache-control "public, max-age=300"
279+
fi
280+
done
281+
282+
echo "Test build $VERSION uploaded successfully"
283+
284+
# Generate download URLs
285+
- name: Generate download URLs
286+
if: steps.aws-check.outcome == 'success'
287+
run: |
288+
VERSION="${{ steps.version.outputs.version }}"
289+
BUCKET="${{ secrets.AWS_S3_BUCKET }}"
290+
REGION="${{ secrets.AWS_REGION }}"
291+
292+
# Determine S3 endpoint based on region
293+
if [[ "$REGION" == cn-* ]]; then
294+
ENDPOINT="s3.$REGION.amazonaws.com.cn"
295+
else
296+
ENDPOINT="s3.$REGION.amazonaws.com"
297+
fi
298+
299+
echo "================================"
300+
echo "Test Build Download URLs"
301+
echo "Build ID: $VERSION"
302+
echo "================================"
303+
echo ""
304+
305+
# Check which platforms exist and show URLs
306+
if [ -d "release/mac-arm64" ] && [ "$(ls -A release/mac-arm64)" ]; then
307+
echo "macOS (ARM64): https://$BUCKET.$ENDPOINT/test-builds/$VERSION/mac-arm64/"
308+
fi
309+
310+
if [ -d "release/mac-intel" ] && [ "$(ls -A release/mac-intel)" ]; then
311+
echo "macOS (Intel): https://$BUCKET.$ENDPOINT/test-builds/$VERSION/mac-intel/"
312+
fi
313+
314+
if [ -d "release/win-x64" ] && [ "$(ls -A release/win-x64)" ]; then
315+
echo "Windows (x64): https://$BUCKET.$ENDPOINT/test-builds/$VERSION/win-x64/"
316+
fi
317+
318+
if [ -d "release/linux-x64" ] && [ "$(ls -A release/linux-x64)" ]; then
319+
echo "Linux (x64): https://$BUCKET.$ENDPOINT/test-builds/$VERSION/linux-x64/"
320+
fi
321+
322+
echo ""
323+
echo "⚠️ Note: Test builds are stored in 'test-builds/' directory"
324+
echo "⚠️ Remember to delete old test builds to save storage costs"
325+
echo ""
326+
echo "To delete this test build:"
327+
echo "aws s3 rm s3://$BUCKET/test-builds/$VERSION/ --recursive --region $REGION"
328+
echo "================================"

.github/workflows/build.yml

Lines changed: 205 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ name: Build
33
on:
44
push:
55
tags:
6-
- "v*"
6+
- 'v*'
77
paths-ignore:
8-
- "**.md"
9-
- "**.spec.js"
10-
- ".idea"
11-
- ".vscode"
12-
- ".dockerignore"
13-
- "Dockerfile"
14-
- ".gitignore"
15-
- ".github/**"
16-
- "!.github/workflows/build.yml"
8+
- '**.md'
9+
- '**.spec.js'
10+
- '.idea'
11+
- '.vscode'
12+
- '.dockerignore'
13+
- 'Dockerfile'
14+
- '.gitignore'
15+
- '.github/**'
16+
- '!.github/workflows/build.yml'
1717

1818
permissions:
1919
contents: write
@@ -260,3 +260,198 @@ jobs:
260260
release/mac-arm64/*
261261
release/win-x64/*
262262
release/linux-x64/*
263+
264+
# Extract version from tag (e.g., v0.0.82 -> 0.0.82)
265+
- name: Extract version
266+
if: startsWith(github.ref, 'refs/tags/')
267+
id: version
268+
run: |
269+
VERSION=${GITHUB_REF#refs/tags/v}
270+
echo "version=$VERSION" >> $GITHUB_OUTPUT
271+
echo "Extracted version: $VERSION"
272+
273+
# Configure AWS credentials (skipped when AWS secrets not configured)
274+
- name: Configure AWS credentials
275+
id: aws-check
276+
if: env.AWS_ACCESS_KEY_ID != ''
277+
env:
278+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
279+
uses: aws-actions/configure-aws-credentials@v4
280+
with:
281+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
282+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
283+
aws-region: ${{ secrets.AWS_REGION }}
284+
285+
# Upload to S3 - versioned directory (immutable; all files get long cache)
286+
- name: Upload to S3 (versioned)
287+
if: steps.aws-check.outcome == 'success'
288+
run: |
289+
VERSION="${{ steps.version.outputs.version }}"
290+
BUCKET="${{ secrets.AWS_S3_BUCKET }}"
291+
292+
echo "Uploading version $VERSION to S3 bucket: $BUCKET"
293+
294+
declare -a targets=(
295+
"release/mac-arm64 mac-arm64"
296+
"release/mac-intel mac-intel"
297+
"release/win-x64 win-x64"
298+
"release/linux-x64 linux-x64"
299+
)
300+
for t in "${targets[@]}"; do
301+
src_dir="${t%% *}"
302+
path_suffix="${t##* }"
303+
if [ -d "$src_dir" ] && [ "$(ls -A "$src_dir")" ]; then
304+
echo "Uploading $path_suffix files..."
305+
aws s3 sync "$src_dir/" "s3://$BUCKET/releases/v$VERSION/$path_suffix/" \
306+
--content-type "binary/octet-stream" \
307+
--metadata-directive REPLACE \
308+
--cache-control "public, max-age=31536000, immutable"
309+
fi
310+
done
311+
312+
echo "Version $VERSION uploaded successfully"
313+
314+
# Upload to S3 - latest directory
315+
- name: Upload to S3 (latest)
316+
if: steps.aws-check.outcome == 'success'
317+
run: |
318+
BUCKET="${{ secrets.AWS_S3_BUCKET }}"
319+
320+
echo "Uploading latest release to S3 bucket: $BUCKET"
321+
322+
# Upload macOS ARM64 files to latest
323+
if [ -d "release/mac-arm64" ] && [ "$(ls -A release/mac-arm64)" ]; then
324+
echo "Uploading latest macOS ARM64 files..."
325+
aws s3 sync release/mac-arm64/ "s3://$BUCKET/releases/latest/mac-arm64/" \
326+
--delete \
327+
--content-type "binary/octet-stream" \
328+
--metadata-directive REPLACE \
329+
--cache-control "public, max-age=300" \
330+
--exclude "*.yml" \
331+
--exclude "*.blockmap"
332+
333+
aws s3 sync release/mac-arm64/ "s3://$BUCKET/releases/latest/mac-arm64/" \
334+
--delete \
335+
--exclude "*" \
336+
--include "*.yml" \
337+
--include "*.blockmap" \
338+
--cache-control "public, max-age=300"
339+
fi
340+
341+
# Upload macOS Intel files to latest (if exists)
342+
if [ -d "release/mac-intel" ] && [ "$(ls -A release/mac-intel)" ]; then
343+
echo "Uploading latest macOS Intel files..."
344+
aws s3 sync release/mac-intel/ "s3://$BUCKET/releases/latest/mac-intel/" \
345+
--delete \
346+
--content-type "binary/octet-stream" \
347+
--metadata-directive REPLACE \
348+
--cache-control "public, max-age=300" \
349+
--exclude "*.yml" \
350+
--exclude "*.blockmap"
351+
352+
aws s3 sync release/mac-intel/ "s3://$BUCKET/releases/latest/mac-intel/" \
353+
--delete \
354+
--exclude "*" \
355+
--include "*.yml" \
356+
--include "*.blockmap" \
357+
--cache-control "public, max-age=300"
358+
fi
359+
360+
# Upload Windows files to latest
361+
if [ -d "release/win-x64" ] && [ "$(ls -A release/win-x64)" ]; then
362+
echo "Uploading latest Windows files..."
363+
aws s3 sync release/win-x64/ "s3://$BUCKET/releases/latest/win-x64/" \
364+
--delete \
365+
--content-type "binary/octet-stream" \
366+
--metadata-directive REPLACE \
367+
--cache-control "public, max-age=300" \
368+
--exclude "*.yml" \
369+
--exclude "*.blockmap"
370+
371+
aws s3 sync release/win-x64/ "s3://$BUCKET/releases/latest/win-x64/" \
372+
--delete \
373+
--exclude "*" \
374+
--include "*.yml" \
375+
--include "*.blockmap" \
376+
--cache-control "public, max-age=300"
377+
fi
378+
379+
# Upload Linux files to latest
380+
if [ -d "release/linux-x64" ] && [ "$(ls -A release/linux-x64)" ]; then
381+
echo "Uploading latest Linux files..."
382+
aws s3 sync release/linux-x64/ "s3://$BUCKET/releases/latest/linux-x64/" \
383+
--delete \
384+
--content-type "binary/octet-stream" \
385+
--metadata-directive REPLACE \
386+
--cache-control "public, max-age=300" \
387+
--exclude "*.yml" \
388+
--exclude "*.blockmap"
389+
390+
aws s3 sync release/linux-x64/ "s3://$BUCKET/releases/latest/linux-x64/" \
391+
--delete \
392+
--exclude "*" \
393+
--include "*.yml" \
394+
--include "*.blockmap" \
395+
--cache-control "public, max-age=300"
396+
fi
397+
398+
echo "Latest release uploaded successfully"
399+
400+
# Generate download URLs
401+
- name: Generate download URLs
402+
if: steps.aws-check.outcome == 'success'
403+
run: |
404+
VERSION="${{ steps.version.outputs.version }}"
405+
BUCKET="${{ secrets.AWS_S3_BUCKET }}"
406+
REGION="${{ secrets.AWS_REGION }}"
407+
408+
# Determine S3 endpoint based on region
409+
if [[ "$REGION" == cn-* ]]; then
410+
ENDPOINT="s3.$REGION.amazonaws.com.cn"
411+
else
412+
ENDPOINT="s3.$REGION.amazonaws.com"
413+
fi
414+
415+
echo "================================"
416+
echo "Download URLs for version v$VERSION"
417+
echo "================================"
418+
echo ""
419+
echo "Versioned URLs:"
420+
421+
# Check which platforms exist and show URLs
422+
if [ -d "release/mac-arm64" ] && [ "$(ls -A release/mac-arm64)" ]; then
423+
echo "macOS (ARM64): https://$BUCKET.$ENDPOINT/releases/v$VERSION/mac-arm64/"
424+
fi
425+
426+
if [ -d "release/mac-intel" ] && [ "$(ls -A release/mac-intel)" ]; then
427+
echo "macOS (Intel): https://$BUCKET.$ENDPOINT/releases/v$VERSION/mac-intel/"
428+
fi
429+
430+
if [ -d "release/win-x64" ] && [ "$(ls -A release/win-x64)" ]; then
431+
echo "Windows (x64): https://$BUCKET.$ENDPOINT/releases/v$VERSION/win-x64/"
432+
fi
433+
434+
if [ -d "release/linux-x64" ] && [ "$(ls -A release/linux-x64)" ]; then
435+
echo "Linux (x64): https://$BUCKET.$ENDPOINT/releases/v$VERSION/linux-x64/"
436+
fi
437+
438+
echo ""
439+
echo "Latest URLs:"
440+
441+
if [ -d "release/mac-arm64" ] && [ "$(ls -A release/mac-arm64)" ]; then
442+
echo "macOS (ARM64): https://$BUCKET.$ENDPOINT/releases/latest/mac-arm64/"
443+
fi
444+
445+
if [ -d "release/mac-intel" ] && [ "$(ls -A release/mac-intel)" ]; then
446+
echo "macOS (Intel): https://$BUCKET.$ENDPOINT/releases/latest/mac-intel/"
447+
fi
448+
449+
if [ -d "release/win-x64" ] && [ "$(ls -A release/win-x64)" ]; then
450+
echo "Windows (x64): https://$BUCKET.$ENDPOINT/releases/latest/win-x64/"
451+
fi
452+
453+
if [ -d "release/linux-x64" ] && [ "$(ls -A release/linux-x64)" ]; then
454+
echo "Linux (x64): https://$BUCKET.$ENDPOINT/releases/latest/linux-x64/"
455+
fi
456+
457+
echo "================================"

0 commit comments

Comments
 (0)