feat(publish:all:pro):20240528-2 #30
This file contains 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: 全量发布到华为云 | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
if: contains(github.event.head_commit.message, 'publish:all') | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
publish-version: ['3.8', '3.7', '3.6', '3.5', '3.4', '3.3', '3.2', '3.1', '3.0', '2.4'] | |
steps: | |
- 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, 'publish:all:test') | |
run: npx dotenvx run --env-file=.env.test -- node scripts/publish.js --version=versions/${{ matrix.publish-version }} | |
- name: 构建项目 (正式环境) | |
if: contains(github.event.head_commit.message, 'publish:all:pro') | |
run: npx dotenvx run --env-file=.env.pro -- node scripts/publish.js --version=versions/${{ matrix.publish-version }} | |
- name: 登录华为云 | |
uses: huaweicloud/auth-action@v1.0.0 | |
with: | |
access_key_id: ${{ secrets.ACCESSKEY }} | |
secret_access_key: ${{ secrets.SECRETACCESSKEY }} | |
region: 'cn-north-4' | |
# 按版本上传到对应的文件去 | |
- name: 上传文件到华为云 (测试环境) | |
if: contains(github.event.head_commit.message, 'publish:all:test') | |
uses: ./.github/actions/obs-helper | |
with: | |
bucket_name: 'cce-creator-docs-test' | |
local_file_path: ./versions/${{ matrix.publish-version }}/.vitepress/dist | |
obs_file_path: gitbook/creator/${{ matrix.publish-version }}/manual/ | |
operation_type: upload | |
include_self_folder: false | |
- name: 上传文件到华为云(正式环境) | |
if: contains(github.event.head_commit.message, 'publish:all:pro') | |
uses: ./.github/actions/obs-helper | |
with: | |
bucket_name: 'cce-creator-docs-pro' | |
local_file_path: ./versions/${{ matrix.publish-version }}/.vitepress/dist | |
obs_file_path: gitbook/creator/${{ matrix.publish-version }}/manual/ | |
operation_type: upload | |
include_self_folder: false | |
- name: Refresh Huawei Cloud CDN Cache | |
env: | |
access_key_id: ${{ secrets.ACCESSKEY }} | |
secret_access_key: ${{ secrets.SECRETACCESSKEY }} | |
run: | | |
# 安装必要的软件包 | |
sudo apt-get update | |
sudo apt-get install -y jq | |
# 设置必要的环境变量 | |
CURRENT_DATE=$(date -u +'%Y%m%dT%H%M%SZ') | |
SERVICE_NAME="cdn" | |
REGION="cn-north-4" # 替换为你的华为云区域 | |
REQUEST_METHOD="POST" | |
REQUEST_URI="/v1.0/cdn/content/refresh" | |
HOST="cdn.myhuaweicloud.com" | |
CONTENT_TYPE="application/json" | |
# 设置需要刷新的目录URL | |
DIRECTORY_URL="https://docs.cocos.com/" | |
# 构建用于刷新目录的请求负载 | |
REQUEST_PAYLOAD="{\"refresh_task\":{\"type\":\"directory\",\"urls\":[\"${DIRECTORY_URL}\"]}}" | |
REQUEST_PAYLOAD_HASH=$(echo -n $REQUEST_PAYLOAD | openssl dgst -sha256 -binary | base64) | |
CANONICAL_URI="/v1.0/cdn/content/refresh" | |
CANONICAL_QUERYSTRING="" | |
CANONICAL_HEADERS="content-type:${CONTENT_TYPE}\nhost:${HOST}\nx-sdk-date:${CURRENT_DATE}\n" | |
SIGNED_HEADERS="content-type;host;x-sdk-date" | |
CANONICAL_REQUEST="${REQUEST_METHOD}\n${CANONICAL_URI}\n${CANONICAL_QUERYSTRING}\n${CANONICAL_HEADERS}\n${SIGNED_HEADERS}\n${REQUEST_PAYLOAD_HASH}" | |
# 生成签名 | |
SIGNATURE=$(echo -n "SDK-HMAC-SHA256\n${CURRENT_DATE}\n${REGION}/${SERVICE_NAME}/sdk_request\n$(echo -n ${CANONICAL_REQUEST} | openssl dgst -sha256 -binary | base64)" | openssl dgst -sha256 -hmac "${secret_access_key}" -binary | base64) | |
# 发送刷新CDN的请求 | |
curl -X $REQUEST_METHOD "https://${HOST}${CANONICAL_URI}" \ | |
-H "Content-Type: ${CONTENT_TYPE}" \ | |
-H "Host: ${HOST}" \ | |
-H "X-Sdk-Date: ${CURRENT_DATE}" \ | |
-H "Authorization: SDK-HMAC-SHA256 Access=${access_key_id}, SignedHeaders=${SIGNED_HEADERS}, Signature=${SIGNATURE}" \ | |
-d $REQUEST_PAYLOAD | |