Skip to content

Commit 66b6d1f

Browse files
committed
run weekly_update hourly with multiple locations
1 parent b37a077 commit 66b6d1f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

.github/workflows/weekly_update.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
22
workflow_dispatch:
33
schedule:
4-
- cron: '5,25,45 * * * 5,6'
4+
- cron: '0 * * * 5,6'
55

66
name: weekly update
77
jobs:
@@ -29,18 +29,20 @@ jobs:
2929
run: |
3030
import datetime, glob, os, subprocess, sys
3131
32-
STALEDATA = 5
33-
GENERATED = {
32+
MAX_IN_RUN = 4
33+
STALE_DAYS = 5
34+
GENERATED = {
3435
"%s.md": "---\ntype: location\nlocation: %s\nmode: commits\n---\n",
3536
"%s_private.md": "---\ntype: location\nlocation: %s\nmode: all\n---\n",
3637
"%s_public.md": "---\ntype: location\nlocation: %s\nmode: contributions\n---\n",
3738
}
3839
3940
preset_list = subprocess.run(["most-active-github-users-counter", "--list-presets"], capture_output=True, text=True).stdout
4041
regenerated = False
42+
to_process = []
4143
4244
# generate markdown files for each preset
43-
expected = ["index.md"]
45+
expected = ["index.md", "README.md"] # shouldn't be deleted!
4446
flookup = {}
4547
for preset, title in sorted(line.split(" = ") for line in preset_list.strip().split("\n")):
4648
filename = preset.replace(" ", "_")
@@ -49,6 +51,7 @@ jobs:
4951
for name, content in GENERATED.items():
5052
expected.append(name % filename)
5153
if not os.path.exists(expected[-1]):
54+
to_process.append(filename)
5255
regenerated = True
5356
with open(expected[-1], "w") as f:
5457
f.write(content % filename)
@@ -60,28 +63,26 @@ jobs:
6063
regenerated = True
6164
6265
# find if any location data is stale
63-
get_mtime = lambda n: datetime.date.fromisoformat(subprocess.run(["git", "log", "-1", "--pretty=%as", n], capture_output=True, text=True).stdout.strip())
64-
locations = sorted([get_mtime(n), os.path.basename(n)] for n in glob.glob("_data/locations/*.yml"))
65-
today = datetime.date.today()
66-
to_process = None
66+
get_mtime = lambda n: datetime.date.fromisoformat(subprocess.run(["git", "log", "-1", "--pretty=%as", n], capture_output=True, text=True).stdout.strip())
67+
locations = sorted([get_mtime(n), os.path.basename(n)] for n in glob.glob("_data/locations/*.yml"))
68+
today = datetime.date.today()
6769
for mtime, filename in locations:
68-
if (today - mtime).days >= STALEDATA:
69-
to_process = os.path.splitext(filename)[0]
70-
break
70+
if (today - mtime).days >= STALE_DAYS:
71+
to_process.append(os.path.splitext(filename)[0])
7172
72-
if not regenerated and to_process is None:
73+
if not regenerated and len(to_process) == 0:
7374
sys.exit(0)
7475
7576
if regenerated:
7677
subprocess.run('git add *.md _data/locations/*.yml && git commit -am "regenerate location pages"', shell=True, check=True)
7778
78-
if to_process:
79-
preset = flookup[to_process]["preset"]
79+
for key in to_process[0:MAX_IN_RUN]:
80+
preset = flookup[key]["preset"]
8081
status = subprocess.run(["most-active-github-users-counter", "--token", os.environ["GITHUB_TOKEN"], "--preset", preset, "--output", "yaml"], capture_output=True, text=True)
8182
if status.returncode == 0:
82-
with open("_data/locations/%s.yml" % to_process, "w") as f:
83-
f.write("page: %s.html\ntitle: %s\n%s" % (to_process, flookup[to_process]["title"], status.stdout))
84-
subprocess.run('git add _data/locations/%s.yml && git commit -m "%s: updates for %s"' % (to_process, preset, today.isoformat()), shell=True, check=True)
83+
with open("_data/locations/%s.yml" % key, "w") as f:
84+
f.write("page: %s.html\ntitle: %s\n%s" % (key, flookup[key]["title"], status.stdout))
85+
subprocess.run('git add _data/locations/%s.yml && git commit -m "%s: updates for %s"' % (key, preset, today.isoformat()), shell=True, check=True)
8586
else:
8687
print("FAILED with exit code %d\n--- stdout ---\n%s\n--- stderr ---\n%s" % (status.returncode, status.stdout, status.stderr))
8788
sys.exit(1)

0 commit comments

Comments
 (0)