forked from MaaAssistantArknights/MaaAssistantArknights
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (72 loc) · 2.51 KB
/
optimize-templates.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Auto Optimize PNG Templates
on:
push:
branches:
- "dev"
paths:
- "resource/**/*.png"
- "docs/.vuepress/public/image/**"
- "website/apps/web/public/**"
- "website/apps/web/src/assets/links/**"
workflow_dispatch:
inputs:
commit_message:
description: "Commit Message"
type: string
required: false
jobs:
optimize-png:
# Skip workflow to prevent double consecutive runs
if: ${{ github.event.head_commit.author.email != '41898282+github-actions[bot]@users.noreply.github.com' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
show-progress: false
persist-credentials: false
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Cache Python packages
id: cache_python
if: always()
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}/lib/python3.11/site-packages
key: ${{ runner.os }}-pip-optimize-templates-${{ hashFiles('./tools/OptimizeTemplates/requirements.txt') }}
- name: Install dependencies
if: steps.cache_python.outputs.cache-hit != 'true'
run: |
pip install -r tools/OptimizeTemplates/requirements.txt
- name: Setup oxipng
uses: baptiste0928/cargo-install@v3
with:
crate: oxipng
- name: Run optimize_templates
run: |
python3 tools/OptimizeTemplates/optimize_templates.py
- name: Commit changes
id: commit_changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
commit_msg="${{ github.event.inputs.commit_message }}"
if [ -z "$commit_msg" ]; then
commit_msg="chore: Auto Templates Optimization"
fi
git commit -m "$commit_msg" -m "[skip changelog]"
git pull origin $(git rev-parse --abbrev-ref HEAD) --unshallow --rebase
echo "have_commits=True" >> $GITHUB_OUTPUT
fi
- name: Push changes
if: steps.commit_changes.outputs.have_commits == 'True'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MAA_RESOURCE_SYNC }}
branch: ${{ github.ref }}