Integrate selected builds with candidate workflows
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -128,6 +129,75 @@ func TestPublishCommandPublishesConfiguredCandidate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCommandWritesValidatedReceiptForConfiguredArtifacts(t *testing.T) {
|
||||
repository := newCLIBuildRepository(t, `package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/buildinfo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 2 && os.Args[1] == "version" { fmt.Printf("fixture %s\n", buildinfo.Version()) }
|
||||
}
|
||||
`)
|
||||
var stdout, stderr bytes.Buffer
|
||||
args := []string{"build", "--repo", repository, "v1.2.3"}
|
||||
if status := run(context.Background(), args, &stdout, &stderr); status != 0 {
|
||||
t.Fatalf("run() status = %d; stdout=%q stderr=%q", status, stdout.String(), stderr.String())
|
||||
}
|
||||
receiptPath := filepath.Join(repository, "dist", cli.BuildReceiptName)
|
||||
receipt, err := cli.LoadBuildReceipt(receiptPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
commit := cliGitOutput(t, repository, "rev-parse", "HEAD")
|
||||
settings := cli.BuildSettings{
|
||||
MainPackage: "./cmd/app",
|
||||
BinaryName: "fixture",
|
||||
Targets: []string{fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)},
|
||||
}
|
||||
if !receipt.MatchesBuild(repository, commit, "v1.2.3", settings) || len(receipt.Artifacts) != 1 {
|
||||
t.Fatalf("build receipt = %#v", receipt)
|
||||
}
|
||||
if !bytes.Contains(stdout.Bytes(), []byte(receipt.Artifacts[0].Filename)) || !bytes.Contains(stdout.Bytes(), []byte(receipt.Artifacts[0].SHA256)) {
|
||||
t.Fatalf("stdout does not report receipt artifacts: %q", stdout.String())
|
||||
}
|
||||
if got := cliGitOutput(t, repository, "status", "--porcelain"); got != "" {
|
||||
t.Fatalf("build output dirtied candidate: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCommandLeavesNoReceiptAfterSmokeFailure(t *testing.T) {
|
||||
repository := newCLIBuildRepository(t, `package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
func main() { if len(os.Args) == 2 && os.Args[1] == "version" { fmt.Println("wrong") } }
|
||||
`)
|
||||
var stdout, stderr bytes.Buffer
|
||||
args := []string{"build", "--repo", repository, "v1.2.3"}
|
||||
if status := run(context.Background(), args, &stdout, &stderr); status != 1 {
|
||||
t.Fatalf("run() status = %d; stdout=%q stderr=%q, want 1", status, stdout.String(), stderr.String())
|
||||
}
|
||||
if stdout.Len() != 0 || !bytes.Contains(stderr.Bytes(), []byte("native version output")) {
|
||||
t.Fatalf("stdout=%q stderr=%q; want smoke failure without final output", stdout.String(), stderr.String())
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(repository, "dist", cli.BuildReceiptName)); !os.IsNotExist(err) {
|
||||
t.Fatalf("partial build wrote receipt: %v", err)
|
||||
}
|
||||
filename := fmt.Sprintf("fixture-v1.2.3-%s-%s", runtime.GOOS, runtime.GOARCH)
|
||||
if runtime.GOOS == "windows" {
|
||||
filename += ".exe"
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(repository, "dist", filename)); err != nil {
|
||||
t.Fatalf("completed artifact not reported or retained: %v; stderr=%q", err, stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCandidateCheckHelper(t *testing.T) {
|
||||
if os.Getenv("RELEASEKIT_CHECK_HELPER") != "1" {
|
||||
return
|
||||
@@ -164,6 +234,33 @@ func newCLIRepository(t *testing.T) string {
|
||||
return repository
|
||||
}
|
||||
|
||||
func newCLIBuildRepository(t *testing.T, mainSource string) string {
|
||||
t.Helper()
|
||||
repository := newCLIRepository(t)
|
||||
root, err := filepath.Abs(filepath.Join("..", ".."))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
module := fmt.Sprintf("module example.com/cli-candidate\n\ngo 1.25.0\n\nrequire gitea.maximumdirect.net/eric/ReleaseKit v0.0.0\n\nreplace gitea.maximumdirect.net/eric/ReleaseKit => %s\n", filepath.ToSlash(root))
|
||||
write := func(name, contents string) {
|
||||
t.Helper()
|
||||
path := filepath.Join(repository, filepath.FromSlash(name))
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("go.mod", module)
|
||||
write("cmd/app/main.go", mainSource)
|
||||
write("releasekit.json", fmt.Sprintf(`{"product":"Example Product","build":{"main_package":"./cmd/app","binary_name":"fixture","targets":[%q]}}`, fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)))
|
||||
write(".gitignore", "dist/\n")
|
||||
cliGitRun(t, repository, "add", "--all")
|
||||
cliGitRun(t, repository, "commit", "-m", "configure build")
|
||||
return repository
|
||||
}
|
||||
|
||||
func cliGitRun(t *testing.T, repository string, args ...string) {
|
||||
t.Helper()
|
||||
commandArgs := append([]string{"git"}, args...)
|
||||
|
||||
Reference in New Issue
Block a user