Validate and publish source-only candidates
This commit is contained in:
@@ -279,10 +279,11 @@ func candidateRequest(invocation cli.Invocation, settings cli.Settings, output i
|
||||
if len(settings.Checks) != 0 {
|
||||
checks := settings.Checks
|
||||
request.AdditionalChecks = func(ctx context.Context, candidate releasekit.Candidate) error {
|
||||
return cli.RunChecks(ctx, candidate.ModuleDir, checks, map[string]string{
|
||||
return cli.RunChecks(ctx, candidate.SourceDir, checks, map[string]string{
|
||||
"RELEASEKIT_VERSION": candidate.Version,
|
||||
"RELEASEKIT_CANDIDATE": candidate.Commit,
|
||||
"RELEASEKIT_REPOSITORY_DIR": candidate.RepositoryDir,
|
||||
"RELEASEKIT_SOURCE_DIR": candidate.SourceDir,
|
||||
"RELEASEKIT_MODULE_DIR": candidate.ModuleDir,
|
||||
"RELEASEKIT_MODULE_PATH": candidate.ModulePath,
|
||||
"RELEASEKIT_TAG": candidate.Tag,
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
releasekit "go.maximumdirect.net/releasekit"
|
||||
"go.maximumdirect.net/releasekit/cmd/releasekit/internal/cli"
|
||||
)
|
||||
|
||||
@@ -22,3 +28,31 @@ func TestSourceSelectionMapsToRequest(t *testing.T) {
|
||||
t.Fatal("legacy profile was converted to an explicit source selection")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceCheckCommandUsesSelectedDirectoryAndEnvironment(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("POSIX shell check")
|
||||
}
|
||||
repo := t.TempDir()
|
||||
source := filepath.Join(repo, "config")
|
||||
if err := os.Mkdir(source, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := filepath.Join(t.TempDir(), "context")
|
||||
settings := cli.Settings{Checks: []cli.CheckCommand{{
|
||||
Args: []string{"sh", "-c", `printf '%s\n' "$PWD" "$RELEASEKIT_SOURCE_DIR" "$RELEASEKIT_MODULE_DIR" "$RELEASEKIT_MODULE_PATH" "$RELEASEKIT_TAG" > "$RESULT"`},
|
||||
Env: map[string]string{"RESULT": result},
|
||||
}}}
|
||||
request := candidateRequest(cli.Invocation{}, settings, nil)
|
||||
if err := request.AdditionalChecks(context.Background(), releasekit.Candidate{RepositoryDir: repo, SourceDir: source, Tag: "config/v1.0.0"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := os.ReadFile(result)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := strings.Join([]string{source, source, "", "", "config/v1.0.0", ""}, "\n")
|
||||
if string(data) != want {
|
||||
t.Fatalf("check context = %q, want %q", data, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user