Files
Sebastian UnterschützandClaude Opus 5.5 b1ca8eb19f
ci / image (pull_request) Successful in 4m1s
ci / build (pull_request) Successful in 8m59s
ci / lint (pull_request) Successful in 10m34s
ci / test (pull_request) Successful in 12m29s
feat(release): sign checksums and publish an SBOM
Releases carry SHA256SUMS signed in the minisign format (prehashed
Ed25519, the release tag as trusted comment) and an SPDX SBOM of the Go
modules and the npm packages the frontend build bundles. internal/signing
signs and verifies; the release keys are committed in release.pub and
compiled in, so the self-updating agents can check their downloads.
Without the RELEASE_SIGNING_KEY secret a release is published unsigned
with a warning.

Closes #34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-23 18:20:05 +01:00

186 lines
4.5 KiB
Go

// Command release derives versions and release notes from Conventional
// Commits.
//
// release next [stable|beta] print the tag the next release gets
// release notes [-json] <tag> print the release notes of a tag, with
// -json as the body of a Gitea release
// release check <tag> fail unless tag is a valid release tag
// release sbom <tag> <bin>... print the SPDX SBOM of a release
// release sign <file> <tag> write file.minisig with the key in
// RELEASE_SIGNING_KEY
// release verify <file> check file.minisig against the release keys
// release keygen <secret-file> create a signing key, print its public key
//
// Stable releases follow semantic versioning from the commits since the
// last stable release: breaking changes move the major version (the minor
// one before 1.0), features the minor and fixes the patch version. Betas
// are numbered prereleases of the coming stable version.
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"strings"
)
const usage = `usage: release next [stable|beta] | notes [-json] <tag> | check <tag> | sbom <tag> <binary>... | sign <file> <tag> | verify <file> | keygen <secret-file>`
func main() {
if err := run(os.Args[1:]); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(args []string) error {
if len(args) == 0 {
return usageError{}
}
switch args[0] {
case "next":
channel := "stable"
if len(args) > 1 {
channel = args[1]
}
tags, err := gitTags()
if err != nil {
return err
}
from := ""
if base := lastStable(tags); base != (version{}) {
from = base.String()
}
commits, err := gitCommits(from, "HEAD")
if err != nil {
return err
}
v, err := next(tags, commits, channel)
if err != nil {
return err
}
fmt.Println(v)
case "notes":
asJSON := len(args) == 3 && args[1] == "-json"
if asJSON {
args = args[1:]
}
if len(args) != 2 {
return usageError{}
}
v, err := parseVersion(args[1])
if err != nil {
return err
}
tags, err := gitTags()
if err != nil {
return err
}
prev, ok := previous(tags, v)
from := ""
var pp *version
if ok {
from, pp = prev.String(), &prev
}
commits, err := gitCommits(from, v.String())
if err != nil {
return err
}
text := notes(v, pp, commits, repoURL())
if !asJSON {
fmt.Print(text)
return nil
}
return json.NewEncoder(os.Stdout).Encode(map[string]any{
"tag_name": v.String(), "name": v.String(), "body": text, "prerelease": v.Beta > 0,
})
case "check":
if len(args) != 2 {
return usageError{}
}
_, err := parseVersion(args[1])
return err
case "sbom":
if len(args) < 3 {
return usageError{}
}
v, err := parseVersion(args[1])
if err != nil {
return err
}
return writeSBOM(v, args[2:])
case "sign":
if len(args) != 3 {
return usageError{}
}
return signFile(args[1], args[2])
case "verify":
if len(args) != 2 {
return usageError{}
}
return verifyFile(args[1])
case "keygen":
if len(args) != 2 {
return usageError{}
}
return keygen(args[1])
default:
return usageError{}
}
return nil
}
type usageError struct{}
func (usageError) Error() string { return usage }
func git(args ...string) (string, error) {
out, err := exec.Command("git", args...).Output()
var exit *exec.ExitError
if errors.As(err, &exit) {
return "", fmt.Errorf("git %s: %s", strings.Join(args, " "), strings.TrimSpace(string(exit.Stderr)))
}
return string(out), err
}
func gitTags() ([]version, error) {
out, err := git("tag", "--list", "v*")
if err != nil {
return nil, err
}
return parseTags(strings.Split(out, "\n")), nil
}
// gitCommits lists the commits after from up to to, oldest first, without
// merge commits. An empty from means the whole history.
func gitCommits(from, to string) ([]commit, error) {
rng := to
if from != "" {
rng = from + ".." + to
}
out, err := git("log", "--reverse", "--no-merges", "--format=%H%x1f%s%x1f%b%x1e", rng, "--")
if err != nil {
return nil, err
}
var commits []commit
for rec := range strings.SplitSeq(out, "\x1e") {
f := strings.SplitN(strings.TrimLeft(rec, "\n"), "\x1f", 3)
if len(f) != 3 {
continue
}
commits = append(commits, commit{Hash: f[0], Subject: f[1], Body: f[2]})
}
return commits, nil
}
// repoURL is the repository's web address in CI, for links in the notes.
func repoURL() string {
server, repo := os.Getenv("GITHUB_SERVER_URL"), os.Getenv("GITHUB_REPOSITORY")
if server == "" || repo == "" {
return ""
}
return strings.TrimSuffix(server, "/") + "/" + repo
}