From 6867beab9c6ede301e5b195451ed8107a8441bdf Mon Sep 17 00:00:00 2001 From: Tien Nguyen Minh Date: Sun, 19 Apr 2026 08:34:19 +0700 Subject: [PATCH] ci(demo): add workflow rendering every card for every theme (#1) Runs on push to main (skipping its own demo/output/markdown commits), builds the ghstats binary, renders every theme for the repo owner, and writes a demo/README.md gallery back to main. --- .github/workflows/demo.yml | 102 +++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .github/workflows/demo.yml diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml new file mode 100644 index 00000000..589dc6f3 --- /dev/null +++ b/.github/workflows/demo.yml @@ -0,0 +1,102 @@ +name: Demo + +on: + push: + branches: [main] + paths-ignore: + - "demo/**" + - "output/**" + - "**.md" + - "LICENSE" + workflow_dispatch: + +permissions: + contents: write + +concurrency: + group: demo + cancel-in-progress: true + +jobs: + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-go@v6 + with: + go-version: "1.26" + cache: true + + - name: Build ghstats + run: go build -trimpath -ldflags="-s -w" -o ghstats . + + - name: Render every card for every theme + env: + GITHUB_TOKEN: ${{ secrets.GHSTATS_TOKEN }} + run: | + rm -rf demo + mkdir -p demo + ./ghstats \ + -user "${{ github.repository_owner }}" \ + -themes all \ + -tz Asia/Saigon \ + -out demo + + - name: Write demo README + env: + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.repository }} + run: | + cards=( + profile-details + repos-per-language + most-commit-language + stats + productive-time + contributions + most-commit-language-all-time + productive-time-all-time + contributions-all-time + ) + themes=$(./ghstats -list-themes) + { + echo "# ghstats demo gallery" + echo + echo "Every card in every theme, rendered for [\`$OWNER\`](https://github.com/$OWNER)." + echo + echo "Auto-generated by [\`.github/workflows/demo.yml\`](../.github/workflows/demo.yml) on each push to \`main\`. Do not edit by hand." + echo + echo "## Themes" + echo + for theme in $themes; do + echo "- [\`$theme\`](#$theme)" + done + echo + for theme in $themes; do + dir="demo/$theme" + [ -d "$dir" ] || continue + echo "## $theme" + echo + for card in "${cards[@]}"; do + svg="$dir/$card.svg" + [ -f "$svg" ] || continue + echo "![$card](./$theme/$card.svg)" + done + echo + echo "[back to top](#themes)" + echo + done + } > demo/README.md + + - name: Commit demo back to main + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add demo + if git diff --cached --quiet; then + echo "No demo changes to commit." + exit 0 + fi + git commit -m "chore(demo): regenerate gallery" + git push origin HEAD:${{ github.ref_name }}