Skip to content

Deploy docs to Huawei OBS #36

Deploy docs to Huawei OBS

Deploy docs to Huawei OBS #36

Workflow file for this run

name: Deploy docs to Huawei OBS
on:
push:
tags:
- 'v*'
paths:
- 'next-sdk/docs/**'
- 'tiny-robot/docs/**'
- 'tiny-vue/examples/sites/demos/pc/webdoc/**'
- '.vitepress/**'
workflow_dispatch:
inputs:
version:
description: 输入您将要发布的版本号(默认使用 package.json 中的版本号),例如:`0.1.0`。
required: false
type: string
env:
# 在 GitHub 项目源码仓库 → 项目的 Settings → Secrets(Actions 里的 Repository secrets) 里提前建好以下变量
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 }}
permissions:
contents: read
pages: write
id-token: write
jobs:
# Build job
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.ver.outputs.value }}
steps:
- uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ secrets.SUBMODULE_SSH_KEY }}
- name: Checkout repository (with submodules)
uses: actions/checkout@v4
with:
fetch-depth: 0 # 推荐完整历史以支持 lastUpdated 等
submodules: false # 检出子模块(递归)
- name: Configure Git identity
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Ensure submodules are up-to-date (pull latest from their remote)
# 这一步会把子模块更新到各自远端的最新分支(通常是子模块配置的上游)
run: |
git submodule update --init --recursive
# 打印状态便于调试
git submodule status --recursive
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Install deps
run: pnpm i
- name: Get docs version
id: ver
run: |
# 优先用手动输入的版本号
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="$(node -p "require('./package.json').version")"
fi
echo "version: $VERSION"
echo "value=$VERSION" >> $GITHUB_OUTPUT
- name: Build @opentiny/tiny-robot
run: pnpm -F robot-root build
- name: Build site
run: pnpm build
env:
VITEPRESS_BASE: /
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: dist-artifact
path: dist/
# Deploy job
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: dist-artifact
path: dist/
- name: Show version
run: |
echo "Deploying version: ${{ needs.build.outputs.version }}"
# ===== 下载 obsutil =====
- 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: Upload to OBS
run: |
# 一次性配置 AK/SK/endpoint
obsutil config -i=${{ env.HUAWEI_CLOUD_AK }} \
-k=${{ env.HUAWEI_CLOUD_SK }} \
-e=${{ env.HUAWEI_CLOUD_ENDPOINT }}
# 把本地 dist/ 目录整站同步到桶根目录
echo "needs.build.outputs.version: ${{ needs.build.outputs.version }}"
mv dist ${{ needs.build.outputs.version }}
obsutil cp ${{ needs.build.outputs.version }} obs://${{ env.HUAWEI_CLOUD_BUCKET }}/opentiny-docs/ -r -f