This commit is contained in:
113
.github/workflows/del-esa-code.yml
vendored
Normal file
113
.github/workflows/del-esa-code.yml
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
name: Clean ESA Versions on Main
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
clean-esa-versions:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# 下载阿里云CLI https://help.aliyun.com/zh/cli/
|
||||
- name: Download Aliyun Cli
|
||||
run: |
|
||||
set -euo pipefail
|
||||
/bin/bash -c "$(curl -fsSL https://aliyuncli.alicdn.com/install.sh)"
|
||||
|
||||
# 配置阿里云CLI
|
||||
- name: Configure Aliyun CLI
|
||||
run: |
|
||||
aliyun configure set \
|
||||
--profile AkProfile \
|
||||
--mode AK \
|
||||
--access-key-id ${{ secrets.ALIYUN_ACCESS_KEY_ID }} \
|
||||
--access-key-secret ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }} \
|
||||
--region "cn-hangzhou"
|
||||
|
||||
# 获取Pages名称(可配置)
|
||||
- name: Get Pages Name
|
||||
id: get-pages-name
|
||||
run: |
|
||||
# 从配置中读取Pages名称,这里使用默认值blog,可根据需要修改
|
||||
echo "pages_name=fuwari" >> $GITHUB_OUTPUT
|
||||
|
||||
# 获取所有代码版本并清理旧版本
|
||||
- name: Clean ESA Code Versions
|
||||
env:
|
||||
PAGES_NAME: ${{ steps.get-pages-name.outputs.pages_name }}
|
||||
# 配置保留的版本数,默认为1(只保留最新版本)
|
||||
RETAIN_VERSIONS: ${{ vars.RETAIN_VERSIONS || '1' }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
echo "开始清理阿里云ESA版本..."
|
||||
echo "目标Pages: $PAGES_NAME"
|
||||
echo "保留版本数: $RETAIN_VERSIONS"
|
||||
|
||||
# 获取所有版本信息
|
||||
VERSIONS_JSON=$(aliyun esa ListRoutineCodeVersions --region cn-hangzhou --Name $PAGES_NAME)
|
||||
|
||||
# 解析版本数量
|
||||
TOTAL_COUNT=$(echo $VERSIONS_JSON | jq -r '.TotalCount')
|
||||
echo "当前共有 $TOTAL_COUNT 个版本"
|
||||
|
||||
# 如果版本数不超过保留数量,不需要清理
|
||||
if [ "$TOTAL_COUNT" -le "$RETAIN_VERSIONS" ]; then
|
||||
echo "版本数 ($TOTAL_COUNT) 未超过保留数量 ($RETAIN_VERSIONS),无需清理"
|
||||
echo "ESA会自动检测main分支更新并部署"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 计算需要删除的版本数(保留指定数量的最新版本)
|
||||
DELETE_COUNT=$((TOTAL_COUNT - RETAIN_VERSIONS))
|
||||
echo "需要删除 $DELETE_COUNT 个旧版本,保留最新的 $RETAIN_VERSIONS 个版本"
|
||||
|
||||
# 解析版本列表,按创建时间排序(最早的在前)
|
||||
VERSIONS_TO_DELETE=$(echo $VERSIONS_JSON | jq -r '.CodeVersions | sort_by(.CreateTime) | .[0:'$DELETE_COUNT'] | .[].CodeVersion')
|
||||
|
||||
echo "将要删除的版本: $VERSIONS_TO_DELETE"
|
||||
|
||||
# 删除旧版本
|
||||
DELETED_COUNT=0
|
||||
for VERSION in $VERSIONS_TO_DELETE; do
|
||||
echo "正在删除版本: $VERSION"
|
||||
DELETE_RESULT=$(aliyun esa DeleteRoutineCodeVersion --region cn-hangzhou --Name $PAGES_NAME --CodeVersion $VERSION)
|
||||
STATUS=$(echo $DELETE_RESULT | jq -r '.Status')
|
||||
|
||||
if [ "$STATUS" = "OK" ]; then
|
||||
echo "版本 $VERSION 删除成功"
|
||||
DELETED_COUNT=$((DELETED_COUNT + 1))
|
||||
else
|
||||
echo "版本 $VERSION 删除失败: $DELETE_RESULT"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "版本清理完成!成功删除 $DELETED_COUNT 个旧版本"
|
||||
|
||||
# 验证清理结果
|
||||
- name: Verify Clean Result
|
||||
env:
|
||||
PAGES_NAME: ${{ steps.get-pages-name.outputs.pages_name }}
|
||||
RETAIN_VERSIONS: ${{ vars.RETAIN_VERSIONS || '1' }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
echo "验证清理结果..."
|
||||
RESULT_JSON=$(aliyun esa ListRoutineCodeVersions --region cn-hangzhou --Name $PAGES_NAME)
|
||||
REMAINING_COUNT=$(echo $RESULT_JSON | jq -r '.TotalCount')
|
||||
|
||||
echo "清理后剩余版本数: $REMAINING_COUNT"
|
||||
|
||||
if [ "$REMAINING_COUNT" -le "$RETAIN_VERSIONS" ]; then
|
||||
echo "版本清理成功,当前版本数: $REMAINING_COUNT (保留设置: $RETAIN_VERSIONS)"
|
||||
echo "ESA会自动检测main分支更新并开始部署"
|
||||
else
|
||||
echo "版本清理失败,仍有 $REMAINING_COUNT 个版本,期望保留: $RETAIN_VERSIONS"
|
||||
exit 1
|
||||
fi
|
||||
27
.github/workflows/deploy.yml-nouse
vendored
Normal file
27
.github/workflows/deploy.yml-nouse
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: Build and Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Deploy to page branch
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./dist
|
||||
publish_branch: page
|
||||
cname: ${{ secrets.CNAME }}
|
||||
Reference in New Issue
Block a user