Skip to content

Commit 4d15511

Browse files
authored
ci: split deploy-obs to build and deploy (#9)
1 parent b46726b commit 4d15511

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

.github/workflows/deploy-obs.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
branches: [main]
66

77
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 输入您将要发布的版本号(默认使用 package.json 中的版本号),例如:`0.1.0`。
11+
required: false
12+
type: string
813

914
env:
1015
# 在 GitHub 项目源码仓库 → 项目的 Settings → Secrets(Actions 里的 Repository secrets) 里提前建好以下变量
@@ -22,6 +27,8 @@ jobs:
2227
# Build job
2328
build:
2429
runs-on: ubuntu-latest
30+
outputs:
31+
version: ${{ steps.ver.outputs.value }}
2532
steps:
2633
- name: Checkout
2734
uses: actions/checkout@v3
@@ -32,12 +39,38 @@ jobs:
3239
- name: Install deps
3340
run: pnpm i
3441
- name: Get version
42+
id: ver
3543
run: |
36-
echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
44+
# 优先用手动输入的版本号
45+
if [ -n "${{ inputs.version }}" ]; then
46+
VERSION="${{ inputs.version }}"
47+
else
48+
VERSION="$(node -p "require('./package.json').version")"
49+
fi
50+
echo "version: $VERSION"
51+
echo "value=$VERSION" >> $GITHUB_OUTPUT
3752
- name: Build site
3853
run: pnpm build
3954
env:
40-
VITEPRESS_BASE: //res-static.opentiny.design/opentiny-playground/${{ env.VERSION }}/
55+
VITEPRESS_BASE: //res-static.opentiny.design/opentiny-playground/${{ steps.ver.outputs.value }}/
56+
- name: Upload build artifact
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: dist-artifact
60+
path: dist/
61+
# Deploy job
62+
deploy:
63+
needs: build
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Download build artifact
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: dist-artifact
70+
path: dist/
71+
- name: Show version
72+
run: |
73+
echo "Deploying version: ${{ needs.build.outputs.version }}"
4174
# ===== 下载 obsutil =====
4275
- name: Install obsutil
4376
run: |
@@ -55,5 +88,6 @@ jobs:
5588
-e=${{ env.HUAWEI_CLOUD_ENDPOINT }}
5689
5790
# 把本地 dist/ 目录整站同步到桶根目录
58-
mv dist ${{ env.VERSION }}
59-
obsutil cp ${{ env.VERSION }} obs://${{ env.HUAWEI_CLOUD_BUCKET }}/opentiny-playground/ -r -f
91+
echo "needs.build.outputs.version: ${{ needs.build.outputs.version }}"
92+
mv dist ${{ needs.build.outputs.version }}
93+
obsutil cp ${{ needs.build.outputs.version }} obs://${{ env.HUAWEI_CLOUD_BUCKET }}/opentiny-playground/ -r -f

0 commit comments

Comments
 (0)