Fix broken Star History chart #3
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 star history | |
| on: | |
| pull_request: | |
| paths: | |
| - ".github/workflows/update-star-history.yml" | |
| - "scripts/generate_star_history.py" | |
| schedule: | |
| - cron: "17 */6 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Generate star history | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: python scripts/generate_star_history.py /tmp/star-history.svg | |
| - name: Validate SVG | |
| run: python -c 'import xml.etree.ElementTree as ET; ET.parse("/tmp/star-history.svg")' | |
| - name: Publish to star-history branch | |
| if: github.event_name != 'pull_request' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| encoded="$(base64 -w 0 /tmp/star-history.svg)" | |
| current="$( | |
| gh api \ | |
| "repos/${GITHUB_REPOSITORY}/contents/assets/star-history.svg?ref=star-history" | |
| )" | |
| current_content="$(jq -r '.content' <<< "${current}" | tr -d '\n')" | |
| if [[ "${encoded}" == "${current_content}" ]]; then | |
| echo "Star history is already up to date." | |
| exit 0 | |
| fi | |
| gh api \ | |
| --method PUT \ | |
| "repos/${GITHUB_REPOSITORY}/contents/assets/star-history.svg" \ | |
| -f branch=star-history \ | |
| -f message="Update star history" \ | |
| -f content="${encoded}" \ | |
| -f sha="$(jq -r '.sha' <<< "${current}")" |