Update LeetCode Grid #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update LeetCode Grid | |
| permissions: | |
| contents: write | |
| actions: write | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: ["Sync Leetcode"] | |
| types: | |
| - completed | |
| jobs: | |
| update-readme: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Restore last processed commit | |
| id: last_commit_cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .last_leetcode_commit | |
| key: leetcode-last-commit | |
| # - name: Load last processed commit SHA | |
| # id: last_commit | |
| # run: | | |
| # if [ -f .last_leetcode_commit ]; then | |
| # echo "last=$(cat .last_leetcode_commit)" >> $GITHUB_OUTPUT | |
| # else | |
| # echo "last=" >> $GITHUB_OUTPUT | |
| # fi | |
| # - name: Check for Solutions/ changes since last run | |
| # id: changes | |
| # run: | | |
| # git fetch --depth=100 origin ${{ github.ref_name }} | |
| # if [ -n "${{ steps.last_commit.outputs.last }}" ]; then | |
| # echo "Comparing from ${{ steps.last_commit.outputs.last }} to HEAD" | |
| # git diff --name-only ${{ steps.last_commit.outputs.last }}..HEAD > files.txt | |
| # else | |
| # echo "No previous commit recorded, checking current HEAD only" | |
| # git show --name-only --pretty="" HEAD > files.txt | |
| # fi | |
| # if grep -q '^Solutions/' files.txt; then | |
| # echo "changed=true" >> $GITHUB_OUTPUT | |
| # else | |
| # echo "changed=false" >> $GITHUB_OUTPUT | |
| # fi | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| pip install pyyaml requests | |
| - name: Restore LeetCode API cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: .leetcode_cache.json | |
| key: leetcode-cache-${{ github.run_id }} | |
| restore-keys: | | |
| leetcode-cache- | |
| - name: Generate LeetCode README table | |
| run: | | |
| python ./Scripts/update_project_readme.py | |
| - name: Save updated cache | |
| if: always() | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: .leetcode_cache.json | |
| key: leetcode-cache-${{ github.run_id }} | |
| - name: Commit and push changes | |
| run: | | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git add README.md Site_README.md | |
| git diff-index --quiet HEAD || git commit -m "[Auto] Update LeetCode README table" | |
| git fetch origin ${{ github.ref_name }} | |
| git rebase origin/${{ github.ref_name }} | |
| git push origin HEAD:${{ github.ref_name }} | |
| - name: Save last processed commit | |
| if: always() | |
| run: | | |
| git rev-parse HEAD > .last_leetcode_commit |