11name : Update LeetCode Grid
22
33on :
4- # push:
5- # paths:
6- # - "Solutions/**"
7- # - "Scripts/update_project_readme.py"
84 workflow_dispatch :
95 workflow_run :
106 workflows : ["Sync Leetcode"]
1410jobs :
1511 update-readme :
1612 runs-on : ubuntu-latest
17- if : >
18- github.event.workflow_run.conclusion == 'success' &&
19- contains(github.event.workflow_run.head_commit.message, 'Solutions/')
13+ if : github.event.workflow_run.conclusion == 'success'
2014
2115 steps :
2216 - name : Checkout repository
2317 uses : actions/checkout@v5
18+ with :
19+ ref : ${{ github.event.workflow_run.head_branch }}
20+
21+ - name : Check for Solutions/ changes
22+ id : changes
23+ run : |
24+ git fetch origin ${{ github.event.workflow_run.head_sha }}
25+ git diff --name-only ${{ github.event.workflow_run.head_sha }}^ ${{ github.event.workflow_run.head_sha }} > files.txt
26+ if grep -q '^Solutions/' files.txt; then
27+ echo "changed=true" >> $GITHUB_OUTPUT
28+ else
29+ echo "changed=false" >> $GITHUB_OUTPUT
30+ fi
2431
2532 - name : Set up Python
33+ if : steps.changes.outputs.changed == 'true'
2634 uses : actions/setup-python@v6
2735 with :
2836 python-version : " 3.11"
2937
3038 - name : Install dependencies
39+ if : steps.changes.outputs.changed == 'true'
3140 run : |
3241 pip install pyyaml requests
3342
3443 - name : Restore LeetCode API cache
44+ if : steps.changes.outputs.changed == 'true'
3545 uses : actions/cache@v4
3646 with :
3747 path : .leetcode_cache.json
3848 key : leetcode-cache
3949
4050 - name : Generate LeetCode README table
51+ if : steps.changes.outputs.changed == 'true'
4152 run : |
42- python ./Scripts/update_project_readme.py
43-
53+ python ./Scripts/update_project_readme.py
54+
4455 - name : Save updated cache
45- if : always()
56+ if : always() && steps.changes.outputs.changed == 'true'
4657 uses : actions/cache/save@v4
4758 with :
4859 path : .leetcode_cache.json
4960 key : leetcode-cache
5061
5162 - name : Commit and push changes
63+ if : steps.changes.outputs.changed == 'true'
5264 run : |
5365 git config --local user.name "github-actions[bot]"
5466 git config --local user.email "github-actions[bot]@users.noreply.github.com"
5971 git fetch origin ${{ github.ref_name }}
6072 git rebase origin/${{ github.ref_name }}
6173
62- git push origin HEAD:${{ github.ref_name }}
74+ git push origin HEAD:${{ github.ref_name }}
0 commit comments