Skip to content

Commit 7fb0e83

Browse files
authored
ci: add deploy obs (#1)
1 parent 3888280 commit 7fb0e83

3 files changed

Lines changed: 75 additions & 5 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ jobs:
2929
run: pnpm i
3030
- name: Build common
3131
run: pnpm build:common
32+
- name: Get home version
33+
run: echo "VERSION=$(node -p \"require('./package.json').version\")" >> $GITHUB_ENV
3234
- name: Build home
3335
run: pnpm build
3436
env:
3537
VITE_CONTEXT: /opentiny.design/
3638
VITE_BASE: /opentiny.design/
3739
- name: Copy files
3840
run: |
39-
cp dist/common/tinyui-design-common.iife.js dist/home
41+
cp dist/${{ env.VERSION }}/common/tinyui-design-common.iife.js dist/${{ env.VERSION }}/home
4042
- name: Setup Pages
4143
uses: actions/configure-pages@v2
4244
- name: Build with Jekyll
43-
uses: actions/jekyll-build-pages@v1
45+
uses: actions/jekyll-build-pages@v1`
4446
with:
45-
source: ./dist/home
47+
source: ./dist/${{ env.VERSION }}/home
4648
destination: ./_site
4749
- name: Upload artifact
4850
uses: actions/upload-pages-artifact@v3

.github/workflows/deploy-obs.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy to Huawei OBS
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
workflow_dispatch:
8+
9+
env:
10+
# 在 GitHub 项目源码仓库 → 项目的 Settings → Secrets(Actions 里的 Repository secrets) 里提前建好以下变量
11+
HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }}
12+
HUAWEI_CLOUD_SK: ${{ secrets.HUAWEI_CLOUD_SK }}
13+
HUAWEI_CLOUD_ENDPOINT: ${{ secrets.HUAWEI_CLOUD_ENDPOINT }}
14+
HUAWEI_CLOUD_BUCKET: ${{ secrets.HUAWEI_CLOUD_BUCKET }}
15+
16+
permissions:
17+
contents: read
18+
pages: write
19+
id-token: write
20+
21+
concurrency:
22+
group: pages
23+
cancel-in-progress: true
24+
25+
jobs:
26+
# Build job
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
- name: Setup pnpm
33+
uses: pnpm/action-setup@v3
34+
with:
35+
version: 9
36+
- name: Install deps
37+
run: pnpm i
38+
- name: Build common
39+
run: pnpm build:common
40+
- name: Get home version
41+
run: echo "VERSION=$(node -p \"require('./package.json').version\")" >> $GITHUB_ENV
42+
- name: Build home
43+
run: pnpm build
44+
env:
45+
VITE_CONTEXT: /opentiny.design/
46+
VITE_BASE: /opentiny.design/
47+
- name: Copy files
48+
run: |
49+
cp dist/${{ env.VERSION }}/common/tinyui-design-common.iife.js dist/${{ env.VERSION }}/home
50+
# ===== 下载 obsutil =====
51+
- name: Install obsutil
52+
run: |
53+
curl -o obsutil.tar.gz https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_amd64.tar.gz
54+
tar -xzf obsutil.tar.gz
55+
chmod +x obsutil_linux_amd64_*/obsutil
56+
sudo mv obsutil_linux_amd64_*/obsutil /usr/local/bin/obsutil
57+
58+
# ===== 配置并上传 =====
59+
- name: Upload to OBS
60+
run: |
61+
# 一次性配置 AK/SK/endpoint
62+
obsutil config -i=${{ env.HUAWEI_CLOUD_AK }} \
63+
-k=${{ env.HUAWEI_CLOUD_SK }} \
64+
-e=${{ env.HUAWEI_CLOUD_ENDPOINT }}
65+
66+
# 把本地 dist/ 目录整站同步到桶根目录
67+
obsutil cp dist/${{ env.VERSION }}/ obs://${{ env.HUAWEI_CLOUD_BUCKET }}/opentiny-design/ -r -f

packages/home/vite.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import importPlugin from '@opentiny/vue-vite-import'
1111
import { visualizer } from 'rollup-plugin-visualizer'
1212
import { viteStaticCopy } from 'vite-plugin-static-copy'
1313
import path from 'path'
14+
import packageJson from './package.json'
1415

1516
function _resolve(dir) {
1617
return path.resolve(__dirname, dir)
@@ -69,7 +70,7 @@ export default defineConfig(({ command, mode }) => {
6970
targets: [
7071
{
7172
src: '../home/public/downloadFile/*',
72-
dest: 'dist/home/downloadFile'
73+
dest: `dist/${packageJson.version}/home/downloadFile`
7374
}
7475
]
7576
})
@@ -79,7 +80,7 @@ export default defineConfig(({ command, mode }) => {
7980
},
8081
base: process.env.VITE_BASE || '/',
8182
build: {
82-
outDir: '../../dist/home',
83+
outDir: `../../dist/${packageJson.version}/home`,
8384
commonjsOptions: {
8485
transformMixedEsModules: true
8586
},

0 commit comments

Comments
 (0)