From 06ea04e31e5bd09e4af6cc536eaffa655c18bae7 Mon Sep 17 00:00:00 2001 From: Constrat <56174894+Constrat@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:53:24 +0100 Subject: [PATCH] ci: optimize templates perf and fixes --- .github/workflows/optimize-templates.yml | 50 +++++++++++++++--------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/optimize-templates.yml b/.github/workflows/optimize-templates.yml index 0e04df296d..aa53489d7a 100644 --- a/.github/workflows/optimize-templates.yml +++ b/.github/workflows/optimize-templates.yml @@ -21,7 +21,7 @@ on: required: false jobs: - check-and-optimize-png: + optimize-png: runs-on: ubuntu-latest steps: - name: Checkout repository @@ -30,9 +30,27 @@ jobs: 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: Run optimization script run: | - python3 optimize-templates.py + python3 tools/OptimizeTemplates/optimize_templates.py - name: Commit changes id: commit_changes @@ -42,25 +60,21 @@ jobs: git add . - $commit_msg = "${{ github.event.inputs.commit_message }}" - if (-not [string]::IsNullOrWhiteSpace($commit_msg)) { - $commit_msg = $commit_msg.Trim() - } else { - $commit_msg = "chore: Auto Templates Optimization" - } - git commit -m "$commit_msg" -m "[skip changelog]" - if ($LASTEXITCODE -eq 0) { - Write-Output "have_commits=True" >> $env:GITHUB_OUTPUT - } - - git pull origin $(git rev-parse --abbrev-ref HEAD) --unshallow --rebase - - - name: Cancelling - if: steps.commit_changes.outputs.have_commits != 'True' - uses: andymckay/cancel-action@0.5 + 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]" + echo "have_commits=True" >> $GITHUB_ENV + git pull origin $(git rev-parse --abbrev-ref HEAD) --unshallow --rebase + 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 }}