Deploy docs to Huawei OBS #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy docs to Huawei OBS | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'next-sdk/docs/**' | |
| - 'tiny-robot/docs/**' | |
| - 'tiny-vue/examples/sites/demos/pc/webdoc/**' | |
| - '.vitepress/**' | |
| workflow_dispatch: | |
| 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 | |
| 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: | |
| token: ${{ secrets.PAT_TOKEN }} # 使用 PAT 以确保有权限访问私有子模块 | |
| fetch-depth: 0 # 推荐完整历史以支持 lastUpdated 等 | |
| submodules: recursive # 检出子模块(递归) | |
| persist-credentials: false | |
| - name: Ensure submodules are up-to-date (pull latest from their remote) | |
| # 这一步会把子模块更新到各自远端的最新分支(通常是子模块配置的上游) | |
| run: | | |
| git submodule sync --recursive | |
| git submodule update --init --recursive | |
| # 拉取子模块的远端最新提交(合并到当前子模块工作树) | |
| # 注意:这不会把变化提交回主仓库;仅用于构建时使用最新子模块内容 | |
| git submodule update --remote --merge --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 | |
| run: | | |
| echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
| - name: Build site | |
| run: pnpm build | |
| env: | |
| VITEPRESS_BASE: //res-static.opentiny.design/opentiny-docs/${{ env.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/ 目录整站同步到桶根目录 | |
| mv dist ${{ env.VERSION }} | |
| obsutil cp ${{ env.VERSION }} obs://${{ env.HUAWEI_CLOUD_BUCKET }}/opentiny-docs/ -r -f |