Skip to content

Commit 45c0894

Browse files
committed
ci(deploy): enhance CDN deployment with latest release option
1 parent 6304554 commit 45c0894

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

.github/workflows/deploy-cdn.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Deploy to CDN
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
is_latest_release:
7+
description: '当前分支是否是最新release版本'
8+
required: true
9+
default: true
10+
type: boolean
511

612
env:
713
HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }}
@@ -36,7 +42,9 @@ jobs:
3642
outputs:
3743
version-timestamp: ${{ steps.prepare-version.outputs.version_timestamp }}
3844
cdn-base: ${{ steps.prepare-version.outputs.cdn_base }}
45+
cdn-base-latest: ${{ steps.prepare-version.outputs.cdn_base_latest }}
3946
obs-path: ${{ steps.prepare-version.outputs.obs_path }}
47+
obs-path-latest: ${{ steps.prepare-version.outputs.obs_path_latest }}
4048
concurrency:
4149
group: deploy-cdn
4250
cancel-in-progress: true
@@ -75,14 +83,16 @@ jobs:
7583
VERSION=$(node -p "require('./designer-demo/package.json').version")
7684
7785
# Generate timestamp in YYYYMMDD-HHMMSS format
78-
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
86+
TIMESTAMP=$(TZ="Asia/Shanghai" date +%Y%m%d-%H%M%S)
7987
8088
# Combine for version-timestamp
8189
VERSION_TIMESTAMP="${VERSION}-${TIMESTAMP}"
8290
8391
# Set CDN base path
8492
CDN_BASE="https://res-static.opentiny.design/tiny-engine-designer/${VERSION_TIMESTAMP}/"
93+
CDN_BASE_LATEST="https://res-static.opentiny.design/tiny-engine-designer/latest/"
8594
OBS_PATH="tiny-engine-designer/${VERSION_TIMESTAMP}/"
95+
OBS_PATH_LATEST="tiny-engine-designer/latest"
8696
8797
# Export as environment variables for subsequent steps
8898
echo "VERSION_TIMESTAMP=$VERSION_TIMESTAMP" >> $GITHUB_ENV
@@ -92,7 +102,9 @@ jobs:
92102
# Set outputs for job-level export
93103
echo "version_timestamp=$VERSION_TIMESTAMP" >> $GITHUB_OUTPUT
94104
echo "cdn_base=$CDN_BASE" >> $GITHUB_OUTPUT
105+
echo "cdn_base_latest=$CDN_BASE_LATEST" >> $GITHUB_OUTPUT
95106
echo "obs_path=$OBS_PATH" >> $GITHUB_OUTPUT
107+
echo "obs_path_latest=$OBS_PATH_LATEST" >> $GITHUB_OUTPUT
96108
97109
echo "Version-Timestamp: $VERSION_TIMESTAMP"
98110
echo "CDN Base: $CDN_BASE"
@@ -140,7 +152,17 @@ jobs:
140152
# Upload to versioned path
141153
obsutil cp ./designer-demo/dist \
142154
obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }} \
143-
-r -f
155+
-r -f -flat
156+
157+
# If is_latest_release is true, also upload to latest path
158+
if [ "${{ github.event.inputs.is_latest_release }}" = "true" ]; then
159+
# use cdn-base-latest replace cdn-base in all ./designer-demo/dist files
160+
find ./designer-demo/dist -type f \( -name "*.html" -o -name "*.js" -o -name "*.mjs" -o -name "*.css" \) \
161+
-exec sed -i "s|${{ needs.build.outputs.cdn-base }}|${{ needs.build.outputs.cdn-base-latest }}|g" {} +
162+
obsutil cp ./designer-demo/dist \
163+
obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path-latest }} \
164+
-r -f -flat
165+
fi
144166
145167
echo "Uploaded to: obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }}"
146168
echo "CDN URL: https://res-static.opentiny.design/${{ needs.build.outputs.obs-path }}"

0 commit comments

Comments
 (0)