ci: add gitea workflows and signed release pipeline
CI runs fmt, clippy and tests. Tag releases build Linux and Windows (mingw cross) artifacts, SHA256SUMS and an Ed25519 signed manifest, then publish via the Gitea API. Helper scripts live in scripts/release, docs in docs/release.md.
This commit is contained in:
parent
ebea98e9a4
commit
948d10bd37
6 changed files with 649 additions and 0 deletions
35
scripts/release/extract_changelog.py
Executable file
35
scripts/release/extract_changelog.py
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Print the body of the CHANGELOG.md section for a version ("## [X.Y.Z] ...").
|
||||
|
||||
Exits non-zero if the section is missing or empty.
|
||||
Usage: extract_changelog.py VERSION [CHANGELOG.md]
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(__doc__)
|
||||
version = sys.argv[1].lstrip("v")
|
||||
path = sys.argv[2] if len(sys.argv) > 2 else "CHANGELOG.md"
|
||||
with open(path, encoding="utf-8") as f:
|
||||
lines = f.read().splitlines()
|
||||
head = re.compile(r"^## \[" + re.escape(version) + r"\]")
|
||||
out, inside = [], False
|
||||
for line in lines:
|
||||
if inside and line.startswith("## "):
|
||||
break
|
||||
if inside:
|
||||
out.append(line)
|
||||
elif head.match(line):
|
||||
inside = True
|
||||
body = "\n".join(out).strip()
|
||||
if not inside or not body:
|
||||
sys.exit(f"CHANGELOG.md has no non-empty section for [{version}]")
|
||||
print(body)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
49
scripts/release/keygen.py
Executable file
49
scripts/release/keygen.py
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Generate an Ed25519 release signing key pair for VNOX.
|
||||
|
||||
The private key is a base64 encoded raw 32 byte seed. Store it ONLY in the
|
||||
Gitea secret VNOX_RELEASE_SIGNING_KEY. The public key is printed as base64 (raw
|
||||
32 bytes) and as a Rust byte array, to be embedded in the client updater.
|
||||
|
||||
Usage:
|
||||
scripts/release/keygen.py # print both keys to stdout
|
||||
scripts/release/keygen.py --private-out key.b64 # write the seed to a 0600 file
|
||||
"""
|
||||
import argparse
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--private-out", help="write the private seed to this file (mode 0600) instead of stdout")
|
||||
args = ap.parse_args()
|
||||
|
||||
key = Ed25519PrivateKey.generate()
|
||||
seed = key.private_bytes(
|
||||
serialization.Encoding.Raw, serialization.PrivateFormat.Raw, serialization.NoEncryption()
|
||||
)
|
||||
pub = key.public_key().public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw)
|
||||
seed_b64 = base64.b64encode(seed).decode()
|
||||
pub_b64 = base64.b64encode(pub).decode()
|
||||
|
||||
if args.private_out:
|
||||
fd = os.open(args.private_out, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
||||
with os.fdopen(fd, "w") as f:
|
||||
f.write(seed_b64 + "\n")
|
||||
print(f"private seed written to {args.private_out} (mode 0600)")
|
||||
else:
|
||||
print(f"VNOX_RELEASE_SIGNING_KEY (private, secret, base64 seed):\n{seed_b64}\n")
|
||||
print(f"public key (base64, raw 32 bytes):\n{pub_b64}\n")
|
||||
rust = ", ".join(f"0x{b:02x}" for b in pub)
|
||||
print("Rust constant for the updater:")
|
||||
print(f"pub const RELEASE_PUBLIC_KEY: [u8; 32] = [{rust}];")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
146
scripts/release/manifest.py
Executable file
146
scripts/release/manifest.py
Executable file
|
|
@ -0,0 +1,146 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Build, sign and verify the VNOX release manifest.
|
||||
|
||||
Canonical form: UTF-8 JSON, keys sorted, no whitespace (separators "," and ":"),
|
||||
ensure_ascii=False, no trailing newline. manifest.json is written in exactly this
|
||||
form, and manifest.json.sig is the base64 Ed25519 signature over those exact bytes.
|
||||
A verifier checks the signature over the raw file bytes first, then parses.
|
||||
|
||||
Subcommands:
|
||||
build --version V --channel C --min-version M --base-url URL [--published-at TS]
|
||||
--dir DIR --out manifest.json NAME=PLATFORM [NAME=PLATFORM ...]
|
||||
sign --manifest manifest.json --out manifest.json.sig
|
||||
(key from env VNOX_RELEASE_SIGNING_KEY: base64 raw 32 byte seed)
|
||||
verify --manifest manifest.json --sig manifest.json.sig --public-key BASE64
|
||||
"""
|
||||
import argparse
|
||||
import base64
|
||||
import datetime
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from cryptography.exceptions import InvalidSignature
|
||||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
||||
|
||||
SCHEMA = 1
|
||||
|
||||
|
||||
def canonical(obj) -> bytes:
|
||||
return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
||||
|
||||
|
||||
def sha256_file(path: str):
|
||||
h = hashlib.sha256()
|
||||
n = 0
|
||||
with open(path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(1 << 20), b""):
|
||||
h.update(chunk)
|
||||
n += len(chunk)
|
||||
return h.hexdigest(), n
|
||||
|
||||
|
||||
def cmd_build(a) -> int:
|
||||
artifacts = []
|
||||
for spec in a.artifacts:
|
||||
name, _, platform = spec.partition("=")
|
||||
if not name or not platform:
|
||||
sys.exit(f"bad artifact spec {spec!r}, expected NAME=PLATFORM")
|
||||
digest, size = sha256_file(os.path.join(a.dir, name))
|
||||
artifacts.append(
|
||||
{
|
||||
"name": name,
|
||||
"platform": platform,
|
||||
"sha256": digest,
|
||||
"size": size,
|
||||
"url": f"{a.base_url.rstrip('/')}/{name}",
|
||||
}
|
||||
)
|
||||
published = a.published_at or datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
manifest = {
|
||||
"schema": SCHEMA,
|
||||
"product": "vnox-client",
|
||||
"version": a.version,
|
||||
"channel": a.channel,
|
||||
"min_version": a.min_version,
|
||||
"published_at": published,
|
||||
"artifacts": sorted(artifacts, key=lambda x: x["platform"]),
|
||||
}
|
||||
with open(a.out, "wb") as f:
|
||||
f.write(canonical(manifest))
|
||||
print(f"wrote {a.out}")
|
||||
return 0
|
||||
|
||||
|
||||
def load_private() -> Ed25519PrivateKey:
|
||||
raw = os.environ.get("VNOX_RELEASE_SIGNING_KEY", "").strip()
|
||||
if not raw:
|
||||
sys.exit("VNOX_RELEASE_SIGNING_KEY is empty or unset, refusing to sign")
|
||||
try:
|
||||
seed = base64.b64decode(raw, validate=True)
|
||||
except Exception:
|
||||
sys.exit("VNOX_RELEASE_SIGNING_KEY is not valid base64")
|
||||
if len(seed) != 32:
|
||||
sys.exit(f"VNOX_RELEASE_SIGNING_KEY must decode to 32 bytes, got {len(seed)}")
|
||||
return Ed25519PrivateKey.from_private_bytes(seed)
|
||||
|
||||
|
||||
def cmd_sign(a) -> int:
|
||||
with open(a.manifest, "rb") as f:
|
||||
data = f.read()
|
||||
# The signed bytes must be canonical, so that re-serialisation can never change them.
|
||||
if canonical(json.loads(data)) != data:
|
||||
sys.exit("manifest is not in canonical form, refusing to sign")
|
||||
key = load_private()
|
||||
sig = key.sign(data)
|
||||
key.public_key().verify(sig, data)
|
||||
with open(a.out, "w") as f:
|
||||
f.write(base64.b64encode(sig).decode() + "\n")
|
||||
print(f"wrote {a.out}")
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_verify(a) -> int:
|
||||
with open(a.manifest, "rb") as f:
|
||||
data = f.read()
|
||||
with open(a.sig) as f:
|
||||
sig = base64.b64decode(f.read().strip(), validate=True)
|
||||
pub = Ed25519PublicKey.from_public_bytes(base64.b64decode(a.public_key, validate=True))
|
||||
try:
|
||||
pub.verify(sig, data)
|
||||
except InvalidSignature:
|
||||
print("signature INVALID", file=sys.stderr)
|
||||
return 1
|
||||
print("signature ok")
|
||||
return 0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
sub = ap.add_subparsers(dest="cmd", required=True)
|
||||
b = sub.add_parser("build")
|
||||
b.add_argument("--version", required=True)
|
||||
b.add_argument("--channel", required=True, choices=["stable", "beta"])
|
||||
b.add_argument("--min-version", default="0.0.0")
|
||||
b.add_argument("--base-url", required=True)
|
||||
b.add_argument("--published-at")
|
||||
b.add_argument("--dir", default=".")
|
||||
b.add_argument("--out", required=True)
|
||||
b.add_argument("artifacts", nargs="+")
|
||||
b.set_defaults(fn=cmd_build)
|
||||
s = sub.add_parser("sign")
|
||||
s.add_argument("--manifest", required=True)
|
||||
s.add_argument("--out", required=True)
|
||||
s.set_defaults(fn=cmd_sign)
|
||||
v = sub.add_parser("verify")
|
||||
v.add_argument("--manifest", required=True)
|
||||
v.add_argument("--sig", required=True)
|
||||
v.add_argument("--public-key", required=True)
|
||||
v.set_defaults(fn=cmd_verify)
|
||||
a = ap.parse_args()
|
||||
return a.fn(a)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue