update #51
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: Build and Deploy | |
on: | |
# 每当 push 到 main 分支时触发部署 | |
push: | |
branches: [master] | |
# 手动触发部署 | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录 | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
# 选择要使用的 node 版本 | |
node-version: 20 | |
# 运行构建脚本 | |
- name: Build VuePress site | |
run: npm install && npm run docs:build | |
# 查看 workflow 的文档来获取更多信息 | |
# @see https://github.com/crazy-max/ghaction-github-pages | |
- name: Deploy to GitHub Pages | |
uses: crazy-max/ghaction-github-pages@v4 | |
with: | |
# 部署到 gh-pages 分支 | |
target_branch: deploy | |
# 部署目录为 VuePress 的默认输出目录 | |
build_dir: src/.vuepress/dist | |
env: | |
# @see https://docs.github.com/cn/actions/reference/authentication-in-a-workflow#about-the-github_token-secret | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Deployment job | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: "deploy" | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: "." | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
# 清理腾讯云 CDN 缓存 | |
purge-cache: | |
environment: | |
name: PROD | |
runs-on: ubuntu-latest | |
needs: deploy | |
steps: | |
- name: Pruge Cache | |
env: | |
TENCENT_CLOUD_SECRET_ID: ${{ secrets.TENCENT_CLOUD_SECRET_ID }} | |
TENCENT_CLOUD_SECRET_KEY: ${{ secrets.TENCENT_CLOUD_SECRET_KEY }} | |
run: | | |
#!/bin/bash | |
secret_id="${TENCENT_CLOUD_SECRET_ID}" | |
secret_key="${TENCENT_CLOUD_SECRET_KEY}" | |
token="" | |
service="teo" | |
host="teo.tencentcloudapi.com" | |
region="ap-guangzhou" | |
action="CreatePurgeTask" | |
version="2022-09-01" | |
algorithm="TC3-HMAC-SHA256" | |
timestamp=$(date +%s) | |
date=$(date -u -d @$timestamp +"%Y-%m-%d") | |
payload="{\"ZoneId\":\"zone-2p8aphgc6owt\",\"Type\":\"purge_url\",\"Method\":\"invalidate\",\"Targets\":[\"https://blog.shabbywu.cn/\",\"https://blog.shabbywu.cn/resume/\",\"https://blog.shabbywu.cn/en/\",\"https://blog.shabbywu.cn/en/resume\"]}" | |
# ************* 步骤 1:拼接规范请求串 ************* | |
http_request_method="POST" | |
canonical_uri="/" | |
canonical_querystring="" | |
canonical_headers="content-type:application/json; charset=utf-8\nhost:$host\nx-tc-action:$(echo $action | awk '{print tolower($0)}')\n" | |
signed_headers="content-type;host;x-tc-action" | |
hashed_request_payload=$(echo -n "$payload" | openssl sha256 -hex | awk '{print $2}') | |
canonical_request="$http_request_method\n$canonical_uri\n$canonical_querystring\n$canonical_headers\n$signed_headers\n$hashed_request_payload" | |
echo "$canonical_request" | |
# ************* 步骤 2:拼接待签名字符串 ************* | |
credential_scope="$date/$service/tc3_request" | |
hashed_canonical_request=$(printf "$canonical_request" | openssl sha256 -hex | awk '{print $2}') | |
string_to_sign="$algorithm\n$timestamp\n$credential_scope\n$hashed_canonical_request" | |
echo "$string_to_sign" | |
# ************* 步骤 3:计算签名 ************* | |
secret_date=$(printf "$date" | openssl sha256 -hmac "TC3$secret_key" | awk '{print $2}') | |
echo $secret_date | |
secret_service=$(printf $service | openssl dgst -sha256 -mac hmac -macopt hexkey:"$secret_date" | awk '{print $2}') | |
echo $secret_service | |
secret_signing=$(printf "tc3_request" | openssl dgst -sha256 -mac hmac -macopt hexkey:"$secret_service" | awk '{print $2}') | |
echo $secret_signing | |
signature=$(printf "$string_to_sign" | openssl dgst -sha256 -mac hmac -macopt hexkey:"$secret_signing" | awk '{print $2}') | |
echo "$signature" | |
# ************* 步骤 4:拼接 Authorization ************* | |
authorization="$algorithm Credential=$secret_id/$credential_scope, SignedHeaders=$signed_headers, Signature=$signature" | |
echo $authorization | |
# ************* 步骤 5:构造并发起请求 ************* | |
curl -XPOST "https://$host" -d "$payload" -H "Authorization: $authorization" -H "Content-Type: application/json; charset=utf-8" -H "Host: $host" -H "X-TC-Action: $action" -H "X-TC-Timestamp: $timestamp" -H "X-TC-Version: $version" -H "X-TC-Region: $region" -H "X-TC-Token: $token" |