Validate selected release configuration during readiness
This commit is contained in:
@@ -59,12 +59,13 @@ func runValidate(ctx context.Context, invocation cli.Invocation, output io.Write
|
||||
report.Checks = append(report.Checks, releasekit.ReadinessResult{ID: "profile", Operation: "configuration", Status: releasekit.ReadinessFailed, Reason: "configuration", Message: git.DisplayDiagnostic(loadErr.Error()), Cause: loadErr})
|
||||
reportErr = loadErr
|
||||
} else {
|
||||
request := releasekit.ValidateRequest{RepositoryDir: root, ModuleDir: settings.ModuleDir, Source: sourceSpec(settings), Product: settings.Product, Remote: settings.Remote, ExpectedPushURL: settings.ExpectedPushURL, Context: invocation.Context, Offline: invocation.Offline, Build: configuredBuildSpec(settings.Build)}
|
||||
request := releasekit.ValidateRequest{RepositoryDir: root, ModuleDir: settings.ModuleDir, Source: sourceSpec(settings), Product: settings.Product, Remote: settings.Remote, ExpectedPushURL: settings.ExpectedPushURL, Context: invocation.Context, Offline: invocation.Offline, Build: configuredBuildSpec(settings.Build), Validation: validationSpec(settings.Validation)}
|
||||
for _, operation := range invocation.Operations {
|
||||
request.Operations = append(request.Operations, releasekit.ReadinessOperation(operation))
|
||||
}
|
||||
for _, operation := range invocation.Operations {
|
||||
if operation == "rehearsal" && settings.Rehearsal != nil && settings.Rehearsal.Woodpecker != nil {
|
||||
request.RehearsalSelector = settings.Rehearsal.RehearsalSelector()
|
||||
wood := settings.Rehearsal.Woodpecker
|
||||
token, _, credentialErr := cli.ResolveWoodpeckerCredential(root, wood)
|
||||
request.Woodpecker = &releasekit.WoodpeckerObservation{BaseURL: wood.BaseURL, RepositoryID: wood.RepositoryID, Workflow: wood.Workflow, Step: wood.Step, Token: token, CredentialError: credentialErr}
|
||||
|
||||
@@ -263,7 +263,7 @@ func TestValidateRehearsalObservesWoodpeckerWithSeparateLocalCredential(t *testi
|
||||
defer ciServer.Close()
|
||||
writeRepositoryFile(t, repo, "forge-token", "fixture-token\n")
|
||||
writeRepositoryFile(t, repo, "ci-token", "woodpecker-private-value\n")
|
||||
profile := fmt.Sprintf(`{"product":"Config","source":{},"delivery":{"forge":"gitea","base_url":%q,"owner":"owner","repository":"example","credentials":{"local":{"token_file":"forge-token"}}},"rehearsal":{"woodpecker":{"base_url":%q,"repository_id":42,"workflow":"release","step":"deliver","token_file":"ci-token"}}}`, forgeServer.URL, ciServer.URL)
|
||||
profile := fmt.Sprintf(`{"product":"Config","source":{},"delivery":{"forge":"gitea","base_url":%q,"owner":"owner","repository":"example","credentials":{"local":{"token_file":"forge-token"},"ci":{}}},"rehearsal":{"woodpecker":{"base_url":%q,"repository_id":42,"workflow":"release","step":"deliver","token_file":"ci-token"}}}`, forgeServer.URL, ciServer.URL)
|
||||
writeRepositoryFile(t, repo, "releasekit.json", profile)
|
||||
var output bytes.Buffer
|
||||
status := run(context.Background(), []string{"validate", "--repo", repo, "--operation", "rehearsal", "--json"}, &output, &bytes.Buffer{})
|
||||
@@ -277,3 +277,54 @@ func TestValidateRehearsalObservesWoodpeckerWithSeparateLocalCredential(t *testi
|
||||
t.Fatalf("offline status=%d calls=%d report=%s", status, calls, output.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateChecksSelectedExecutionConfiguration(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name, operation, selector string
|
||||
goChecks map[string]any
|
||||
missingCI, online bool
|
||||
want int
|
||||
}{
|
||||
{name: "source race", goChecks: map[string]any{"race": true}, want: 2},
|
||||
{name: "source vet", goChecks: map[string]any{"full_vet": true}, want: 2},
|
||||
{name: "source compilation", goChecks: map[string]any{"compile_targets": []string{"linux/amd64"}}, want: 2},
|
||||
{name: "narrow local delivery", operation: "delivery", goChecks: map[string]any{"race": true}},
|
||||
{name: "missing CI offline", operation: "rehearsal", missingCI: true, want: 2},
|
||||
{name: "missing CI online", operation: "rehearsal", missingCI: true, online: true, want: 2},
|
||||
{name: "selector slash", operation: "rehearsal", selector: "invalid/selector", want: 2},
|
||||
{name: "selector ref syntax", operation: "rehearsal", selector: "invalid..selector", want: 2},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
repo, _ := newSimplePublishRepository(t, false)
|
||||
forge := newDeliveryServer(t, &deliveryServerState{})
|
||||
defer forge.Close()
|
||||
ci := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, `{"id":42}`) }))
|
||||
defer ci.Close()
|
||||
writeRepositoryFile(t, repo, "forge-token", "fixture-token\n")
|
||||
writeRepositoryFile(t, repo, "ci-token", "wood-token\n")
|
||||
credentials := map[string]any{"local": map[string]any{"token_file": "forge-token"}}
|
||||
if !test.missingCI {
|
||||
credentials["ci"] = map[string]any{}
|
||||
}
|
||||
profile := map[string]any{"product": "Config", "source": map[string]any{}, "validation": map[string]any{"go": test.goChecks},
|
||||
"delivery": map[string]any{"forge": "gitea", "base_url": forge.URL, "owner": "owner", "repository": "example", "credentials": credentials},
|
||||
"rehearsal": map[string]any{"selector": test.selector, "woodpecker": map[string]any{"base_url": ci.URL, "repository_id": 42, "workflow": "release", "step": "deliver", "token_file": "ci-token"}}}
|
||||
data, err := json.Marshal(profile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeRepositoryFile(t, repo, "releasekit.json", string(data))
|
||||
args := []string{"validate", "--repo", repo, "--json"}
|
||||
if test.operation != "" {
|
||||
args = append(args, "--operation", test.operation)
|
||||
}
|
||||
if !test.online {
|
||||
args = append(args, "--offline")
|
||||
}
|
||||
var output bytes.Buffer
|
||||
if status := run(t.Context(), args, &output, &bytes.Buffer{}); status != test.want {
|
||||
t.Fatalf("status=%d want=%d report=%s", status, test.want, &output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user