Skip to content

Commit 7b6c80e

Browse files
author
niuweili
committed
feat: 跳过cdn发布
1 parent 89d32ef commit 7b6c80e

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Staging Deployment
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
confirm_deploy:
7+
description: 'Type "yes" to confirm deployment'
8+
required: true
9+
default: 'no'
10+
11+
jobs:
12+
deploy-staging:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '18'
22+
23+
- name: Install dependencies
24+
run: yarn
25+
26+
- name: Export BUILD_MODE
27+
run: export BUILD_MODE=release
28+
29+
- name: Get version
30+
run: |
31+
FULL_VERSION=$(node -p -e "require('./lerna.json').version")
32+
MAJOR_VERSION=$(echo $FULL_VERSION | cut -d. -f1)
33+
echo "VERSION=$MAJOR_VERSION" >> $GITHUB_ENV
34+
echo "version=$MAJOR_VERSION" >> $GITHUB_OUTPUT
35+
env:
36+
BUILD_MODE: release
37+
38+
- name: Build bundle
39+
run: yarn build:bundle
40+
41+
- name: Deploy to staging
42+
run: node ./scripts/deploy/deploy-oss.js staging v${VERSION}
43+
env:
44+
OSS_ENDPOINT: ${{ secrets.OSS_ENDPOINT }}
45+
OSS_REGION: ${{ secrets.OSS_REGION }}
46+
OSS_ACCESS_KEY: ${{ secrets.OSS_ACCESS_KEY }}
47+
OSS_BUCKET: ${{ secrets.OSS_BUCKET }}
48+
OSS_SECRET_KEY: ${{ secrets.OSS_SECRET_KEY }}

scripts/deploy/deploy-oss.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
const { printLog, printError, runMain } = require('../lib/executionUtils')
2-
const { forEachFile } = require('../lib/filesUtils')
31
const OSS = require('ali-oss')
4-
const dotenv = require('dotenv')
52
const CDN = require('@alicloud/cdn20180510')
63
const OpenApi = require('@alicloud/openapi-client')
7-
8-
dotenv.config()
4+
const { printLog, printError, runMain } = require('../lib/executionUtils')
5+
const { forEachFile } = require('../lib/filesUtils')
96

107
const { buildBundleFolder, packages } = require('./lib/deploymentUtils')
118

@@ -40,6 +37,10 @@ const client = new OSS({
4037
if (require.main === module) {
4138
const env = process.argv[2]
4239
const version = process.argv[3]
40+
if (env === 'prod' && (version.includes('beta') || version.includes('alpha'))) {
41+
printError('❌❌❌❌检测到非正式版本,跳过CDN发布,当前版本为:', version)
42+
process.exit(1)
43+
}
4344
runMain(async () => {
4445
await main(env, version)
4546
})
@@ -53,7 +54,7 @@ async function main(env, version) {
5354
const pathsToInvalidate = await uploadPackage(awsConfig, packageName, version)
5455
cloudfrontPathsToInvalidate.push(...pathsToInvalidate)
5556
}
56-
refreshCdnCache(cloudfrontPathsToInvalidate)
57+
await refreshCdnCache(cloudfrontPathsToInvalidate)
5758
}
5859

5960
// 读取bundle文件夹,上传到ali oss,并刷新cdn缓存

0 commit comments

Comments
 (0)