mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-19 13:59:27 +02:00
update
This commit is contained in:
parent
8e892b2805
commit
48a4e5315e
113
.github/workflows/optimize-assets.yml
vendored
113
.github/workflows/optimize-assets.yml
vendored
@ -1,27 +1,44 @@
|
|||||||
name: Optimize Assets
|
name: Optimize Assets
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch: # 允许手动触发
|
workflow_dispatch: # 手动触发
|
||||||
|
schedule:
|
||||||
|
- cron: '0 3 * * *' # 每天凌晨3点执行
|
||||||
|
|
||||||
|
env:
|
||||||
|
FFMPEG_VERSION: '6.1'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
optimize:
|
optimize:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30 # 设置任务超时时间
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
# 添加仓库缓存
|
||||||
|
- name: Cache Git Repository
|
||||||
|
id: cache-repo
|
||||||
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
path: .git
|
||||||
token: ${{ secrets.FORK_SYNC_TOKEN }}
|
key: git-repo-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
git-repo-
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # 获取完整历史以确保正确同步
|
||||||
|
token: ${{ github.token }} # 使用默认的 GITHUB_TOKEN
|
||||||
|
|
||||||
- name: Sync with upstream
|
- name: Sync with upstream
|
||||||
id: sync
|
id: sync
|
||||||
continue-on-error: true
|
|
||||||
run: |
|
run: |
|
||||||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git config --local user.name "github-actions[bot]"
|
git config --local user.name "github-actions[bot]"
|
||||||
|
|
||||||
# 添加上游仓库
|
# 检查并添加上游仓库
|
||||||
git remote add upstream https://github.com/pagefaultgames/pokerogue.git
|
if ! git remote | grep -q '^upstream$'; then
|
||||||
|
git remote add upstream https://github.com/pagefaultgames/pokerogue.git
|
||||||
|
fi
|
||||||
|
|
||||||
# 获取上游更新
|
# 获取上游更新
|
||||||
git fetch upstream main
|
git fetch upstream main
|
||||||
@ -30,39 +47,35 @@ jobs:
|
|||||||
if git rev-list HEAD..upstream/main --count | grep -q "^0$"; then
|
if git rev-list HEAD..upstream/main --count | grep -q "^0$"; then
|
||||||
echo "sync_status=uptodate" >> $GITHUB_OUTPUT
|
echo "sync_status=uptodate" >> $GITHUB_OUTPUT
|
||||||
echo "仓库已是最新,无需同步"
|
echo "仓库已是最新,无需同步"
|
||||||
else
|
exit 0
|
||||||
# 合并上游更新
|
|
||||||
if git merge upstream/main --no-edit; then
|
|
||||||
echo "sync_status=success" >> $GITHUB_OUTPUT
|
|
||||||
git push
|
|
||||||
else
|
|
||||||
echo "sync_status=failed" >> $GITHUB_OUTPUT
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 重置到上游状态
|
||||||
|
git reset --hard upstream/main
|
||||||
|
|
||||||
|
# 强制推送更新
|
||||||
|
git push -f
|
||||||
|
echo "sync_status=updated" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Check sync status
|
# 只有当仓库不是最新且同步成功时,才继续执行后续步骤
|
||||||
if: steps.sync.outputs.sync_status == 'failed'
|
|
||||||
run: |
|
|
||||||
echo "同步上游仓库失败,请手动解决冲突"
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
if: steps.sync.outputs.sync_status == 'updated'
|
||||||
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '18'
|
node-version: '18'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
# 优化 FFmpeg 缓存
|
# 优化 FFmpeg 缓存
|
||||||
- name: Cache FFmpeg
|
- name: Cache FFmpeg
|
||||||
|
if: steps.sync.outputs.sync_status == 'updated'
|
||||||
id: cache-ffmpeg
|
id: cache-ffmpeg
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/ffmpeg
|
path: ~/ffmpeg
|
||||||
key: ${{ runner.os }}-ffmpeg-static-6.1
|
key: ${{ runner.os }}-ffmpeg-static-${{ env.FFMPEG_VERSION }}
|
||||||
|
|
||||||
- name: Install FFmpeg
|
- name: Install FFmpeg
|
||||||
if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
|
if: steps.sync.outputs.sync_status == 'updated' && steps.cache-ffmpeg.outputs.cache-hit != 'true'
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/ffmpeg
|
mkdir -p ~/ffmpeg
|
||||||
wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
|
wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
|
||||||
@ -72,12 +85,14 @@ jobs:
|
|||||||
rm -rf ffmpeg-*-amd64-static*
|
rm -rf ffmpeg-*-amd64-static*
|
||||||
|
|
||||||
- name: Add FFmpeg to PATH
|
- name: Add FFmpeg to PATH
|
||||||
|
if: steps.sync.outputs.sync_status == 'updated'
|
||||||
run: echo "$HOME/ffmpeg" >> $GITHUB_PATH
|
run: echo "$HOME/ffmpeg" >> $GITHUB_PATH
|
||||||
|
|
||||||
# 添加 node_modules 缓存
|
# 添加 node_modules 缓存
|
||||||
- name: Cache node_modules
|
- name: Cache node_modules
|
||||||
|
if: steps.sync.outputs.sync_status == 'updated'
|
||||||
id: cache-node-modules
|
id: cache-node-modules
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: node_modules
|
path: node_modules
|
||||||
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
|
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
|
||||||
@ -85,20 +100,27 @@ jobs:
|
|||||||
${{ runner.os }}-node-modules-
|
${{ runner.os }}-node-modules-
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
if: steps.sync.outputs.sync_status == 'updated' && steps.cache-node-modules.outputs.cache-hit != 'true'
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Optimize Assets
|
||||||
|
if: steps.sync.outputs.sync_status == 'updated'
|
||||||
|
id: optimize_assets
|
||||||
|
continue-on-error: true
|
||||||
run: |
|
run: |
|
||||||
npm install sharp glob
|
node scripts/optimize-images.js &
|
||||||
|
node scripts/optimize-audio.js &
|
||||||
|
node scripts/optimize-json.js &
|
||||||
|
wait
|
||||||
|
|
||||||
- name: Optimize Images
|
- name: Check Optimization Status
|
||||||
run: node scripts/optimize-images.js
|
if: steps.sync.outputs.sync_status == 'updated' && steps.optimize_assets.outcome == 'failure'
|
||||||
|
run: |
|
||||||
- name: Optimize Audio
|
echo "资源优化过程中出现错误,请检查日志"
|
||||||
run: node scripts/optimize-audio.js
|
exit 1
|
||||||
|
|
||||||
- name: Optimize JSON
|
|
||||||
run: node scripts/optimize-json.js
|
|
||||||
|
|
||||||
- name: Check for changes
|
- name: Check for changes
|
||||||
|
if: steps.sync.outputs.sync_status == 'updated'
|
||||||
id: check_changes
|
id: check_changes
|
||||||
run: |
|
run: |
|
||||||
if [[ -n "$(git status --porcelain)" ]]; then
|
if [[ -n "$(git status --porcelain)" ]]; then
|
||||||
@ -108,10 +130,23 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Commit and push if changed
|
- name: Commit and push if changed
|
||||||
if: steps.check_changes.outputs.changes == 'true' && steps.sync.outputs.sync_status == 'success'
|
if: steps.sync.outputs.sync_status == 'updated' && steps.check_changes.outputs.changes == 'true'
|
||||||
run: |
|
run: |
|
||||||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git config --local user.name "github-actions[bot]"
|
git config --local user.name "github-actions[bot]"
|
||||||
|
|
||||||
|
# 获取更改的文件统计
|
||||||
|
IMAGES_CHANGED=$(git diff --name-only | grep -E "\.(png|jpg|jpeg|gif|webp)$" | wc -l)
|
||||||
|
AUDIO_CHANGED=$(git diff --name-only | grep -E "\.(mp3|wav|ogg)$" | wc -l)
|
||||||
|
JSON_CHANGED=$(git diff --name-only | grep -E "\.json$" | wc -l)
|
||||||
|
|
||||||
|
# 构建提交信息
|
||||||
|
COMMIT_MSG="🤖 自动优化资源\n\n"
|
||||||
|
COMMIT_MSG+="优化统计:\n"
|
||||||
|
COMMIT_MSG+="- 图片文件: ${IMAGES_CHANGED}个\n"
|
||||||
|
COMMIT_MSG+="- 音频文件: ${AUDIO_CHANGED}个\n"
|
||||||
|
COMMIT_MSG+="- JSON文件: ${JSON_CHANGED}个"
|
||||||
|
|
||||||
git add -A
|
git add -A
|
||||||
git commit -m "Automatically optimize assets"
|
git commit -m "$COMMIT_MSG"
|
||||||
git push origin HEAD:test -f
|
git push origin HEAD:test -f
|
Loading…
Reference in New Issue
Block a user