Adopt ReleaseKit module publishing
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -36,15 +37,15 @@ func TestReleaseIntegration(t *testing.T) {
|
||||
env := fixture.releaseEnv(marker)
|
||||
|
||||
candidate := gitRun(t, ctx, git, fixture.worktree, env, "rev-parse", "HEAD")
|
||||
stdout, stderr, status := runPublisher(t, ctx, shell, fixture, env, "v0.0.1")
|
||||
stdout, stderr, status := runPublisher(t, ctx, shell, fixture, env, "core", "v0.0.1")
|
||||
if status != 0 {
|
||||
t.Fatalf("publish v0.0.1 status = %d\nstdout:\n%s\nstderr:\n%s", status, stdout, stderr)
|
||||
t.Fatalf("publish core v0.0.1 status = %d\nstdout:\n%s\nstderr:\n%s", status, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "v0.0.1") || !strings.Contains(stdout, candidate) {
|
||||
t.Fatalf("publication output does not identify version and candidate %s:\n%s", candidate, stdout)
|
||||
}
|
||||
assertTag(t, ctx, git, fixture, "v0.0.1", candidate)
|
||||
assertOnlyTag(t, ctx, git, fixture, "v0.0.1")
|
||||
assertTags(t, ctx, git, fixture, "v0.0.1")
|
||||
if got := readLines(t, marker); !equalStrings(got, []string{"candidate suite ran"}) {
|
||||
t.Fatalf("candidate suite marker = %#v, want one run", got)
|
||||
}
|
||||
@@ -58,28 +59,41 @@ func TestReleaseIntegration(t *testing.T) {
|
||||
t.Fatalf("expected ignored bootstrap executable: %v", err)
|
||||
}
|
||||
|
||||
nestedCandidate := gitRun(t, ctx, git, fixture.worktree, env, "rev-parse", "HEAD")
|
||||
stdout, stderr, status = runPublisher(t, ctx, shell, fixture, env, "ckconfig", "v0.0.1")
|
||||
if status != 0 {
|
||||
t.Fatalf("publish ckconfig v0.0.1 status = %d\nstdout:\n%s\nstderr:\n%s", status, stdout, stderr)
|
||||
}
|
||||
nestedTag := "integrations/ckconfig/v0.0.1"
|
||||
if !strings.Contains(stdout, nestedTag) || !strings.Contains(stdout, nestedCandidate) {
|
||||
t.Fatalf("nested publication output does not identify tag %s and candidate %s:\n%s", nestedTag, nestedCandidate, stdout)
|
||||
}
|
||||
assertTag(t, ctx, git, fixture, nestedTag, nestedCandidate)
|
||||
assertTags(t, ctx, git, fixture, "v0.0.1", nestedTag)
|
||||
|
||||
fixture.prepareSecondCandidate(t, ctx, git)
|
||||
stdout, stderr, status = runPublisher(t, ctx, shell, fixture, env, "v0.0.2")
|
||||
stdout, stderr, status = runPublisher(t, ctx, shell, fixture, env, "core", "v0.0.2")
|
||||
if status != 1 {
|
||||
t.Fatalf("publish with mismatched endpoint status = %d, want 1\nstdout:\n%s\nstderr:\n%s", status, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(stderr), "unexpected publication push url") {
|
||||
t.Fatalf("endpoint mismatch diagnostic not found in stderr:\n%s", stderr)
|
||||
}
|
||||
assertOnlyTag(t, ctx, git, fixture, "v0.0.1")
|
||||
assertTags(t, ctx, git, fixture, "v0.0.1", nestedTag)
|
||||
if got := readLines(t, marker); !equalStrings(got, []string{"candidate suite ran"}) {
|
||||
t.Fatalf("candidate suite ran after endpoint preflight failure: %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
type publicationFixture struct {
|
||||
root string
|
||||
worktree string
|
||||
bare string
|
||||
outside string
|
||||
profile string
|
||||
gitConfig string
|
||||
gitEnv []string
|
||||
root string
|
||||
worktree string
|
||||
bare string
|
||||
outside string
|
||||
profile string
|
||||
nestedProfile string
|
||||
gitConfig string
|
||||
gitEnv []string
|
||||
}
|
||||
|
||||
func newPublicationFixture(t *testing.T, ctx context.Context, git string) publicationFixture {
|
||||
@@ -124,6 +138,13 @@ func newPublicationFixture(t *testing.T, ctx context.Context, git string) public
|
||||
for _, name := range []string{"go.mod", "go.sum", ".gitignore"} {
|
||||
copyFile(t, filepath.Join(commandkitRoot, name), filepath.Join(worktree, name), 0o644)
|
||||
}
|
||||
for _, name := range []string{"COPYRIGHT", "LICENSE", "docs/oss/attribution.md"} {
|
||||
target := filepath.Join(worktree, name)
|
||||
if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
copyFile(t, filepath.Join(commandkitRoot, name), target, 0o644)
|
||||
}
|
||||
script := filepath.Join(worktree, "scripts", "release")
|
||||
if err := os.MkdirAll(filepath.Dir(script), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -147,6 +168,35 @@ func newPublicationFixture(t *testing.T, ctx context.Context, git string) public
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFile(t, profile, string(profileData)+"\n", 0o644)
|
||||
nestedModule := filepath.Join(worktree, "integrations", "ckconfig")
|
||||
if err := os.MkdirAll(nestedModule, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFile(t, filepath.Join(nestedModule, "go.mod"), "module gitea.maximumdirect.net/eric/CommandKit/integrations/ckconfig\n\ngo 1.26.0\n", 0o644)
|
||||
writeFile(t, filepath.Join(nestedModule, "fixture.go"), "package fixture\n\nfunc Ready() bool { return true }\n", 0o644)
|
||||
writeFile(t, filepath.Join(nestedModule, "fixture_test.go"), "package fixture\n\nimport \"testing\"\n\nfunc TestReady(t *testing.T) { if !Ready() { t.Fatal(\"not ready\") } }\n", 0o644)
|
||||
if err := os.MkdirAll(filepath.Join(nestedModule, "docs", "releases"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFile(t, filepath.Join(nestedModule, "docs", "releases", "v0.0.1.md"), releaseNoteFor("CommandKit ckconfig", "v0.0.1"), 0o644)
|
||||
nestedProfile := filepath.Join(nestedModule, "releasekit.json")
|
||||
nestedProfileData, err := os.ReadFile(filepath.Join(commandkitRoot, "integrations", "ckconfig", "releasekit.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var nestedFields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(nestedProfileData, &nestedFields); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nestedFields["expected_push_url"], err = json.Marshal(bare)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nestedProfileData, err = json.MarshalIndent(nestedFields, "", " ")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFile(t, nestedProfile, string(nestedProfileData)+"\n", 0o644)
|
||||
writeFile(t, filepath.Join(worktree, "fixture_test.go"), fixtureSuiteTest, 0o644)
|
||||
if err := os.MkdirAll(filepath.Join(worktree, "docs", "releases"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -158,13 +208,14 @@ func newPublicationFixture(t *testing.T, ctx context.Context, git string) public
|
||||
gitRun(t, ctx, git, worktree, gitEnv, "push", "origin", "HEAD:refs/heads/main")
|
||||
|
||||
return publicationFixture{
|
||||
root: root,
|
||||
worktree: worktree,
|
||||
bare: bare,
|
||||
outside: outside,
|
||||
profile: profile,
|
||||
gitConfig: configPath,
|
||||
gitEnv: gitEnv,
|
||||
root: root,
|
||||
worktree: worktree,
|
||||
bare: bare,
|
||||
outside: outside,
|
||||
profile: profile,
|
||||
nestedProfile: nestedProfile,
|
||||
gitConfig: configPath,
|
||||
gitEnv: gitEnv,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,9 +260,9 @@ func (fixture publicationFixture) prepareSecondCandidate(t *testing.T, ctx conte
|
||||
gitRun(t, ctx, git, fixture.worktree, fixture.gitEnv, "push", "origin", "HEAD:refs/heads/main")
|
||||
}
|
||||
|
||||
func runPublisher(t *testing.T, ctx context.Context, shell string, fixture publicationFixture, env []string, version string) (string, string, int) {
|
||||
func runPublisher(t *testing.T, ctx context.Context, shell string, fixture publicationFixture, env []string, module, version string) (string, string, int) {
|
||||
t.Helper()
|
||||
cmd := exec.CommandContext(ctx, shell, filepath.Join(fixture.worktree, "scripts", "release"), version)
|
||||
cmd := exec.CommandContext(ctx, shell, filepath.Join(fixture.worktree, "scripts", "release"), module, version)
|
||||
cmd.Dir = fixture.outside
|
||||
cmd.Env = env
|
||||
var stdout, stderr strings.Builder
|
||||
@@ -251,11 +302,16 @@ func assertTag(t *testing.T, ctx context.Context, git string, fixture publicatio
|
||||
}
|
||||
}
|
||||
|
||||
func assertOnlyTag(t *testing.T, ctx context.Context, git string, fixture publicationFixture, version string) {
|
||||
func assertTags(t *testing.T, ctx context.Context, git string, fixture publicationFixture, versions ...string) {
|
||||
t.Helper()
|
||||
local := gitRun(t, ctx, git, fixture.worktree, fixture.gitEnv, "for-each-ref", "--format=%(refname)", "refs/tags")
|
||||
remote := gitRun(t, ctx, git, fixture.root, fixture.gitEnv, "--git-dir", fixture.bare, "for-each-ref", "--format=%(refname)", "refs/tags")
|
||||
want := "refs/tags/" + version
|
||||
wantRefs := make([]string, len(versions))
|
||||
for i, version := range versions {
|
||||
wantRefs[i] = "refs/tags/" + version
|
||||
}
|
||||
sort.Strings(wantRefs)
|
||||
want := strings.Join(wantRefs, "\n")
|
||||
if local != want || remote != want {
|
||||
t.Fatalf("tag refs local=%q remote=%q, want only %q", local, remote, want)
|
||||
}
|
||||
@@ -309,7 +365,11 @@ func isolatedProcessEnv(overrides map[string]string, cleared ...string) []string
|
||||
}
|
||||
|
||||
func releaseNote(version string) string {
|
||||
return "# CommandKit " + version + "\n\nLocal fixture release candidate.\n"
|
||||
return releaseNoteFor("CommandKit", version)
|
||||
}
|
||||
|
||||
func releaseNoteFor(product, version string) string {
|
||||
return "# " + product + " " + version + "\n\nLocal fixture release candidate.\n"
|
||||
}
|
||||
|
||||
const fixtureSuiteTest = `package fixture
|
||||
|
||||
Reference in New Issue
Block a user