Skip to content

feat(publish:docs:3.8):fixed some issues #207

feat(publish:docs:3.8):fixed some issues

feat(publish:docs:3.8):fixed some issues #207

Workflow file for this run

name: 发布到华为云
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
judge:
if: contains(github.event.head_commit.message, 'docs:')
runs-on: ubuntu-latest
steps:
- name: Extract version from commit message
run: |
COMMIT_MSG=$(echo '${{ github.event.head_commit.message }}' | grep -oP '(?<=docs:)\d+\.\d+')
if [ -z "$COMMIT_MSG" ]; then
echo "没有指定需要发布的版本"
exit 1
fi
echo "将构建版本: $COMMIT_MSG !"
deploy:
needs: judge
runs-on: ubuntu-latest
steps:
- name: 提取版本信息
id: extract
run: |
COMMIT_MSG=$(echo '${{ github.event.head_commit.message }}' | grep -oP '(?<=docs:)\d+\.\d+')
echo "version=$COMMIT_MSG" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
- name: 设置 node 环境
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: 安装依赖
run: npm install
- name: 构建项目 (测试环境)
if: contains(github.event.head_commit.message, 'test:docs:')
run: node scripts/publish.js --version=versions/${{ steps.extract.outputs.version }}
- name: 构建项目 (正式环境)
if: contains(github.event.head_commit.message, 'publish:docs:')
run: node scripts/publish.js --version=versions/${{ steps.extract.outputs.version }}
- name: 登录华为云
uses: huaweicloud/[email protected]
with:
access_key_id: ${{ secrets.ACCESSKEY }}
secret_access_key: ${{ secrets.SECRETACCESSKEY }}
region: 'cn-north-4'
# 按版本上传到对应的文件去
- name: 上传文件到华为云 (测试环境)
if: contains(github.event.head_commit.message, 'test:docs:')
uses: ./.github/actions/obs-helper
with:
bucket_name: 'cce-creator-docs-test'
local_file_path: ./versions/${{ steps.extract.outputs.version }}/.vitepress/dist
obs_file_path: gitbook/creator/${{ steps.extract.outputs.version }}/manual/
operation_type: upload
include_self_folder: false
- name: 上传文件到华为云(正式环境)
if: contains(github.event.head_commit.message, 'publish:docs:')
#uses: huaweicloud/obs-helper@master
uses: ./.github/actions/obs-helper
with:
bucket_name: 'cce-creator-docs-pro'
local_file_path: ./versions/${{ steps.extract.outputs.version }}/.vitepress/dist
obs_file_path: gitbook/creator/${{ steps.extract.outputs.version }}/manual/
operation_type: upload
include_self_folder: false
- name: Get Huawei Cloud IAM Token
if: contains(github.event.head_commit.message, 'publish:docs:')
id: get-token
env:
HWCLOUD_USERNAME: ${{ secrets.HUAWEI_CLOUD_USERNAME }}
HWCLOUD_PASSWORD: ${{ secrets.HUAWEI_CLOUD_PASSWORD }}
HWCLOUD_DOMAIN_NAME: ${{ secrets.HUAWEI_CLOUD_DOMAIN_NAME }}
HWCLOUD_PROJECT_ID: ${{ secrets.HUAWEI_CLOUD_PROJECT_ID }}
IAM_ENDPOINT: 'https://iam.myhuaweicloud.com/v3/auth/tokens'
run: |
PAYLOAD="{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"name\":\"$HWCLOUD_USERNAME\",\"password\":\"$HWCLOUD_PASSWORD\",\"domain\":{\"name\":\"$HWCLOUD_DOMAIN_NAME\"}}}},\"scope\":{\"project\":{\"id\":\"$HWCLOUD_PROJECT_ID\"}}}}"
IAM_RESPONSE=$(curl -si -X POST "$IAM_ENDPOINT" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
IAM_TOKEN=$(echo "$IAM_RESPONSE" | grep X-Subject-Token: | awk '{print $2}' | tr -d '\r')
if [ -z "$IAM_TOKEN" ]; then
echo "Failed to get IAM token"
exit 1
fi
echo "::add-mask::$IAM_TOKEN"
echo "::set-output name=IAM_TOKEN::$IAM_TOKEN"
- name: Refresh CDN Cache
if: success() && steps.get-token.outputs.IAM_TOKEN
env:
CDN_ENDPOINT: 'https://cdn.myhuaweicloud.com/v1.0/cdn/content/refresh-tasks'
IAM_TOKEN: ${{ steps.get-token.outputs.IAM_TOKEN }}
run: |
CDN_PAYLOAD="{\"refresh_task\":{\"type\":\"directory\",\"urls\":[\"https://docs.cocos.com/\"]}}"
CDN_RESPONSE=$(curl -si -X POST "$CDN_ENDPOINT" \
-H "Content-Type: application/json" \
-H "X-Auth-Token: $IAM_TOKEN" \
-d "$CDN_PAYLOAD")
echo "$CDN_RESPONSE"