Test ReleaseKit integration selections

This commit is contained in:
2026-11-23 18:14:46 +00:00
parent 8e5511b112
commit ef4335cda3
2 changed files with 115 additions and 46 deletions

View File

@@ -195,7 +195,9 @@ delivery, independently of source publication.
## Stage 4 — Refocus tests on Narratio's selections and integration ## Stage 4 — Refocus tests on Narratio's selections and integration
Status: pending. Status: completed. Integration tests cover the profile and delivery selections;
workflow decoding accepts and exercises both supported step shapes. Verified
`go test ./internal/doccheck ./internal/app` with Go 1.27.4.
Read `internal/doccheck/doccheck_test.go`, especially the workflow types, Read `internal/doccheck/doccheck_test.go`, especially the workflow types,
`TestWoodpeckerWorkflowDependencies`, `TestWoodpeckerWorkflowDependencies`,

View File

@@ -1,9 +1,11 @@
package doccheck package doccheck
import ( import (
"encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"regexp" "regexp"
"strings" "strings"
"testing" "testing"
@@ -116,59 +118,85 @@ func TestVerifyWorkflowUsesFullSuiteWithoutFocusedDuplicates(t *testing.T) {
} }
} }
func TestReleaseWorkflowRequiresValidation(t *testing.T) { func TestReleaseProfileSelections(t *testing.T) {
root := repositoryRoot(t) data, err := os.ReadFile(filepath.Join(repositoryRoot(t), "releasekit.json"))
path := filepath.Join(root, ".woodpecker", "release.yml")
data, err := os.ReadFile(path)
if err != nil { if err != nil {
t.Fatalf("read release workflow: %v", err) t.Fatal(err)
}
var profile struct {
Product string `json:"product"`
Remote string `json:"remote"`
Validation struct {
Go struct {
Race bool `json:"race"`
FullVet bool `json:"full_vet"`
} `json:"go"`
GoFormat bool `json:"go_format"`
ModuleDistribution struct {
LocalReplacements bool `json:"local_replacements"`
} `json:"module_distribution"`
} `json:"validation"`
Build struct {
MainPackage string `json:"main_package"`
BinaryName string `json:"binary_name"`
Targets []string `json:"targets"`
} `json:"build"`
Delivery struct {
Forge string `json:"forge"`
BaseURL string `json:"base_url"`
Owner string `json:"owner"`
Repository string `json:"repository"`
TokenEnv string `json:"token_env"`
} `json:"delivery"`
}
if err := json.Unmarshal(data, &profile); err != nil {
t.Fatal(err)
}
if profile.Product != "Narratio" || profile.Remote != "origin" || !profile.Validation.Go.Race || !profile.Validation.Go.FullVet || !profile.Validation.GoFormat || !profile.Validation.ModuleDistribution.LocalReplacements {
t.Fatalf("unexpected identity or validation: %+v", profile)
}
if profile.Build.MainPackage != "./cmd/narratio" || profile.Build.BinaryName != "narratio" || !reflect.DeepEqual(profile.Build.Targets, []string{"linux/amd64", "linux/arm64", "darwin/arm64"}) {
t.Fatalf("unexpected build selection: %+v", profile.Build)
}
if profile.Delivery.Forge != "gitea" || profile.Delivery.BaseURL != "https://forge.maximumdirect.net" || profile.Delivery.Owner != "eric" || profile.Delivery.Repository != "narratio" || profile.Delivery.TokenEnv != "RELEASEKIT_GITEA_TOKEN" {
t.Fatalf("unexpected delivery selection: %+v", profile.Delivery)
}
}
func TestReleaseWorkflowDelivery(t *testing.T) {
data, err := os.ReadFile(filepath.Join(repositoryRoot(t), ".woodpecker", "release.yml"))
if err != nil {
t.Fatal(err)
} }
var workflow woodpeckerWorkflow var workflow woodpeckerWorkflow
if err := yaml.Unmarshal(data, &workflow); err != nil { if err := yaml.Unmarshal(data, &workflow); err != nil {
t.Fatalf("parse release workflow: %v", err) t.Fatal(err)
} }
validate, ok := workflow.Steps["validate-release"] deliver, ok := workflow.Steps["deliver"]
if !ok { if !ok || deliver.Image != "${GO_IMAGE}" || len(workflow.Matrix.Include) != 1 || workflow.Matrix.Include[0]["GO_IMAGE"] != "golang:1.27.4-bookworm" {
t.Fatal("release workflow must define validate-release") t.Fatalf("unexpected delivery image: %+v", workflow)
} }
if validate.Image != "golang:1.27.4" || !containsWorkflowCommand(validate.Commands, `./scripts/check-release-candidate.sh "$CI_COMMIT_TAG"`) { if deliver.Environment["RELEASEKIT_GITEA_TOKEN"].FromSecret != "GITEA_RELEASE_TOKEN" {
t.Fatalf("validate-release = %#v, want the shared candidate checker in golang:1.27.4", validate) t.Fatalf("unexpected delivery environment: %+v", deliver.Environment)
} }
assets, ok := workflow.Steps["build-release-assets"] commands := strings.Join(deliver.Commands, "\n")
if !ok { if !strings.Contains(commands, "go.maximumdirect.net/releasekit") || !strings.Contains(commands, "cmd/releasekit") || !strings.Contains(commands, "ci-deliver") || !strings.Contains(commands, "--prepared") {
t.Fatal("release workflow must define build-release-assets") t.Fatalf("delivery does not invoke the native tool: %s", commands)
} }
if assets.Image != "golang:1.27.4" || !workflowDependsOn(workflow.Steps, "build-release-assets", "validate-release", map[string]bool{}) { }
t.Fatalf("build-release-assets = %#v, want validated golang:1.27.4 asset construction", assets)
} func TestWorkflowStepShapes(t *testing.T) {
assetCommands := strings.Join(assets.Commands, "\n") for _, input := range []string{
if !strings.Contains(assetCommands, `./scripts/build-release-assets.sh "$CI_COMMIT_TAG" "$PWD/dist"`) || strings.Contains(assetCommands, "GOOS=") || strings.Contains(assetCommands, "go build") { "steps:\n first:\n image: example\n second:\n depends_on: first\n",
t.Fatalf("build-release-assets commands must delegate target construction: %q", assetCommands) "steps:\n - name: first\n image: example\n - name: second\n depends_on: first\n",
}
publish, ok := workflow.Steps["publish-release"]
if !ok {
t.Fatal("release workflow must define publish-release")
}
if publish.Image != "woodpeckerci/plugin-release:0.3.1" || !workflowDependsOn(workflow.Steps, "publish-release", "validate-release", map[string]bool{}) || !workflowDependsOn(workflow.Steps, "publish-release", "build-release-assets", map[string]bool{}) {
t.Fatalf("publish-release = %#v, want transitive validation and asset dependencies", publish)
}
for key, want := range map[string]any{
"title": "Narratio ${CI_COMMIT_TAG}",
"note": "docs/releases/${CI_COMMIT_TAG}.md",
"checksum": "sha256",
"checksum-file": "SHA256SUMS",
"checksum-flatten": true,
"file-exists": "skip",
"overwrite": false,
"prerelease": false,
} { } {
if got := publish.Settings[key]; got != want { var workflow woodpeckerWorkflow
t.Fatalf("publish-release setting %q = %#v, want %#v", key, got, want) if err := yaml.Unmarshal([]byte(input), &workflow); err != nil {
t.Fatal(err)
}
if len(workflow.Steps) != 2 || workflow.Steps["first"].Image != "example" || !workflowDependsOn(workflow.Steps, "second", "first", map[string]bool{}) {
t.Fatalf("unexpected decoded steps: %+v", workflow.Steps)
} }
}
files, ok := publish.Settings["files"].([]any)
if !ok || len(files) != 1 || files[0] != "dist/narratio-*" {
t.Fatalf("publish-release files = %#v", publish.Settings["files"])
} }
} }
@@ -241,14 +269,53 @@ func relativeToRoot(root, path string) string {
} }
type woodpeckerWorkflow struct { type woodpeckerWorkflow struct {
Steps map[string]woodpeckerStep `yaml:"steps"` Steps woodpeckerSteps `yaml:"steps"`
Matrix struct {
Include []map[string]string `yaml:"include"`
} `yaml:"matrix"`
}
type woodpeckerSteps map[string]woodpeckerStep
func (s *woodpeckerSteps) UnmarshalYAML(value *yaml.Node) error {
switch value.Kind {
case yaml.MappingNode:
var steps map[string]woodpeckerStep
if err := value.Decode(&steps); err != nil {
return err
}
*s = steps
return nil
case yaml.SequenceNode:
var list []woodpeckerStep
if err := value.Decode(&list); err != nil {
return err
}
steps := make(woodpeckerSteps, len(list))
for _, step := range list {
if step.Name == "" {
return fmt.Errorf("workflow step has no name")
}
if _, exists := steps[step.Name]; exists {
return fmt.Errorf("duplicate workflow step %q", step.Name)
}
steps[step.Name] = step
}
*s = steps
return nil
default:
return fmt.Errorf("workflow steps must be a mapping or sequence")
}
} }
type woodpeckerStep struct { type woodpeckerStep struct {
Name string `yaml:"name"`
Environment map[string]struct {
FromSecret string `yaml:"from_secret"`
} `yaml:"environment"`
DependsOn woodpeckerDependencies `yaml:"depends_on"` DependsOn woodpeckerDependencies `yaml:"depends_on"`
Image string `yaml:"image"` Image string `yaml:"image"`
Commands []string `yaml:"commands"` Commands []string `yaml:"commands"`
Settings map[string]any `yaml:"settings"`
} }
type woodpeckerDependencies []string type woodpeckerDependencies []string