Skip to content

Commit

Permalink
add build 4 and add diff links
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinafyi committed Jul 6, 2024
1 parent 8182828 commit b2cf75b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
64 changes: 55 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import html
import shutil
import subprocess
import dataclasses

VERSION_CSV = 'versions.csv'
OUT_PATH = './out'
Expand All @@ -15,31 +16,76 @@

# date +"%Y-%m-%d %H:%M:%S%z"

@dataclasses.dataclass
class Row:
id: str
flake: str
path: str
date: str
desc: str

diff_url = 'https://github.com/katrinafyi/pac-nix/compare/{0}...{1}'

def commit(v: Row) -> str | None:
front, back = 'github:katrinafyi/pac-nix/', '#aslp_web'
if v.flake.startswith(front) and v.flake.endswith(back):
return v.flake.replace(front, '', 1).replace(back, '', 1)
return None

def rows(versions: list[Row]):
for i, ver in enumerate(versions):
(v,flake,path,t,desc) = ver.id, ver.flake, ver.path, ver.date, ver.desc

i -= 1
diff = ''
# find previous pac-nix commit
while (c := commit(ver)) and i >= 0:
prev = versions[i]
if p := commit(prev):
url = diff_url.format(p, c)
diff = f'<small>(<a href="{q(url)}/" target="_blank" rel="noopener noreferrer">diff from {q(prev.id)}</a>)</small>'
break
i -= 1

yield f'''
<!--
{q(flake)}
{q(path)}
-->
<a href="{q(v)}/">build {q(v)}</a>
({q(desc)})
{diff}
<small><code>{q(t)}</code></small>
'''.strip().encode('ascii')


def main():
os.makedirs(OUT_PATH)

versions = []
data = []
with open(VERSION_CSV) as f:
for l in f:
if not l.strip(): continue
versions.append([x.strip() for x in l.strip().split(',')])
data.append([x.strip() for x in l.strip().split(',')])

versions = [Row(v,flake,path,t,desc) for v,flake,path,t,desc in data]

print(*versions, sep='\n')
for v,flake,path,time in versions:
print('building', v, flake)
result = 'result_' + v
for v in versions:
print('building', v)
result = 'result_' + v.id

subprocess.check_call(['nix', 'build', '-L', '--out-link', result, flake])
subprocess.check_call(['nix', 'build', '-L', '--out-link', result, v.flake])

shutil.copytree(result + '/' + path + '/.', OUT_PATH + '/' + v, copy_function=shutil.copy)
shutil.copytree(result + '/' + v.path + '/.', OUT_PATH + '/' + v.id, copy_function=shutil.copy)

shutil.copy('./index.html', OUT_PATH)
shutil.copy('./reset.css', OUT_PATH)

listing = [f'<a href="{q(v)}/">build {q(v)}</a> (<code>{q(t)}</code>)<!-- {q(flake)} {q(path)} -->'.encode('ascii') for v,flake,path,t in versions]
listing = list(rows(versions))

latest = listing[-1]
other = b'\n'.join(b'<li>'+x+b'</li>' for x in reversed(listing))
other = b'\n\n'.join(b'<li>'+x+b'</li>' for x in reversed(listing))

with open(OUT_PATH + '/index.html', 'rb') as f:
html = f.read()
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1>ASLp Web</h1>
<summary>All versions</summary>
<p>
<ul>
<!--VERSIONS-->
<!--VERSIONS-->
</ul>
</p>
</details></p>
Expand Down
7 changes: 4 additions & 3 deletions versions.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1,github:katrinafyi/pac-nix/35227e069861203638c88e0b47139ce283c25b89#aslp_web,lib/ocaml/4.14.1/site-lib/aslp_web/,2024-06-25 16:14:52+1000
2,github:katrinafyi/pac-nix/807df4aececfdf4c4010af42edbe1ce64785928f#aslp_web,lib/ocaml/4.14.1/site-lib/aslp_web/,2024-06-28 16:25:48+1000
3,github:katrinafyi/pac-nix/0828d849a8bc11df73c05233067f390c310bc484#aslp_web,lib/ocaml/5.1.1/site-lib/aslp_web/,2024-07-03 14:44:14+1000
1,github:katrinafyi/pac-nix/35227e069861203638c88e0b47139ce283c25b89#aslp_web,lib/ocaml/4.14.1/site-lib/aslp_web/,2024-06-25 16:14:52+1000,initial build
2,github:katrinafyi/pac-nix/807df4aececfdf4c4010af42edbe1ce64785928f#aslp_web,lib/ocaml/4.14.1/site-lib/aslp_web/,2024-06-28 16:25:48+1000,evaluation environment caching
3,github:katrinafyi/pac-nix/0828d849a8bc11df73c05233067f390c310bc484#aslp_web,lib/ocaml/5.1.1/site-lib/aslp_web/,2024-07-03 14:44:14+1000,ocaml 5
4,github:katrinafyi/pac-nix/08a867d1d300eb6e17cf7c5ecbe75fe5d2542d9e#aslp_web,lib/ocaml/5.1.1/site-lib/aslp_web/,2024-07-06 21:57:54+1000,web worker

0 comments on commit b2cf75b

Please sign in to comment.