Skip to content

Generate contribution snake #170

Generate contribution snake

Generate contribution snake #170

Workflow file for this run

name: Generate contribution snake
on:
push:
branches:
- main
paths-ignore:
- "dist/**"
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
concurrency:
group: snake-${{ github.repository }}
cancel-in-progress: true
permissions:
contents: write
jobs:
snake:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# After a force-push or concurrent commits, local main can diverge from origin and
# git-auto-commit-action will fail to push (non-fast-forward). Reset to remote tip first.
- name: Sync with remote branch
run: |
git fetch origin "${{ github.ref_name }}"
git reset --hard "origin/${{ github.ref_name }}"
- name: Generate snake SVGs
uses: Platane/snk@v3.4.1
with:
github_user_name: ${{ github.repository_owner }}
# Double-quoted string so YAML does not treat # in hex colors as comments. Plain # matches snk README examples.
# Blue / periwinkle / violet — aligned with github-readme-activity-graph (tokyo-night).
outputs: "dist/github-snake.svg?color_dots=#f8fafc,#e0e7ff,#c7d2fe,#a5b4fc,#818cf8&color_snake=#7a95f5\ndist/github-snake-dark.svg?color_dots=#1a1b27,#3d4f73,#565f89,#7aa2f7,#bb9af7&color_snake=#7aa2f7"
- name: Normalize snake SVG canvas
run: |
python - <<'PY'
import pathlib
import re
paths = [
pathlib.Path("dist/github-snake.svg"),
pathlib.Path("dist/github-snake-dark.svg"),
]
viewbox_re = re.compile(r'viewBox="([-0-9.]+)\s+([-0-9.]+)\s+([0-9.]+)\s+([0-9.]+)"')
width_re = re.compile(r'width="([0-9.]+)"')
height_re = re.compile(r'height="([0-9.]+)"')
for path in paths:
text = path.read_text(encoding="utf-8")
m = viewbox_re.search(text)
if not m:
raise SystemExit(f"viewBox not found in {path}")
x, y, w, h = map(float, m.groups())
# snk currently emits a negative-origin canvas, which adds side padding.
# Convert to a zero-origin viewBox while preserving the right/bottom bounds.
new_w = w + x
new_h = h + y
if new_w <= 0 or new_h <= 0:
raise SystemExit(f"Invalid normalized dimensions for {path}: {new_w}x{new_h}")
text = viewbox_re.sub(f'viewBox="0 0 {new_w:g} {new_h:g}"', text, count=1)
text = width_re.sub(f'width="{new_w:g}"', text, count=1)
text = height_re.sub(f'height="{new_h:g}"', text, count=1)
path.write_text(text, encoding="utf-8")
PY
- name: Commit snake assets
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: update contribution snake"
file_pattern: "dist/*.svg"