oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package release
2
3import (
4 "regexp"
5 "strconv"
6
7 "amadan.net/oficina/equipo/internal/wire"
8)
9
10// Linked from the release's renderer tree (Makefile, release-runner):
11// the SHA-256 of its MANIFEST, as scripts/build-renderer-tree.py printed
12// it. Only the Linux runner has one.
13var rendererSHA256 string
14
15// RendererPin is the renderer pin linked into this build. With none, or
16// a malformed one, it is "" and health is wire.ToolUnpinned: no tree on
17// disk can be checked against it. With a pin, health is "" and the tree
18// decides.
19func RendererPin() (pin, health string) {
20 if !sha256Hex(rendererSHA256) {
21 return "", wire.ToolUnpinned
22 }
23 return rendererSHA256, ""
24}
25
26// Linked from the same kit file as rendererSHA256 (Makefile,
27// release-runner): the archive's own SHA-256 and size, and the forge
28// release tag it is published under (renderer-<first 12 of that digest>,
29// or renderer-<12>-r<n> after a withdrawal). Only the Linux runner has
30// them.
31var rendererArchiveSHA256, rendererArchiveSize, rendererTag string
32
33// RendererForge is where every published renderer archive is, by tag:
34// <RendererForge><tag>/renderer.tar.gz. A constant of the runner, never
35// data: nothing an instance or a manifest says can point it elsewhere.
36const RendererForge = "https://amadan.net/oficina/equipo/-/releases/"
37
38// RendererAsset is the published archive a runner fetches when it has no
39// verified tree: the tree pin it unpacks to, the archive's digest and size,
40// and its forge tag.
41type RendererAsset struct {
42 Pin, SHA256 string
43 Size int64
44 Tag string
45}
46
47// URL is the archive's address on the forge.
48func (a RendererAsset) URL() string { return RendererForge + a.Tag + "/" + RendererArchive }
49
50// rendererTagPattern is renderer-<12 hex>, with an optional -r<n>.
51var rendererTagPattern = regexp.MustCompile(`^renderer-([0-9a-f]{12})(-r[1-9][0-9]{0,2})?$`)
52
53// Valid: a tree pin, an archive digest, a size within RendererArchiveMax
54// and a tag naming that digest.
55func (a RendererAsset) Valid() bool {
56 m := rendererTagPattern.FindStringSubmatch(a.Tag)
57 return sha256Hex(a.Pin) && sha256Hex(a.SHA256) && a.Size > 0 && a.Size <= RendererArchiveMax && m != nil && m[1] == a.SHA256[:12]
58}
59
60// LinkedRendererAsset is the asset linked into this build, and whether it
61// is whole and valid (only a Linux release runner has one).
62func LinkedRendererAsset() (RendererAsset, bool) {
63 pin, _ := RendererPin()
64 size, err := strconv.ParseInt(rendererArchiveSize, 10, 64)
65 a := RendererAsset{Pin: pin, SHA256: rendererArchiveSHA256, Size: size, Tag: rendererTag}
66 return a, err == nil && a.Valid()
67}
68