Update Google Scholar Citations #40
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 Google Scholar Citations | |
| on: | |
| # Add this line to make it accessible to other workflows | |
| workflow_call: | |
| schedule: | |
| - cron: "0 0 * * 1" # Monday | |
| - cron: "0 0 * * 3" # Wednesday | |
| - cron: "0 0 * * 5" # Friday | |
| workflow_dispatch: | |
| jobs: | |
| update-citations: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| # Use PAT if provided, otherwise fall back to GitHub token so `act` runs cleanly. | |
| token: ${{ secrets.PAT || github.token }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| run: | | |
| echo "π§ Installing dependencies..." | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Save current citations.yml hash | |
| id: before | |
| run: | | |
| echo "π¦ Checking existing citations.yml hash..." | |
| if [ -f _data/citations.yml ]; then | |
| sha_before=$(sha256sum _data/citations.yml | awk '{print $1}') | |
| echo "sha_before=$sha_before" >> $GITHUB_OUTPUT | |
| echo "π SHA before: $sha_before" | |
| else | |
| echo "sha_before=none" >> $GITHUB_OUTPUT | |
| echo "π No existing citations.yml file found." | |
| fi | |
| - name: Run citation update script | |
| id: run_citation_update | |
| shell: bash | |
| run: | | |
| set +e | |
| max_attempts=2 | |
| attempt=1 | |
| status=1 | |
| while [ $attempt -le $max_attempts ]; do | |
| echo "π Attempt $attempt/$max_attempts: running citation update (timeout 180s)..." | |
| start_time=$(date) | |
| timeout 360 python bin/update_scholar_citations.py | |
| status=$? | |
| end_time=$(date) | |
| if [ $status -eq 0 ]; then | |
| echo "β Citation update succeeded on attempt $attempt (started at $start_time, ended at $end_time)." | |
| echo "β Citation update succeeded." >> $GITHUB_STEP_SUMMARY | |
| break | |
| else | |
| echo "β Citation update failed on attempt $attempt with exit code $status (started at $start_time, ended at $end_time)." | |
| if [ $attempt -lt $max_attempts ]; then | |
| echo "β³ Retrying after brief pause..." | |
| sleep 5 | |
| fi | |
| fi | |
| attempt=$((attempt+1)) | |
| done | |
| if [ $status -ne 0 ]; then | |
| echo "β Citation update script failed after $max_attempts attempt(s) with exit code $status." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| set -e | |
| - name: Save new citations.yml hash | |
| id: after | |
| run: | | |
| echo "π Checking updated citations.yml hash..." | |
| if [ -f _data/citations.yml ]; then | |
| sha_after=$(sha256sum _data/citations.yml | awk '{print $1}') | |
| echo "sha_after=$sha_after" >> $GITHUB_OUTPUT | |
| echo "π SHA after: $sha_after" | |
| else | |
| echo "sha_after=none" >> $GITHUB_OUTPUT | |
| echo "π citations.yml was not created or is missing." | |
| fi | |
| - name: Report citations.yml change in summary | |
| run: | | |
| echo "π Comparing citation file hashes..." | |
| if [ "${{ steps.before.outputs.sha_before }}" != "${{ steps.after.outputs.sha_after }}" ]; then | |
| echo "β _data/citations.yml was updated." | |
| echo "β _data/citations.yml was updated." >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "βΉοΈ _data/citations.yml was not changed." | |
| echo "βΉοΈ _data/citations.yml was not changed." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "actions@github.com" | |
| git config --local user.name "GitHub Actions" | |
| echo "π§ Git configured." | |
| - name: Commit and push if changed | |
| if: ${{ !env.ACT }} # skip pushing when running under act | |
| run: | | |
| git add _data/citations.yml | |
| git diff --staged --quiet || ( | |
| echo "π€ Committing and pushing changes..." | |
| git commit -m "Update Google Scholar citations" | |
| git push | |
| ) |