File tree Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Leaderboard
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+ workflow_dispatch : {}
7+
8+ jobs :
9+
10+ build :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - uses : actions/checkout@v4
14+
15+ - name : Update Leaderboard in README.md
16+ run : ./leaderboard-replace.sh
17+
18+ - name : Commit and Push changes
19+ run : |
20+ git config --global user.name "${GITHUB_ACTOR}"
21+ git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
22+ git commit -am "README.md: update leaderboard" \
23+ && git push \
24+ || true
25+
Original file line number Diff line number Diff line change @@ -3,3 +3,9 @@ Advent of Code 2024
33
44See https://adventofcode.com/2024
55
6+ [ // ] : # ( LEADERBOARD_BEGIN )
7+
8+ > user ** fxnn** (6 stars, last one at 2024-12-03T09:54:00Z)
9+
10+ [ // ] : # ( LEADERBOARD_END )
11+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+ set -o pipefail
4+
5+ aoc_year=2024
6+ export aoc_username=" fxnn"
7+
8+ [ -z " ${AOC_SESSION_COOKIE} " ] && { echo " ERROR: missing AOC_SESSION_COOKIE" ; exit 1; }
9+ [ -z " ${AOC_LEADERBOARD_ID} " ] && { echo " ERROR: missing AOC_LEADERBOARD_ID" ; exit 1; }
10+
11+ curl \
12+ -sS \
13+ -H " Cookie: ${AOC_SESSION_COOKIE} " \
14+ https://adventofcode.com/${aoc_year} /leaderboard/private/view/${AOC_LEADERBOARD_ID} .json \
15+ | jq -r \
16+ ' .members
17+ | values[]
18+ | select(.name==$ENV.aoc_username)
19+ | "user **"
20+ + .name
21+ + "** ("
22+ + (.stars | tostring)
23+ + " stars, last one at "
24+ + (.last_star_ts | todateiso8601)
25+ + ")"'
26+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ export leaderboard=" $( ./leaderboard-fetch.sh) "
5+
6+ awk \
7+ '
8+ BEGIN {
9+ isLeaderboard="false" ;
10+ isLeaderboardPrinted="false" ;
11+ }
12+ /^.*\(LEADERBOARD_BEGIN\)$/ {
13+ isLeaderboard="true" ;
14+ isLeaderboardPrinted="false" ;
15+ print $0 ;
16+ next ;
17+ }
18+ /^.*\(LEADERBOARD_END\)$/ {
19+ isLeaderboard="false" ;
20+ print $0 ;
21+ next ;
22+ }
23+ isLeaderboard=="true" && isLeaderboardPrinted=="false" {
24+ print "" ;
25+ print "> " ENVIRON["leaderboard"] ;
26+ print "" ;
27+ isLeaderboardPrinted="true" ;
28+ next ;
29+ }
30+ isLeaderboard=="true" && isLeaderboardPrinted=="false" {
31+ next ;
32+ }
33+ isLeaderboard=="false" {
34+ print $0 ;
35+ }
36+ ' \
37+ README.md \
38+ > README.md.tmp
39+
40+ mv README.md.tmp README.md
41+
You can’t perform that action at this time.
0 commit comments