@@ -12,91 +12,93 @@ jobs:
1212 daily_update :
1313 runs-on : ubuntu-20.04
1414 steps :
15- - name : Checkout code
16- uses : actions/checkout@v2
15+ - uses : actions/checkout@v2
1716 with :
1817 fetch-depth : 0
19- - name : Setup Go
18+ - name : setup Go
2019 uses : actions/setup-go@v2
2120 with :
2221 go-version : 1.17
23- - name : Build latest binary
22+ - name : build latest binary
2423 run : go get -d -v . && CGO_ENABLED=0 go install -v .
25- - name : Switch to gh-pages branch
24+ - name : switch to gh-pages branch
2625 run : |
2726 git checkout -b gh-pages origin/gh-pages
2827 git config user.name "eplus-bot"
2928 git config user.email "bot@eplus.dev"
30- - name : Perform update and push commits (if applicable)
29+ - name : perform update and push commits (if applicable)
30+ shell : python
31+ env :
32+ GITHUB_TOKEN : ${{ secrets.API_TOKEN }}
3133 run : |
3234 import csv, datetime, glob, os, re, subprocess, sys
3335
34- MAX_IN_RUN = 3
35- STALE_DAYS = 2
36- GENERATED = {
37- "%s.md": "---\ntype: location\nlocation: %s\nmode: commits\n---\n",
38- "%s_private.md": "---\ntype: location\nlocation: %s\nmode: all\n---\n",
39- "%s_public.md": "---\ntype: location\nlocation: %s\nmode: contributions\n---\n",
40- "rank_only/%s.json": "---\nlayout: rank_only\nlocation: %s\n---\n",
41- }
36+ MAX_IN_RUN = 3
37+ STALE_DAYS = 5
38+ GENERATED = {
39+ "%s.md": "---\ntype: location\nlocation: %s\nmode: commits\n---\n",
40+ "%s_private.md": "---\ntype: location\nlocation: %s\nmode: all\n---\n",
41+ "%s_public.md": "---\ntype: location\nlocation: %s\nmode: contributions\n---\n",
42+ "rank_only/%s.json": "---\nlayout: rank_only\nlocation: %s\n---\n",
43+ }
4244
43- subprocess.run("mkdir -p rank_only", shell=True, check=True)
44- preset_data = subprocess.run(["most-active-github-users-counter", "--list-presets"], capture_output=True, text=True).stdout
45- all_presets = dict([row.pop('preset'), row] for row in csv.DictReader(preset_data.split('\n')))
46- regenerated = False
47- to_process = []
45+ subprocess.run("mkdir -p rank_only", shell=True, check=True)
46+ preset_data = subprocess.run(["most-active-github-users-counter", "--list-presets"], capture_output=True, text=True).stdout
47+ all_presets = dict([row.pop('preset'), row] for row in csv.DictReader(preset_data.split('\n')))
48+ regenerated = False
49+ to_process = []
4850
49- # generate markdown files for each preset
50- expected = ["index.md", "README.md"] # shouldn't be deleted!
51- flookup = {}
52- for preset in sorted(all_presets.keys()):
53- filename = preset.replace(" ", "_")
54- flookup[filename] = preset
55- expected.append("_data/locations/%s.yml" % filename)
56- if not os.path.exists(expected[-1]):
57- to_process.append(filename)
58- else:
59- match = re.search("^definition_checksum: (\w+)$", open(expected[-1]).read(), re.M)
60- if not match or match.group(1) != all_presets[preset]['definition_checksum']:
61- to_process.append(filename)
62- for name, content in GENERATED.items():
63- expected.append(name % filename)
64- if not os.path.exists(expected[-1]):
65- regenerated = True
66- with open(expected[-1], "w") as f:
67- f.write(content % filename)
51+ # generate markdown files for each preset
52+ expected = ["index.md", "README.md"] # shouldn't be deleted!
53+ flookup = {}
54+ for preset in sorted(all_presets.keys()):
55+ filename = preset.replace(" ", "_")
56+ flookup[filename] = preset
57+ expected.append("_data/locations/%s.yml" % filename)
58+ if not os.path.exists(expected[-1]):
59+ to_process.append(filename)
60+ else:
61+ match = re.search("^definition_checksum: (\w+)$", open(expected[-1]).read(), re.M)
62+ if not match or match.group(1) != all_presets[preset]['definition_checksum']:
63+ to_process.append(filename)
64+ for name, content in GENERATED.items():
65+ expected.append(name % filename)
66+ if not os.path.exists(expected[-1]):
67+ regenerated = True
68+ with open(expected[-1], "w") as f:
69+ f.write(content % filename)
6870
69- # remove files for presets no longer supported (if any)
70- for filename in sorted(glob.glob("*.md") + glob.glob("_data/locations/*.yml") + glob.glob("rank_only/*.json")):
71- if filename not in expected:
72- os.remove(filename)
73- regenerated = True
71+ # remove files for presets no longer supported (if any)
72+ for filename in sorted(glob.glob("*.md") + glob.glob("_data/locations/*.yml") + glob.glob("rank_only/*.json")):
73+ if filename not in expected:
74+ os.remove(filename)
75+ regenerated = True
7476
75- # find if any location data is stale
76- get_mtime = lambda n: datetime.date.fromisoformat(subprocess.run(["git", "log", "-1", "--pretty=%as", n], capture_output=True, text=True).stdout.strip())
77- locations = sorted([get_mtime(n), os.path.basename(n)] for n in glob.glob("_data/locations/*.yml"))
78- today = datetime.date.today()
79- for mtime, filename in locations:
80- if (today - mtime).days >= STALE_DAYS:
81- to_process.append(os.path.splitext(filename)[0])
77+ # find if any location data is stale
78+ get_mtime = lambda n: datetime.date.fromisoformat(subprocess.run(["git", "log", "-1", "--pretty=%as", n], capture_output=True, text=True).stdout.strip())
79+ locations = sorted([get_mtime(n), os.path.basename(n)] for n in glob.glob("_data/locations/*.yml"))
80+ today = datetime.date.today()
81+ for mtime, filename in locations:
82+ if (today - mtime).days >= STALE_DAYS:
83+ to_process.append(os.path.splitext(filename)[0])
8284
83- if not regenerated and len(to_process) == 0:
84- sys.exit(0)
85+ if not regenerated and len(to_process) == 0:
86+ sys.exit(0)
8587
86- if regenerated:
87- subprocess.run('git add *.md _data/locations/*.yml rank_only/*.json && git commit -am "regenerate location pages"', shell=True, check=True)
88+ if regenerated:
89+ subprocess.run('git add *.md _data/locations/*.yml rank_only/*.json && git commit -am "regenerate location pages"', shell=True, check=True)
8890
89- for key in to_process[0:MAX_IN_RUN]:
90- print("Running: %s" % key)
91- preset = flookup[key]
92- status = subprocess.run(["most-active-github-users-counter", "--token", os.environ["GITHUB_TOKEN"], "--preset", preset, "--output", "yaml"], capture_output=True, text=True)
93- if status.returncode == 0:
94- with open("_data/locations/%s.yml" % key, "w") as f:
95- f.write("page: %s.html\n%s" % (key, status.stdout))
96- subprocess.run('git add _data/locations/%s.yml && git commit -m "%s: updates for %s"' % (key, preset, today.isoformat()), shell=True, check=True)
97- else:
98- subprocess.run("git push origin gh-pages", shell=True) # push successful commits, if any
99- print("FAILED with exit code %d\n--- stdout ---\n%s\n--- stderr ---\n%s" % (status.returncode, status.stdout, status.stderr))
100- sys.exit(1)
91+ for key in to_process[0:MAX_IN_RUN]:
92+ print("Running: %s" % key)
93+ preset = flookup[key]
94+ status = subprocess.run(["most-active-github-users-counter", "--token", os.environ["GITHUB_TOKEN"], "--preset", preset, "--output", "yaml"], capture_output=True, text=True)
95+ if status.returncode == 0:
96+ with open("_data/locations/%s.yml" % key, "w") as f:
97+ f.write("page: %s.html\n%s" % (key, status.stdout))
98+ subprocess.run('git add _data/locations/%s.yml && git commit -m "%s: updates for %s"' % (key, preset, today.isoformat()), shell=True, check=True)
99+ else:
100+ subprocess.run("git push origin gh-pages", shell=True) # push successful commits, if any
101+ print("FAILED with exit code %d\n--- stdout ---\n%s\n--- stderr ---\n%s" % (status.returncode, status.stdout, status.stderr))
102+ sys.exit(1)
101103
102- subprocess.run("git push origin gh-pages", shell=True, check=True)
104+ subprocess.run("git push origin gh-pages", shell=True, check=True)
0 commit comments