Skip to content

Commit 1ed3aec

Browse files
[gh-pages] Generate timestamps.json file w/ git timestamps for sources
For the GH Pages deployment, this change generates a timestamps.json file that maps each shortname in the repo to a timestamp representing the time for the most recent commit of corresponding Bikeshed source file for that shortname — enabling any downstream users/consumers of the deployed GH Pages specs to have accurate last-committed data for all sources.
1 parent c6ce86e commit 1ed3aec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bin/build-index.py

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os.path
1010
import re
1111
import sys
12+
import subprocess
1213
from collections import defaultdict
1314

1415
from html.parser import HTMLParser
@@ -59,6 +60,13 @@ def handle_endtag(self, tag):
5960
return parser.title if parser.done else None
6061

6162

63+
def get_date_authored_timestamp_from_git(path):
64+
source = os.path.realpath(path)
65+
proc = subprocess.run(["git", "log", "-1", "--format=%at", source],
66+
capture_output = True, encoding = "utf_8")
67+
return int(proc.stdout.splitlines()[-1])
68+
69+
6270
def get_bs_spec_metadata(folder_name, path):
6371
spec = Spec(path)
6472
spec.assembleDocument()
@@ -84,6 +92,7 @@ def get_bs_spec_metadata(folder_name, path):
8492
shortname = spec.md.shortname
8593

8694
return {
95+
"timestamp": get_date_authored_timestamp_from_git(path),
8796
"shortname": shortname,
8897
"level": level,
8998
"title": spec.md.title,
@@ -112,6 +121,9 @@ def create_symlink(shortname, spec_folder):
112121
"""Creates a <shortname> symlink pointing to the given <spec_folder>.
113122
"""
114123

124+
if spec_folder in timestamps:
125+
timestamps[shortname] = timestamps[spec_folder]
126+
115127
try:
116128
os.symlink(spec_folder, shortname)
117129
except OSError:
@@ -134,6 +146,7 @@ def create_symlink(shortname, spec_folder):
134146
constants.setErrorLevel("nothing")
135147

136148
specgroups = defaultdict(list)
149+
timestamps = defaultdict(list)
137150

138151
for entry in os.scandir("."):
139152
if entry.is_dir(follow_symlinks=False):
@@ -145,6 +158,7 @@ def create_symlink(shortname, spec_folder):
145158
html_file = os.path.join(entry.path, "Overview.html")
146159
if os.path.exists(bs_file):
147160
metadata = get_bs_spec_metadata(entry.name, bs_file)
161+
timestamps[entry.name] = metadata["timestamp"]
148162
elif os.path.exists(html_file):
149163
metadata = get_html_spec_metadata(entry.name, html_file)
150164
else:
@@ -186,6 +200,9 @@ def create_symlink(shortname, spec_folder):
186200
if shortname == "css-snapshot":
187201
create_symlink("css", currentWorkDir)
188202

203+
with open('./timestamps.json', 'w') as f:
204+
json.dump(dict(sorted(timestamps.items())), f, indent = 2)
205+
189206
with open("./index.html", mode='w', encoding="UTF-8") as f:
190207
template = jinja_env.get_template("index.html.j2")
191208
f.write(template.render(specgroups=specgroups))

0 commit comments

Comments
 (0)