Add pin-check: catch release pins that have fallen behind upstream #58
No files matched your search
@@ -0,0 +1,31 @@
|
||||
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#
|
||||
# Weekly check that the releases this installer pins (internal/release) have
|
||||
# not fallen behind the newest release of inbuxa-server, inbuxa-admin and
|
||||
# inbuxa-webmail. A fresh install ships whatever release.go names, so a pin
|
||||
# left behind is a fresh install shipped stale -- and, if the skipped release
|
||||
# fixed a vulnerability, shipped vulnerable.
|
||||
#
|
||||
# A stale pin fails this run (exit 10) and opens or updates a tracking issue;
|
||||
# the fix is a reviewed change to release.go with the new checksums, never an
|
||||
# automatic edit. The release reads are public, so they need no token; --issue
|
||||
# uses the run token to write the issue in this repository.
|
||||
name: pin-check
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 6 * * 1"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
pins:
|
||||
runs-on: light
|
||||
container:
|
||||
image: golang:1.26-bookworm@sha256:dc40a13b61304647ed7e5d581d246b86413dfc29d63c6d018310feb93cd98fc0 # 1.26-bookworm (1.26.11)
|
||||
steps:
|
||||
- uses: coffey-labs/actions/checkout@fab0c4d45e0162963965f1555df27b7bed5e20ec
|
||||
- name: Check the release pins
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: go run ./cmd/pin-check --issue
|
||||
@@ -0,0 +1,243 @@
|
||||
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// Command pin-check reports whether the releases this installer pins
|
||||
// (internal/release) have fallen behind the newest release of each component.
|
||||
//
|
||||
// It reads each repository's releases from the Gitea API and compares the
|
||||
// newest one in the pin's channel against the pin. It prints a line per
|
||||
// component and exits 10 when any pin is behind, 0 when all are current, and 1
|
||||
// on an error -- so a scheduled job turns a stale pin into a red run (and, with
|
||||
// --issue, an open issue) instead of a fresh install shipped stale.
|
||||
//
|
||||
// It only reads; it never edits release.go. The move itself stays a reviewed
|
||||
// change: the report names the version to move to, and release.go's checksums
|
||||
// are still taken from each release's signed SHA256SUMS by hand.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// pin-check [--base-url URL] [--timeout D] [--issue]
|
||||
//
|
||||
// GITEA_TOKEN, if set, authenticates the API reads (needed while the
|
||||
// repositories are private). --issue opens or updates a tracking issue in this
|
||||
// repository when something is stale, and needs a token with issue write.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/pins"
|
||||
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/release"
|
||||
)
|
||||
|
||||
// component ties a pin from internal/release to the repository whose releases
|
||||
// name its newer versions.
|
||||
type component struct {
|
||||
pins.Component
|
||||
repo string
|
||||
}
|
||||
|
||||
func components() []component {
|
||||
return []component{
|
||||
{pins.Component{Name: "inbuxa-server", Current: release.ServerVersion, TagPrefix: "v"}, "inbuxa-server"},
|
||||
{pins.Component{Name: "inbuxa-admin (console)", Current: release.ConsoleVersion, TagPrefix: "v"}, "inbuxa-admin"},
|
||||
{pins.Component{Name: "inbuxa-webmail", Current: release.WebmailVersion, TagPrefix: "inbuxa-v"}, "inbuxa-webmail"},
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
baseURL := flag.String("base-url", "https://git.coffeylabs.org", "the Gitea base URL whose releases to read")
|
||||
timeout := flag.Duration("timeout", 30*time.Second, "overall deadline for the API reads")
|
||||
openIssue := flag.Bool("issue", false, "open or update a tracking issue in this repo when a pin is stale")
|
||||
flag.Parse()
|
||||
|
||||
token := strings.TrimSpace(os.Getenv("GITEA_TOKEN"))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
|
||||
defer cancel()
|
||||
|
||||
code, err := run(ctx, http.DefaultClient, *baseURL, token, *openIssue)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "pin-check: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func run(ctx context.Context, client *http.Client, baseURL, token string, openIssue bool) (int, error) {
|
||||
var findings []pins.Finding
|
||||
for _, c := range components() {
|
||||
rels, err := fetchReleases(ctx, client, baseURL, token, c.repo)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("%s: %w", c.repo, err)
|
||||
}
|
||||
f, stale, err := pins.Check(c.Component, rels)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if stale {
|
||||
findings = append(findings, f)
|
||||
fmt.Printf("STALE %-24s %s -> %s\n", c.Name, f.Current, f.Latest)
|
||||
} else {
|
||||
fmt.Printf("ok %-24s %s\n", c.Name, c.Current)
|
||||
}
|
||||
}
|
||||
|
||||
if len(findings) == 0 {
|
||||
fmt.Println("\nAll pins are current.")
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
fmt.Printf("\n%d pin(s) behind. Move release.go to the versions above, taking each\n", len(findings))
|
||||
fmt.Println("checksum from that release's signed SHA256SUMS, and open a pull request.")
|
||||
if openIssue {
|
||||
if token == "" {
|
||||
return 0, fmt.Errorf("--issue needs GITEA_TOKEN")
|
||||
}
|
||||
if err := ensureIssue(ctx, client, baseURL, token, findings); err != nil {
|
||||
return 0, fmt.Errorf("opening the tracking issue: %w", err)
|
||||
}
|
||||
}
|
||||
return 10, nil
|
||||
}
|
||||
|
||||
// giteaRelease is the slice of a Gitea release the check needs.
|
||||
type giteaRelease struct {
|
||||
TagName string `json:"tag_name"`
|
||||
Draft bool `json:"draft"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
}
|
||||
|
||||
func fetchReleases(ctx context.Context, client *http.Client, baseURL, token, repo string) ([]pins.Release, error) {
|
||||
u := fmt.Sprintf("%s/api/v1/repos/inbuxa/%s/releases?limit=50", strings.TrimRight(baseURL, "/"), repo)
|
||||
body, err := apiGet(ctx, client, u, token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var got []giteaRelease
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
return nil, fmt.Errorf("decoding releases: %w", err)
|
||||
}
|
||||
out := make([]pins.Release, 0, len(got))
|
||||
for _, r := range got {
|
||||
if r.Draft {
|
||||
continue
|
||||
}
|
||||
out = append(out, pins.Release{Tag: r.TagName, Prerelease: r.Prerelease})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func apiGet(ctx context.Context, client *http.Client, u, token string) ([]byte, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
if token != "" {
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%s: %s", u, resp.Status)
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
const issueTitle = "Pinned releases are behind upstream"
|
||||
|
||||
// ensureIssue opens the tracking issue, or updates the open one, so a stale pin
|
||||
// is visible without flooding: one issue, its body rewritten to the current
|
||||
// findings, reused until it is closed.
|
||||
func ensureIssue(ctx context.Context, client *http.Client, baseURL, token string, findings []pins.Finding) error {
|
||||
body := issueBody(findings)
|
||||
existing, err := openIssueNumber(ctx, client, baseURL, token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base := strings.TrimRight(baseURL, "/")
|
||||
if existing > 0 {
|
||||
u := fmt.Sprintf("%s/api/v1/repos/inbuxa/inbuxa-installer/issues/%d", base, existing)
|
||||
return apiPatch(ctx, client, u, token, map[string]string{"body": body})
|
||||
}
|
||||
u := fmt.Sprintf("%s/api/v1/repos/inbuxa/inbuxa-installer/issues", base)
|
||||
return apiPost(ctx, client, u, token, map[string]string{"title": issueTitle, "body": body})
|
||||
}
|
||||
|
||||
func issueBody(findings []pins.Finding) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("These default-release pins in `internal/release/release.go` are behind the newest release in their channel:\n\n")
|
||||
for _, f := range findings {
|
||||
fmt.Fprintf(&b, "- **%s**: `%s` -> `%s`\n", f.Component, f.Current, f.Latest)
|
||||
}
|
||||
b.WriteString("\nMove each pin, taking its checksum from that release's signed `SHA256SUMS`, and open a pull request. This issue is maintained by `pin-check`; it updates itself and can be closed once the pins are current.\n")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func openIssueNumber(ctx context.Context, client *http.Client, baseURL, token string) (int, error) {
|
||||
u := fmt.Sprintf("%s/api/v1/repos/inbuxa/inbuxa-installer/issues?state=open&type=issues&limit=50",
|
||||
strings.TrimRight(baseURL, "/"))
|
||||
body, err := apiGet(ctx, client, u, token)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var issues []struct {
|
||||
Number int `json:"number"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &issues); err != nil {
|
||||
return 0, fmt.Errorf("decoding issues: %w", err)
|
||||
}
|
||||
for _, is := range issues {
|
||||
if is.Title == issueTitle {
|
||||
return is.Number, nil
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func apiPost(ctx context.Context, client *http.Client, u, token string, payload map[string]string) error {
|
||||
return apiWrite(ctx, client, http.MethodPost, u, token, payload, http.StatusCreated)
|
||||
}
|
||||
|
||||
func apiPatch(ctx context.Context, client *http.Client, u, token string, payload map[string]string) error {
|
||||
return apiWrite(ctx, client, http.MethodPatch, u, token, payload, http.StatusOK)
|
||||
}
|
||||
|
||||
func apiWrite(ctx context.Context, client *http.Client, method, u, token string, payload map[string]string, want int) error {
|
||||
buf, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, method, u, strings.NewReader(string(buf)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
io.Copy(io.Discard, io.LimitReader(resp.Body, 1<<20))
|
||||
if resp.StatusCode != want {
|
||||
return fmt.Errorf("%s %s: %s", method, u, resp.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/release"
|
||||
)
|
||||
|
||||
// releasesFor serves a plausible set of releases for each component's repo: the
|
||||
// pinned version plus, when bump is true, one newer candidate.
|
||||
func releasesServer(t *testing.T, bump bool) *httptest.Server {
|
||||
t.Helper()
|
||||
newer := func(v string) string {
|
||||
// 27.1-rc.10 -> 27.1-rc.11; leaves a final pin alone.
|
||||
i := strings.LastIndex(v, ".")
|
||||
if i < 0 || !strings.Contains(v, "-rc.") {
|
||||
return v
|
||||
}
|
||||
return v[:i+1] + bumpNum(v[i+1:])
|
||||
}
|
||||
repoVersion := map[string]struct {
|
||||
prefix, current string
|
||||
}{
|
||||
"inbuxa-server": {"v", release.ServerVersion},
|
||||
"inbuxa-admin": {"v", release.ConsoleVersion},
|
||||
"inbuxa-webmail": {"inbuxa-v", release.WebmailVersion},
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
for repo, rv := range repoVersion {
|
||||
rv := rv
|
||||
mux.HandleFunc("/api/v1/repos/inbuxa/"+repo+"/releases", func(w http.ResponseWriter, r *http.Request) {
|
||||
rels := []giteaRelease{{TagName: rv.prefix + rv.current, Prerelease: true}}
|
||||
if bump {
|
||||
rels = append(rels, giteaRelease{TagName: rv.prefix + newer(rv.current), Prerelease: true})
|
||||
}
|
||||
// A draft and an unrelated tag, to prove both are ignored.
|
||||
rels = append(rels,
|
||||
giteaRelease{TagName: rv.prefix + "99.9-rc.9", Draft: true},
|
||||
giteaRelease{TagName: "unrelated", Prerelease: true},
|
||||
)
|
||||
_ = json.NewEncoder(w).Encode(rels)
|
||||
})
|
||||
}
|
||||
return httptest.NewServer(mux)
|
||||
}
|
||||
|
||||
func bumpNum(s string) string {
|
||||
var n int
|
||||
fmt.Sscanf(s, "%d", &n)
|
||||
return fmt.Sprintf("%d", n+1)
|
||||
}
|
||||
|
||||
func TestRunReportsAllCurrentWhenNothingIsNewer(t *testing.T) {
|
||||
srv := releasesServer(t, false)
|
||||
defer srv.Close()
|
||||
code, err := run(context.Background(), srv.Client(), srv.URL, "", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code != 0 {
|
||||
t.Errorf("exit code = %d, want 0", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunExits10WhenAPinIsBehind(t *testing.T) {
|
||||
srv := releasesServer(t, true)
|
||||
defer srv.Close()
|
||||
code, err := run(context.Background(), srv.Client(), srv.URL, "", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code != 10 {
|
||||
t.Errorf("exit code = %d, want 10", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunErrorsOnABadStatus(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "nope", http.StatusInternalServerError)
|
||||
}))
|
||||
defer srv.Close()
|
||||
if _, err := run(context.Background(), srv.Client(), srv.URL, "", false); err == nil {
|
||||
t.Errorf("a 500 from the releases API should be an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchReleasesSkipsDraftsAndKeepsPrereleaseFlag(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_ = json.NewEncoder(w).Encode([]giteaRelease{
|
||||
{TagName: "v27.1-rc.1", Prerelease: true},
|
||||
{TagName: "v27.1-rc.2", Draft: true},
|
||||
{TagName: "v27.1", Prerelease: false},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
got, err := fetchReleases(context.Background(), srv.Client(), srv.URL, "", "inbuxa-server")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("want 2 non-draft releases, got %d: %+v", len(got), got)
|
||||
}
|
||||
if got[0].Tag != "v27.1-rc.1" || !got[0].Prerelease || got[1].Tag != "v27.1" || got[1].Prerelease {
|
||||
t.Errorf("releases not carried through faithfully: %+v", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// Package pins decides whether the releases this installer pins
|
||||
// (internal/release) have fallen behind the newest release of each component.
|
||||
//
|
||||
// A fresh install ships whatever release.go names, so a pin left behind is a
|
||||
// fresh install shipped stale -- and, when the release it skipped fixed a
|
||||
// vulnerability, shipped vulnerable. This package is the check that catches
|
||||
// that: given the pinned version and the releases a repository has published,
|
||||
// it reports the newer one to move to, or nothing when the pin is current.
|
||||
//
|
||||
// The channel follows the pin itself, and stays within the pin's own
|
||||
// major.minor series. A release-candidate pin (27.1-rc.15) tracks the
|
||||
// candidates and the final of that series: a newer 27.1 rc, or 27.1 final, is a
|
||||
// move. A final pin (27.1) has nothing newer in its series. Crossing to another
|
||||
// series -- a later flagship like 27.2, or the parallel calendar-versioned
|
||||
// maintenance line (2026.11.11) the suite ships alongside the flagship -- is a
|
||||
// deliberate change to a new installer line, not something this flags. This
|
||||
// mirrors release.go's rule that an rc installer pins rcs and a final pins
|
||||
// finals.
|
||||
package pins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Version is a parsed suite version: 27.1, 27.1.2, or 27.1-rc.15. A final
|
||||
// release orders after every candidate of the same major.minor.patch.
|
||||
type Version struct {
|
||||
Major int
|
||||
Minor int
|
||||
Patch int
|
||||
// RC is the candidate number; Final is true for a non-candidate release,
|
||||
// in which case RC is ignored.
|
||||
RC int
|
||||
Final bool
|
||||
}
|
||||
|
||||
// Parse reads a version like "27.1", "27.1.2", "27.1-rc.15", tolerating a
|
||||
// leading "v". The component's own tag prefix (for example "inbuxa-v") must be
|
||||
// stripped before calling.
|
||||
func Parse(s string) (Version, error) {
|
||||
s = strings.TrimPrefix(strings.TrimSpace(s), "v")
|
||||
if s == "" {
|
||||
return Version{}, fmt.Errorf("empty version")
|
||||
}
|
||||
core, pre, hasPre := strings.Cut(s, "-")
|
||||
parts := strings.Split(core, ".")
|
||||
if len(parts) < 2 || len(parts) > 3 {
|
||||
return Version{}, fmt.Errorf("version %q: want MAJOR.MINOR[.PATCH]", s)
|
||||
}
|
||||
nums := make([]int, 3)
|
||||
for i, p := range parts {
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil || n < 0 {
|
||||
return Version{}, fmt.Errorf("version %q: %q is not a number", s, p)
|
||||
}
|
||||
nums[i] = n
|
||||
}
|
||||
v := Version{Major: nums[0], Minor: nums[1], Patch: nums[2], Final: !hasPre}
|
||||
if hasPre {
|
||||
rc, ok := strings.CutPrefix(pre, "rc.")
|
||||
if !ok {
|
||||
return Version{}, fmt.Errorf("version %q: only rc.N pre-releases are known, not %q", s, pre)
|
||||
}
|
||||
n, err := strconv.Atoi(rc)
|
||||
if err != nil || n < 0 {
|
||||
return Version{}, fmt.Errorf("version %q: rc number %q is not a number", s, rc)
|
||||
}
|
||||
v.RC = n
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Compare orders two versions: negative if a is older, zero if equal, positive
|
||||
// if a is newer. A final outranks any candidate of the same core.
|
||||
func (a Version) Compare(b Version) int {
|
||||
if c := cmp(a.Major, b.Major); c != 0 {
|
||||
return c
|
||||
}
|
||||
if c := cmp(a.Minor, b.Minor); c != 0 {
|
||||
return c
|
||||
}
|
||||
if c := cmp(a.Patch, b.Patch); c != 0 {
|
||||
return c
|
||||
}
|
||||
switch {
|
||||
case a.Final && b.Final:
|
||||
return 0
|
||||
case a.Final:
|
||||
return 1
|
||||
case b.Final:
|
||||
return -1
|
||||
default:
|
||||
return cmp(a.RC, b.RC)
|
||||
}
|
||||
}
|
||||
|
||||
func cmp(a, b int) int {
|
||||
switch {
|
||||
case a < b:
|
||||
return -1
|
||||
case a > b:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// String renders the version the way release.go writes it.
|
||||
func (a Version) String() string {
|
||||
core := fmt.Sprintf("%d.%d", a.Major, a.Minor)
|
||||
if a.Patch != 0 {
|
||||
core = fmt.Sprintf("%d.%d.%d", a.Major, a.Minor, a.Patch)
|
||||
}
|
||||
if a.Final {
|
||||
return core
|
||||
}
|
||||
return fmt.Sprintf("%s-rc.%d", core, a.RC)
|
||||
}
|
||||
|
||||
// Release is one published release of a repository, as the check reads it from
|
||||
// the releases API: its tag and whether it is a pre-release. Drafts are left
|
||||
// out by the caller.
|
||||
type Release struct {
|
||||
Tag string
|
||||
Prerelease bool
|
||||
}
|
||||
|
||||
// Component is one pinned thing to check: a name for the report, the current
|
||||
// pinned version (from release.go, with no tag prefix), and the prefix the
|
||||
// repository's tags carry (for example "v" or "inbuxa-v").
|
||||
type Component struct {
|
||||
Name string
|
||||
Current string
|
||||
TagPrefix string
|
||||
}
|
||||
|
||||
// Finding is a component whose pin is behind the newest release in its channel.
|
||||
type Finding struct {
|
||||
Component string
|
||||
Current string
|
||||
Latest string
|
||||
}
|
||||
|
||||
// Check compares a component's pin against the releases a repository has
|
||||
// published and reports the newer version to move to, if any. The channel is
|
||||
// taken from the current pin: a candidate pin also accepts the final of its
|
||||
// core, a final pin accepts finals only.
|
||||
func Check(c Component, releases []Release) (Finding, bool, error) {
|
||||
cur, err := Parse(c.Current)
|
||||
if err != nil {
|
||||
return Finding{}, false, fmt.Errorf("%s: current pin: %w", c.Name, err)
|
||||
}
|
||||
best := cur
|
||||
found := false
|
||||
for _, r := range releases {
|
||||
tag, ok := strings.CutPrefix(r.Tag, c.TagPrefix)
|
||||
if !ok {
|
||||
// A tag that does not carry this component's prefix is a release
|
||||
// of something else sharing the repo, or a differently-shaped tag;
|
||||
// it is not a candidate.
|
||||
continue
|
||||
}
|
||||
v, err := Parse(tag)
|
||||
if err != nil {
|
||||
// An unparseable tag is skipped, not fatal: one odd historical tag
|
||||
// must not blind the check to every good one.
|
||||
continue
|
||||
}
|
||||
// Stay in the pin's own series. A different major.minor is another
|
||||
// flagship (27.2) or the parallel calendar-versioned line (2026.x),
|
||||
// each a deliberate move to a new installer line, not a pin bump.
|
||||
if v.Major != cur.Major || v.Minor != cur.Minor {
|
||||
continue
|
||||
}
|
||||
// A final pin never moves onto a pre-release: not a candidate by its
|
||||
// tag, and not one flagged pre-release in the releases API.
|
||||
if cur.Final && (!v.Final || r.Prerelease) {
|
||||
continue
|
||||
}
|
||||
if v.Compare(best) > 0 {
|
||||
best = v
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return Finding{}, false, nil
|
||||
}
|
||||
return Finding{Component: c.Name, Current: cur.String(), Latest: best.String()}, true, nil
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package pins
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseAcceptsTheShapesReleaseUses(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
want Version
|
||||
}{
|
||||
{"27.1", Version{Major: 27, Minor: 1, Final: true}},
|
||||
{"v27.1", Version{Major: 27, Minor: 1, Final: true}},
|
||||
{"27.1.2", Version{Major: 27, Minor: 1, Patch: 2, Final: true}},
|
||||
{"27.1-rc.15", Version{Major: 27, Minor: 1, RC: 15}},
|
||||
{" 27.1-rc.3 ", Version{Major: 27, Minor: 1, RC: 3}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, err := Parse(c.in)
|
||||
if err != nil {
|
||||
t.Fatalf("Parse(%q): %v", c.in, err)
|
||||
}
|
||||
if got != c.want {
|
||||
t.Errorf("Parse(%q) = %+v, want %+v", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRejectsNonsense(t *testing.T) {
|
||||
for _, in := range []string{"", "27", "27.1.2.3", "27.x", "27.1-beta.1", "27.1-rc.x"} {
|
||||
if _, err := Parse(in); err == nil {
|
||||
t.Errorf("Parse(%q) accepted a bad version", in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareOrdersCandidatesBeforeTheFinal(t *testing.T) {
|
||||
order := []string{"27.1-rc.1", "27.1-rc.2", "27.1-rc.15", "27.1", "27.2-rc.1", "27.2"}
|
||||
for i := 0; i+1 < len(order); i++ {
|
||||
a := mustParse(t, order[i])
|
||||
b := mustParse(t, order[i+1])
|
||||
if a.Compare(b) >= 0 {
|
||||
t.Errorf("%s should be older than %s", order[i], order[i+1])
|
||||
}
|
||||
if b.Compare(a) <= 0 {
|
||||
t.Errorf("%s should be newer than %s", order[i+1], order[i])
|
||||
}
|
||||
}
|
||||
if v := mustParse(t, "27.1"); v.Compare(v) != 0 {
|
||||
t.Errorf("a version should equal itself")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringRoundTrips(t *testing.T) {
|
||||
for _, s := range []string{"27.1", "27.1.2", "27.1-rc.15"} {
|
||||
if got := mustParse(t, s).String(); got != s {
|
||||
t.Errorf("String() = %q, want %q", got, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckFindsANewerCandidate(t *testing.T) {
|
||||
c := Component{Name: "server", Current: "27.1-rc.15", TagPrefix: "v"}
|
||||
rels := []Release{
|
||||
{Tag: "v27.1-rc.14", Prerelease: true},
|
||||
{Tag: "v27.1-rc.16", Prerelease: true},
|
||||
{Tag: "v27.1-rc.15", Prerelease: true},
|
||||
}
|
||||
f, stale, err := Check(c, rels)
|
||||
if err != nil || !stale {
|
||||
t.Fatalf("Check: stale=%v err=%v", stale, err)
|
||||
}
|
||||
if f.Latest != "27.1-rc.16" || f.Current != "27.1-rc.15" {
|
||||
t.Errorf("Finding = %+v", f)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCandidatePinMovesToTheFinal(t *testing.T) {
|
||||
c := Component{Name: "server", Current: "27.1-rc.15", TagPrefix: "v"}
|
||||
rels := []Release{
|
||||
{Tag: "v27.1-rc.16", Prerelease: true},
|
||||
{Tag: "v27.1", Prerelease: false},
|
||||
}
|
||||
f, stale, err := Check(c, rels)
|
||||
if err != nil || !stale {
|
||||
t.Fatalf("Check: stale=%v err=%v", stale, err)
|
||||
}
|
||||
if f.Latest != "27.1" {
|
||||
t.Errorf("a candidate pin should move to the final, got %q", f.Latest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinalPinIgnoresLaterCandidates(t *testing.T) {
|
||||
c := Component{Name: "server", Current: "27.1", TagPrefix: "v"}
|
||||
rels := []Release{
|
||||
{Tag: "v27.2-rc.1", Prerelease: true},
|
||||
{Tag: "v27.1", Prerelease: false},
|
||||
}
|
||||
_, stale, err := Check(c, rels)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stale {
|
||||
t.Errorf("a final pin must not move onto a later series' candidate")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckStaysInTheSameSeries(t *testing.T) {
|
||||
// A later flagship series is a deliberate move to a new installer line, not
|
||||
// a pin bump, even when it is a final.
|
||||
c := Component{Name: "server", Current: "27.1", TagPrefix: "v"}
|
||||
rels := []Release{
|
||||
{Tag: "v27.2-rc.1", Prerelease: true},
|
||||
{Tag: "v27.2", Prerelease: false},
|
||||
}
|
||||
_, stale, err := Check(c, rels)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stale {
|
||||
t.Errorf("a 27.1 pin must not be pulled onto the 27.2 series")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckIgnoresTheCalendarVersionedLine(t *testing.T) {
|
||||
// The suite ships a parallel calendar-versioned maintenance line
|
||||
// (2026.11.11) whose major sorts above the flagship's (2026 > 27). It must
|
||||
// not be read as a newer 27.1.
|
||||
c := Component{Name: "server", Current: "27.1-rc.15", TagPrefix: "v"}
|
||||
rels := []Release{
|
||||
{Tag: "v2026.11.11", Prerelease: false},
|
||||
{Tag: "v2026.10.26", Prerelease: false},
|
||||
{Tag: "v27.1-rc.16", Prerelease: true},
|
||||
}
|
||||
f, stale, err := Check(c, rels)
|
||||
if err != nil || !stale {
|
||||
t.Fatalf("Check: stale=%v err=%v", stale, err)
|
||||
}
|
||||
if f.Latest != "27.1-rc.16" {
|
||||
t.Errorf("should move within the 27.1 series only, got %q", f.Latest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentPinIsNotStale(t *testing.T) {
|
||||
c := Component{Name: "server", Current: "27.1-rc.16", TagPrefix: "v"}
|
||||
rels := []Release{
|
||||
{Tag: "v27.1-rc.15", Prerelease: true},
|
||||
{Tag: "v27.1-rc.16", Prerelease: true},
|
||||
}
|
||||
_, stale, err := Check(c, rels)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stale {
|
||||
t.Errorf("the newest release equals the pin; not stale")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckHonoursTheTagPrefixAndSkipsOthers(t *testing.T) {
|
||||
c := Component{Name: "webmail", Current: "27.1-rc.3", TagPrefix: "inbuxa-v"}
|
||||
rels := []Release{
|
||||
{Tag: "inbuxa-v27.1-rc.5", Prerelease: true},
|
||||
{Tag: "v27.9-rc.9", Prerelease: true}, // wrong prefix: another tag line, ignored
|
||||
{Tag: "nightly", Prerelease: true}, // unparseable: skipped, not fatal
|
||||
}
|
||||
f, stale, err := Check(c, rels)
|
||||
if err != nil || !stale {
|
||||
t.Fatalf("Check: stale=%v err=%v", stale, err)
|
||||
}
|
||||
if f.Latest != "27.1-rc.5" {
|
||||
t.Errorf("Finding = %+v", f)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckReportsABadCurrentPin(t *testing.T) {
|
||||
c := Component{Name: "server", Current: "not-a-version", TagPrefix: "v"}
|
||||
if _, _, err := Check(c, nil); err == nil {
|
||||
t.Errorf("a malformed current pin should be an error")
|
||||
}
|
||||
}
|
||||
|
||||
func mustParse(t *testing.T, s string) Version {
|
||||
t.Helper()
|
||||
v, err := Parse(s)
|
||||
if err != nil {
|
||||
t.Fatalf("Parse(%q): %v", s, err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
@@ -12,6 +12,11 @@
|
||||
// candidates; a final release pins final releases only. Downloading an RC
|
||||
// installer is the opt-in: it is published as a pre-release, so
|
||||
// releases/latest, and so a plain install, never reaches one.
|
||||
//
|
||||
// A pin left behind is a fresh install shipped stale. The pin-check command
|
||||
// (cmd/pin-check, run weekly by .gitea/workflows/pin-check.yml) reads each
|
||||
// component's releases and reports when the version here is behind the newest
|
||||
// in its channel, so the move is noticed and made before it ships.
|
||||
package release
|
||||
|
||||
import (
|
||||
|
||||
Reference in new issue
Block a user