From 7f47169490de78a05d578286be3906fc24d3e108 Mon Sep 17 00:00:00 2001 From: hexqi Date: Sat, 17 Jan 2026 16:55:42 +0800 Subject: [PATCH 1/4] ci(deploy): add workflow for CDN deployment --- .github/workflows/deploy-cdn.yml | 130 +++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 .github/workflows/deploy-cdn.yml diff --git a/.github/workflows/deploy-cdn.yml b/.github/workflows/deploy-cdn.yml new file mode 100644 index 000000000..53d5c45f0 --- /dev/null +++ b/.github/workflows/deploy-cdn.yml @@ -0,0 +1,130 @@ +name: Deploy to CDN + +on: + workflow_dispatch: + +env: + HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }} + HUAWEI_CLOUD_SK: ${{ secrets.HUAWEI_CLOUD_SK }} + HUAWEI_CLOUD_ENDPOINT: ${{ secrets.HUAWEI_CLOUD_ENDPOINT }} + HUAWEI_CLOUD_BUCKET: ${{ secrets.HUAWEI_CLOUD_BUCKET }} + +jobs: + build: + runs-on: ubuntu-latest + outputs: + version-timestamp: ${{ steps.prepare-version.outputs.version_timestamp }} + cdn-base: ${{ steps.prepare-version.outputs.cdn_base }} + obs-path: ${{ steps.prepare-version.outputs.obs_path }} + concurrency: + group: deploy-cdn + cancel-in-progress: true + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 10 + run_install: false + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: pnpm install + + - name: add environment variable + run: | + VITE_ORIGIN_URL="https://agent.opentiny.design/" + cat <> designer-demo/env/.env.alpha + # ---- appended by CI (deploy-cdn) ---- + VITE_ORIGIN=$VITE_ORIGIN_URL + EOF + echo "VITE_ORIGIN_URL=$VITE_ORIGIN_URL" + + - id: prepare-version + name: Prepare version-timestamp + run: | + # Extract version from package.json + VERSION=$(node -p "require('./designer-demo/package.json').version") + + # Generate timestamp in YYYYMMDD-HHMMSS format + TIMESTAMP=$(date +%Y%m%d-%H%M%S) + + # Combine for version-timestamp + VERSION_TIMESTAMP="${VERSION}-${TIMESTAMP}" + + # Set CDN base path + CDN_BASE="https://res-static.opentiny.design/tiny-engine-designer/${VERSION_TIMESTAMP}/" + OBS_PATH="tiny-engine-designer/${VERSION_TIMESTAMP}/" + + # Export as environment variables for subsequent steps + echo "VERSION_TIMESTAMP=$VERSION_TIMESTAMP" >> $GITHUB_ENV + echo "CDN_BASE=$CDN_BASE" >> $GITHUB_ENV + echo "OBS_PATH=$OBS_PATH" >> $GITHUB_ENV + + # Set outputs for job-level export + echo "version_timestamp=$VERSION_TIMESTAMP" >> $GITHUB_OUTPUT + echo "cdn_base=$CDN_BASE" >> $GITHUB_OUTPUT + echo "obs_path=$OBS_PATH" >> $GITHUB_OUTPUT + + echo "Version-Timestamp: $VERSION_TIMESTAMP" + echo "CDN Base: $CDN_BASE" + echo "OBS Path: $OBS_PATH" + + - name: Run Build + run: | + set -eo pipefail + pnpm run build:plugin 2>&1 | tee /tmp/build-plugin.log + # Run build:alpha equivalent with --base parameter + pnpm --filter designer-demo build:alpha -- --base=${{ env.CDN_BASE }} 2>&1 | tee /tmp/build-alpha.log + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: designer-demo-dist + path: ./designer-demo/dist/ + retention-days: 1 + + deploy-cdn: + runs-on: ubuntu-latest + needs: build + if: | + secrets.HUAWEI_CLOUD_AK != '' && + secrets.HUAWEI_CLOUD_SK != '' && + secrets.HUAWEI_CLOUD_ENDPOINT != '' && + secrets.HUAWEI_CLOUD_BUCKET != '' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: designer-demo-dist + path: ./designer-demo/dist/ + + - name: Install obsutil + run: | + curl -o obsutil.tar.gz https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_amd64.tar.gz + tar -xzf obsutil.tar.gz + chmod +x obsutil_linux_amd64_*/obsutil + sudo mv obsutil_linux_amd64_*/obsutil /usr/local/bin/obsutil + + - name: Configure and Upload to OBS + run: | + obsutil config -i=${{ env.HUAWEI_CLOUD_AK }} \ + -k=${{ env.HUAWEI_CLOUD_SK }} \ + -e=${{ env.HUAWEI_CLOUD_ENDPOINT }} + # Upload to versioned path + obsutil cp ./designer-demo/dist \ + obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }} \ + -r -f + + echo "Uploaded to: obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }}" + echo "CDN URL: https://res-static.opentiny.design/${{ needs.build.outputs.obs-path }}" From 4e55e84f2ab3537486b971a49349765920072ab7 Mon Sep 17 00:00:00 2001 From: hexqi Date: Sat, 17 Jan 2026 17:22:54 +0800 Subject: [PATCH 2/4] ci(deploy): add secret checks for Huawei Cloud deployment --- .github/workflows/deploy-cdn.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-cdn.yml b/.github/workflows/deploy-cdn.yml index 53d5c45f0..9cd608c71 100644 --- a/.github/workflows/deploy-cdn.yml +++ b/.github/workflows/deploy-cdn.yml @@ -10,8 +10,29 @@ env: HUAWEI_CLOUD_BUCKET: ${{ secrets.HUAWEI_CLOUD_BUCKET }} jobs: + check-secrets: + runs-on: ubuntu-latest + outputs: + secrets-ready: ${{ steps.check.outputs.secrets-ready }} + steps: + - name: Check required secrets + id: check + run: | + if [[ -z "${{ secrets.HUAWEI_CLOUD_AK }}" ]] || \ + [[ -z "${{ secrets.HUAWEI_CLOUD_SK }}" ]] || \ + [[ -z "${{ secrets.HUAWEI_CLOUD_ENDPOINT }}" ]] || \ + [[ -z "${{ secrets.HUAWEI_CLOUD_BUCKET }}" ]]; then + echo "secrets-ready=false" >> $GITHUB_OUTPUT + echo "::error::Required Huawei Cloud secrets are not configured." + echo "::error::Please set: HUAWEI_CLOUD_AK, HUAWEI_CLOUD_SK, HUAWEI_CLOUD_ENDPOINT, HUAWEI_CLOUD_BUCKET" + exit 1 + fi + echo "secrets-ready=true" >> $GITHUB_OUTPUT + echo "✅ All required secrets are configured" + build: runs-on: ubuntu-latest + needs: check-secrets outputs: version-timestamp: ${{ steps.prepare-version.outputs.version_timestamp }} cdn-base: ${{ steps.prepare-version.outputs.cdn_base }} @@ -93,12 +114,7 @@ jobs: deploy-cdn: runs-on: ubuntu-latest - needs: build - if: | - secrets.HUAWEI_CLOUD_AK != '' && - secrets.HUAWEI_CLOUD_SK != '' && - secrets.HUAWEI_CLOUD_ENDPOINT != '' && - secrets.HUAWEI_CLOUD_BUCKET != '' + needs: [check-secrets, build] steps: - name: Checkout uses: actions/checkout@v4 From 63045545c7f91e2e0842c2550931f0ba8112550a Mon Sep 17 00:00:00 2001 From: hexqi Date: Sat, 17 Jan 2026 17:34:44 +0800 Subject: [PATCH 3/4] ci(deploy): fix command for building alpha plugin --- .github/workflows/deploy-cdn.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-cdn.yml b/.github/workflows/deploy-cdn.yml index 9cd608c71..8dc42e9e6 100644 --- a/.github/workflows/deploy-cdn.yml +++ b/.github/workflows/deploy-cdn.yml @@ -103,7 +103,7 @@ jobs: set -eo pipefail pnpm run build:plugin 2>&1 | tee /tmp/build-plugin.log # Run build:alpha equivalent with --base parameter - pnpm --filter designer-demo build:alpha -- --base=${{ env.CDN_BASE }} 2>&1 | tee /tmp/build-alpha.log + pnpm run build:alpha --base=${{ env.CDN_BASE }} 2>&1 | tee /tmp/build-alpha.log - name: Upload build artifacts uses: actions/upload-artifact@v4 From a4addc3ac33eeb90b9f9e2ac8579b5a27cb924db Mon Sep 17 00:00:00 2001 From: hexqi Date: Sun, 18 Jan 2026 20:31:17 +0800 Subject: [PATCH 4/4] ci(deploy): enhance CDN deployment with latest release option --- .github/workflows/deploy-cdn.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-cdn.yml b/.github/workflows/deploy-cdn.yml index 8dc42e9e6..98df2d182 100644 --- a/.github/workflows/deploy-cdn.yml +++ b/.github/workflows/deploy-cdn.yml @@ -2,6 +2,12 @@ name: Deploy to CDN on: workflow_dispatch: + inputs: + is_latest_release: + description: '当前分支是否是最新release版本' + required: true + default: true + type: boolean env: HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }} @@ -36,7 +42,9 @@ jobs: outputs: version-timestamp: ${{ steps.prepare-version.outputs.version_timestamp }} cdn-base: ${{ steps.prepare-version.outputs.cdn_base }} + cdn-base-latest: ${{ steps.prepare-version.outputs.cdn_base_latest }} obs-path: ${{ steps.prepare-version.outputs.obs_path }} + obs-path-latest: ${{ steps.prepare-version.outputs.obs_path_latest }} concurrency: group: deploy-cdn cancel-in-progress: true @@ -75,14 +83,16 @@ jobs: VERSION=$(node -p "require('./designer-demo/package.json').version") # Generate timestamp in YYYYMMDD-HHMMSS format - TIMESTAMP=$(date +%Y%m%d-%H%M%S) + TIMESTAMP=$(TZ="Asia/Shanghai" date +%Y%m%d-%H%M%S) # Combine for version-timestamp VERSION_TIMESTAMP="${VERSION}-${TIMESTAMP}" # Set CDN base path CDN_BASE="https://res-static.opentiny.design/tiny-engine-designer/${VERSION_TIMESTAMP}/" + CDN_BASE_LATEST="https://res-static.opentiny.design/tiny-engine-designer/latest/" OBS_PATH="tiny-engine-designer/${VERSION_TIMESTAMP}/" + OBS_PATH_LATEST="tiny-engine-designer/latest" # Export as environment variables for subsequent steps echo "VERSION_TIMESTAMP=$VERSION_TIMESTAMP" >> $GITHUB_ENV @@ -92,7 +102,9 @@ jobs: # Set outputs for job-level export echo "version_timestamp=$VERSION_TIMESTAMP" >> $GITHUB_OUTPUT echo "cdn_base=$CDN_BASE" >> $GITHUB_OUTPUT + echo "cdn_base_latest=$CDN_BASE_LATEST" >> $GITHUB_OUTPUT echo "obs_path=$OBS_PATH" >> $GITHUB_OUTPUT + echo "obs_path_latest=$OBS_PATH_LATEST" >> $GITHUB_OUTPUT echo "Version-Timestamp: $VERSION_TIMESTAMP" echo "CDN Base: $CDN_BASE" @@ -140,7 +152,17 @@ jobs: # Upload to versioned path obsutil cp ./designer-demo/dist \ obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }} \ - -r -f + -r -f -flat + + # If is_latest_release is true, also upload to latest path + if [ "${{ github.event.inputs.is_latest_release }}" = "true" ]; then + # use cdn-base-latest replace cdn-base in all ./designer-demo/dist files + find ./designer-demo/dist -type f \( -name "*.html" -o -name "*.js" -o -name "*.mjs" -o -name "*.css" \) \ + -exec sed -i "s|${{ needs.build.outputs.cdn-base }}|${{ needs.build.outputs.cdn-base-latest }}|g" {} + + obsutil cp ./designer-demo/dist \ + obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path-latest }} \ + -r -f -flat + fi echo "Uploaded to: obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }}" echo "CDN URL: https://res-static.opentiny.design/${{ needs.build.outputs.obs-path }}"