From 0f71f0f3e4c9ced10dc1e6a8b375cd954251dae1 Mon Sep 17 00:00:00 2001 From: autoactions <125431179+autoactions@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:33:38 +0800 Subject: [PATCH] Add files via upload --- .github/workflows/optimize-assets.yml | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/optimize-assets.yml diff --git a/.github/workflows/optimize-assets.yml b/.github/workflows/optimize-assets.yml new file mode 100644 index 00000000000..38fff58a7aa --- /dev/null +++ b/.github/workflows/optimize-assets.yml @@ -0,0 +1,72 @@ +name: Optimize Assets + +on: + workflow_dispatch: # 允许手动触发 + +jobs: + optimize: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # 获取完整历史以便进行比较 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'npm' + + # 添加 FFmpeg 缓存 + - name: Cache FFmpeg + id: cache-ffmpeg + uses: actions/cache@v3 + with: + path: /usr/bin/ffmpeg + key: ${{ runner.os }}-ffmpeg + + - name: Install FFmpeg + if: steps.cache-ffmpeg.outputs.cache-hit != 'true' + run: | + sudo apt-get update + sudo apt-get install -y ffmpeg + + # 添加 node_modules 缓存 + - name: Cache node_modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: node_modules + key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node-modules- + + - name: Install dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: | + npm install sharp + + - name: Optimize Images + run: node scripts/optimize-images.js + + - name: Optimize Audio + run: node scripts/optimize-audio.js + + - name: Check for changes + id: check_changes + run: | + if [[ -n "$(git status --porcelain)" ]]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Commit and push if changed + if: steps.check_changes.outputs.changes == 'true' + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add -A + git commit -m "Automatically optimize assets" + git push