Skip to content

Commit a972288

Browse files
authored
ci: add deploy-obs-tech-college (#73)
1 parent bc2b239 commit a972288

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Deploy tech-college to Huawei OBS
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
paths:
8+
- 'packages/common/**'
9+
- 'packages/tech-college/**'
10+
11+
workflow_dispatch:
12+
inputs:
13+
version:
14+
description: 输入您将要发布的版本号(默认使用 packages/tech-college/package.json 中的版本号),例如:`0.1.0`。
15+
required: false
16+
type: string
17+
18+
env:
19+
# 在 GitHub 项目源码仓库 → 项目的 Settings → Secrets(Actions 里的 Repository secrets) 里提前建好以下变量
20+
HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }}
21+
HUAWEI_CLOUD_SK: ${{ secrets.HUAWEI_CLOUD_SK }}
22+
HUAWEI_CLOUD_ENDPOINT: ${{ secrets.HUAWEI_CLOUD_ENDPOINT }}
23+
HUAWEI_CLOUD_BUCKET: ${{ secrets.HUAWEI_CLOUD_BUCKET }}
24+
25+
permissions:
26+
contents: read
27+
pages: write
28+
id-token: write
29+
30+
jobs:
31+
# Build job
32+
build:
33+
runs-on: ubuntu-latest
34+
outputs:
35+
version: ${{ steps.ver.outputs.value }}
36+
steps:
37+
- uses: webfactory/ssh-agent@v0.8.0
38+
with:
39+
ssh-private-key: ${{ secrets.SUBMODULE_SSH_KEY }}
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
- name: Setup pnpm
43+
uses: pnpm/action-setup@v3
44+
with:
45+
version: 9
46+
- name: Configure Git identity
47+
run: |
48+
git config --global user.name "GitHub Actions"
49+
git config --global user.email "actions@github.com"
50+
- name: Ensure submodules are up-to-date
51+
run: |
52+
git submodule sync --recursive
53+
git submodule update --init --recursive
54+
git submodule status --recursive
55+
- name: Install genui-sdk deps
56+
run: |
57+
cd genui-sdk && pnpm install
58+
- name: Build genui-sdk homepage
59+
run: |
60+
cd genui-sdk
61+
pnpm build:homepage
62+
- name: Install deps
63+
run: |
64+
pnpm -F opentiny-tech-college i --no-frozen-lockfile
65+
- name: Get version
66+
id: ver
67+
run: |
68+
# 优先用手动输入的版本号
69+
if [ -n "${{ inputs.version }}" ]; then
70+
VERSION="${{ inputs.version }}"
71+
else
72+
VERSION="$(node -p "require('./packages/tech-college/package.json').version")"
73+
fi
74+
echo "version: $VERSION"
75+
echo "value=$VERSION" >> $GITHUB_OUTPUT
76+
- name: Build
77+
run: pnpm -F opentiny-tech-college build
78+
env:
79+
VITE_CONTEXT: /
80+
VITE_BASE: //res-static.opentiny.design/opentiny-tech-college/${{ steps.ver.outputs.value }}/
81+
- name: Copy files
82+
run: |
83+
cp dist/index.html dist/404.html
84+
- name: Upload build artifact
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: dist-artifact
88+
path: dist/
89+
# Deploy job
90+
deploy:
91+
needs: build
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Download build artifact
95+
uses: actions/download-artifact@v4
96+
with:
97+
name: dist-artifact
98+
path: dist/
99+
- name: Show version
100+
run: |
101+
echo "Deploying version: ${{ needs.build.outputs.version }}"
102+
# ===== 下载 obsutil =====
103+
- name: Install obsutil
104+
run: |
105+
curl -o obsutil.tar.gz https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_amd64.tar.gz
106+
tar -xzf obsutil.tar.gz
107+
chmod +x obsutil_linux_amd64_*/obsutil
108+
sudo mv obsutil_linux_amd64_*/obsutil /usr/local/bin/obsutil
109+
110+
# ===== 配置并上传 =====
111+
- name: Upload to OBS
112+
run: |
113+
# 一次性配置 AK/SK/endpoint
114+
obsutil config -i=${{ env.HUAWEI_CLOUD_AK }} \
115+
-k=${{ env.HUAWEI_CLOUD_SK }} \
116+
-e=${{ env.HUAWEI_CLOUD_ENDPOINT }}
117+
118+
# 把本地 dist/ 目录整站同步到桶根目录
119+
echo "needs.build.outputs.version: ${{ needs.build.outputs.version }}"
120+
mv dist ${{ needs.build.outputs.version }}
121+
obsutil cp ${{ needs.build.outputs.version }} obs://${{ env.HUAWEI_CLOUD_BUCKET }}/opentiny-tech-college/ -r -f

0 commit comments

Comments
 (0)