Skip to content

Commit 7f47169

Browse files
committed
ci(deploy): add workflow for CDN deployment
1 parent 69efc94 commit 7f47169

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

.github/workflows/deploy-cdn.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Deploy to CDN
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }}
8+
HUAWEI_CLOUD_SK: ${{ secrets.HUAWEI_CLOUD_SK }}
9+
HUAWEI_CLOUD_ENDPOINT: ${{ secrets.HUAWEI_CLOUD_ENDPOINT }}
10+
HUAWEI_CLOUD_BUCKET: ${{ secrets.HUAWEI_CLOUD_BUCKET }}
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
version-timestamp: ${{ steps.prepare-version.outputs.version_timestamp }}
17+
cdn-base: ${{ steps.prepare-version.outputs.cdn_base }}
18+
obs-path: ${{ steps.prepare-version.outputs.obs_path }}
19+
concurrency:
20+
group: deploy-cdn
21+
cancel-in-progress: true
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Install pnpm
27+
uses: pnpm/action-setup@v4
28+
with:
29+
version: 10
30+
run_install: false
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '20'
36+
registry-url: 'https://registry.npmjs.org'
37+
38+
- name: Install dependencies
39+
run: pnpm install
40+
41+
- name: add environment variable
42+
run: |
43+
VITE_ORIGIN_URL="https://agent.opentiny.design/"
44+
cat <<EOF >> designer-demo/env/.env.alpha
45+
# ---- appended by CI (deploy-cdn) ----
46+
VITE_ORIGIN=$VITE_ORIGIN_URL
47+
EOF
48+
echo "VITE_ORIGIN_URL=$VITE_ORIGIN_URL"
49+
50+
- id: prepare-version
51+
name: Prepare version-timestamp
52+
run: |
53+
# Extract version from package.json
54+
VERSION=$(node -p "require('./designer-demo/package.json').version")
55+
56+
# Generate timestamp in YYYYMMDD-HHMMSS format
57+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
58+
59+
# Combine for version-timestamp
60+
VERSION_TIMESTAMP="${VERSION}-${TIMESTAMP}"
61+
62+
# Set CDN base path
63+
CDN_BASE="https://res-static.opentiny.design/tiny-engine-designer/${VERSION_TIMESTAMP}/"
64+
OBS_PATH="tiny-engine-designer/${VERSION_TIMESTAMP}/"
65+
66+
# Export as environment variables for subsequent steps
67+
echo "VERSION_TIMESTAMP=$VERSION_TIMESTAMP" >> $GITHUB_ENV
68+
echo "CDN_BASE=$CDN_BASE" >> $GITHUB_ENV
69+
echo "OBS_PATH=$OBS_PATH" >> $GITHUB_ENV
70+
71+
# Set outputs for job-level export
72+
echo "version_timestamp=$VERSION_TIMESTAMP" >> $GITHUB_OUTPUT
73+
echo "cdn_base=$CDN_BASE" >> $GITHUB_OUTPUT
74+
echo "obs_path=$OBS_PATH" >> $GITHUB_OUTPUT
75+
76+
echo "Version-Timestamp: $VERSION_TIMESTAMP"
77+
echo "CDN Base: $CDN_BASE"
78+
echo "OBS Path: $OBS_PATH"
79+
80+
- name: Run Build
81+
run: |
82+
set -eo pipefail
83+
pnpm run build:plugin 2>&1 | tee /tmp/build-plugin.log
84+
# Run build:alpha equivalent with --base parameter
85+
pnpm --filter designer-demo build:alpha -- --base=${{ env.CDN_BASE }} 2>&1 | tee /tmp/build-alpha.log
86+
87+
- name: Upload build artifacts
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: designer-demo-dist
91+
path: ./designer-demo/dist/
92+
retention-days: 1
93+
94+
deploy-cdn:
95+
runs-on: ubuntu-latest
96+
needs: build
97+
if: |
98+
secrets.HUAWEI_CLOUD_AK != '' &&
99+
secrets.HUAWEI_CLOUD_SK != '' &&
100+
secrets.HUAWEI_CLOUD_ENDPOINT != '' &&
101+
secrets.HUAWEI_CLOUD_BUCKET != ''
102+
steps:
103+
- name: Checkout
104+
uses: actions/checkout@v4
105+
106+
- name: Download build artifacts
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: designer-demo-dist
110+
path: ./designer-demo/dist/
111+
112+
- name: Install obsutil
113+
run: |
114+
curl -o obsutil.tar.gz https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_amd64.tar.gz
115+
tar -xzf obsutil.tar.gz
116+
chmod +x obsutil_linux_amd64_*/obsutil
117+
sudo mv obsutil_linux_amd64_*/obsutil /usr/local/bin/obsutil
118+
119+
- name: Configure and Upload to OBS
120+
run: |
121+
obsutil config -i=${{ env.HUAWEI_CLOUD_AK }} \
122+
-k=${{ env.HUAWEI_CLOUD_SK }} \
123+
-e=${{ env.HUAWEI_CLOUD_ENDPOINT }}
124+
# Upload to versioned path
125+
obsutil cp ./designer-demo/dist \
126+
obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }} \
127+
-r -f
128+
129+
echo "Uploaded to: obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }}"
130+
echo "CDN URL: https://res-static.opentiny.design/${{ needs.build.outputs.obs-path }}"

0 commit comments

Comments
 (0)