| | @@ -7,7 +7,7 @@ |
| 7 | 7 | any web server. Nothing runs in the reader's browser; the code on the |
| 8 | 8 | tour's pages is run here, by ./raz, and the output shown is what it |
| 9 | 9 | printed, so a lesson that stops working fails the build. The home page |
| 10 | | -offers the latest release's tarball, made by make dist from the tag. |
| 10 | +offers every release's tarball, made by make dist from its tag. |
| 11 | 11 | |
| 12 | 12 | Lessons are site/content/<tour>/NN-name.txt, one folder to a tour (see |
| 13 | 13 | TOURS below): |
| | @@ -315,33 +315,42 @@ |
| 315 | 315 | body = '<div class="spec">%s</div>' % p.stdout |
| 316 | 316 | write("spec.html", page("The raz report", body, 0, "spec")) |
| 317 | 317 | |
| 318 | +# The first release whose tarball the site offers: the first with the |
| 319 | +# manual, which make dist packs |
| 320 | +FIRST_RELEASE = "v0.7.1" |
| 321 | + |
| 318 | 322 | def build_download(): |
| 319 | | - """The latest release's tarball, in public/download/ with its SHA-256 |
| 320 | | - and /download/latest leading to it; (version, file name, SHA-256). |
| 321 | | - It is made of the tag's own checkout, not of the tree at hand, and |
| 322 | | - kept in build/ to be made once.""" |
| 323 | + """Every release's tarball from FIRST_RELEASE on, in public/download/ |
| 324 | + with its SHA-256, and /download/latest leading to the newest; a list |
| 325 | + of (version, file name, SHA-256), oldest first. A program's CI can |
| 326 | + fetch the version it was written for by its name, so none is ever |
| 327 | + taken away. Each is made of its tag's own checkout, not of the tree |
| 328 | + at hand. One already in public/download/ is kept as it is, never |
| 329 | + made again: a new one would differ in its dates, and so its SHA-256, |
| 330 | + which a program's CI may check.""" |
| 323 | 331 | git = lambda *a: subprocess.run(("git", "-C", ROOT) + a, capture_output=True, |
| 324 | 332 | text=True, check=True).stdout.strip() |
| 325 | | - tag = git("describe", "--tags", "--abbrev=0", "--match", "v*") |
| 326 | | - name = "raz-%s-linux-x86_64.tar.gz" % tag[1:] |
| 327 | | - made = os.path.join(ROOT, "build", name) |
| 328 | | - if not os.path.exists(made): |
| 329 | | - tree = tempfile.mkdtemp() |
| 330 | | - try: |
| 331 | | - git("worktree", "add", "--detach", tree, tag) |
| 332 | | - subprocess.run(["make", "-s", "-C", ROOT, "dist", "TREE=" + tree], |
| 333 | | - stdout=subprocess.DEVNULL, check=True) |
| 334 | | - finally: |
| 335 | | - git("worktree", "remove", "--force", tree) |
| 336 | | - digest = hashlib.sha256(open(made, "rb").read()).hexdigest() |
| 337 | | - os.makedirs(os.path.join(OUT, "download")) |
| 338 | | - shutil.copy(made, os.path.join(OUT, "download")) |
| 339 | | - write("download/%s.sha256" % name, "%s %s\n" % (digest, name)) |
| 333 | + releases = [] |
| 334 | + for tag in git("tag", "-l", "v*", "--sort=v:refname", "--contains", FIRST_RELEASE).split(): |
| 335 | + name = "raz-%s-linux-x86_64.tar.gz" % tag[1:] |
| 336 | + made = os.path.join(OUT, "download", name) |
| 337 | + if not os.path.exists(made): |
| 338 | + tree = tempfile.mkdtemp() |
| 339 | + try: |
| 340 | + git("worktree", "add", "--detach", tree, tag) |
| 341 | + subprocess.run(["make", "-s", "-C", ROOT, "dist", "TREE=" + tree], |
| 342 | + stdout=subprocess.DEVNULL, check=True) |
| 343 | + finally: |
| 344 | + git("worktree", "remove", "--force", tree) |
| 345 | + shutil.copy(os.path.join(ROOT, "build", name), made) |
| 346 | + digest = hashlib.sha256(open(made, "rb").read()).hexdigest() |
| 347 | + write("download/%s.sha256" % name, "%s %s\n" % (digest, name)) |
| 348 | + releases.append((tag[1:], name, digest)) |
| 340 | 349 | # Cloudflare reads _redirects from the root of what it serves |
| 341 | | - write("_redirects", "/download/latest /download/%s 302\n" % name) |
| 342 | | - return tag[1:], name, digest |
| 350 | + write("_redirects", "/download/latest /download/%s 302\n" % releases[-1][1]) |
| 351 | + return releases |
| 343 | 352 | |
| 344 | | -def build_home(release): |
| 353 | +def build_home(releases): |
| 345 | 354 | snippet = open(os.path.join(HERE, "content", "home.raz"), encoding="utf-8").read() |
| 346 | 355 | tmp = tempfile.mkdtemp() |
| 347 | 356 | try: |
| | @@ -355,7 +364,10 @@ |
| 355 | 364 | text = open(os.path.join(HERE, "content", "home.html"), encoding="utf-8").read() |
| 356 | 365 | text = text.replace("@SNIPPET@", highlight(snippet.rstrip("\n"))) |
| 357 | 366 | text = text.replace("@OUTPUT@", html.escape(stdout.rstrip("\n"))) |
| 358 | | - version, name, digest = release |
| 367 | + version, name, digest = releases[-1] |
| 368 | + earlier = ", ".join('<a href="download/%s">%s</a>' % (n, v) |
| 369 | + for v, n, _ in reversed(releases[:-1])) |
| 370 | + text = text.replace("@EARLIER@", earlier) |
| 359 | 371 | text = text.replace("@VERSION@", version).replace("@TARBALL@", name) |
| 360 | 372 | text = text.replace("@DIR@", name[:-len(".tar.gz")]).replace("@SHA256@", digest) |
| 361 | 373 | write("index.html", page("raz: a small systems language", text, 0, "home")) |
| | @@ -363,8 +375,16 @@ |
| 363 | 375 | def main(): |
| 364 | 376 | if not os.path.exists(RAZ): |
| 365 | 377 | sys.exit("make raz first") |
| 366 | | - shutil.rmtree(OUT, ignore_errors=True) |
| 367 | | - os.makedirs(OUT) |
| 378 | + # everything is made again but the tarballs (see build_download) |
| 379 | + for f in os.listdir(OUT) if os.path.exists(OUT) else []: |
| 380 | + path = os.path.join(OUT, f) |
| 381 | + if f == "download": |
| 382 | + continue |
| 383 | + elif os.path.isdir(path): |
| 384 | + shutil.rmtree(path) |
| 385 | + else: |
| 386 | + os.remove(path) |
| 387 | + os.makedirs(os.path.join(OUT, "download"), exist_ok=True) |
| 368 | 388 | shutil.copy(os.path.join(HERE, "style.css"), OUT) |
| 369 | 389 | for f in os.listdir(os.path.join(HERE, "assets")): # the logo and icons |
| 370 | 390 | if f not in ("social.html", "render.sh"): |