Recover publication against the captured endpoint
This commit is contained in:
@@ -61,7 +61,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stderr, "validating and publishing %s\n", invocation.Version)
|
||||
result, err := releasekit.Publish(ctx, request)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "publication state=%s phase=%s version=%s commit=%s tag-object=%s: %v\n", result.State, result.Phase, result.Version, result.CandidateCommit, result.TagObject, err)
|
||||
fmt.Fprintf(stderr, "publication state=%s phase=%s version=%s commit=%s tag-object=%s endpoint=%q: %v\n", result.State, result.Phase, result.Version, result.CandidateCommit, result.TagObject, result.Endpoint, err)
|
||||
if errors.Is(err, releasekit.ErrInvalidVersion) {
|
||||
return 2
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -57,6 +59,10 @@ func TestReleaseWrapperPreservesNativeExitStatuses(t *testing.T) {
|
||||
cliGitRun(t, repository, "init", "--bare", remote)
|
||||
cliGitRun(t, repository, "remote", "set-url", "origin", remote)
|
||||
cliGitRun(t, repository, "push", "origin", "HEAD:refs/heads/main")
|
||||
fetch := filepath.Join(t.TempDir(), "fetch.git")
|
||||
cliGitRun(t, repository, "init", "--bare", fetch)
|
||||
cliGitRun(t, repository, "remote", "set-url", "origin", fetch)
|
||||
cliGitRun(t, repository, "remote", "set-url", "--push", "origin", remote)
|
||||
if mode.name == "rejected" {
|
||||
if err := os.WriteFile(filepath.Join(remote, "hooks/pre-receive"), []byte("#!/bin/sh\nexit 1\n"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -67,7 +73,12 @@ func TestReleaseWrapperPreservesNativeExitStatuses(t *testing.T) {
|
||||
marker := filepath.Join(bin, "push-started")
|
||||
shim := `#!/bin/sh
|
||||
for arg do
|
||||
if [ "$arg" = push ]; then : > "$RELEASEKIT_TEST_PUSH_MARKER"; exit 1; fi
|
||||
if [ "$arg" = push ]; then
|
||||
"$RELEASEKIT_TEST_REAL_GIT" "$@" || exit 1
|
||||
"$RELEASEKIT_TEST_REAL_GIT" remote set-url --push origin "$RELEASEKIT_TEST_MOVED_ENDPOINT"
|
||||
: > "$RELEASEKIT_TEST_PUSH_MARKER"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ -f "$RELEASEKIT_TEST_PUSH_MARKER" ]; then
|
||||
for arg do if [ "$arg" = ls-remote ]; then exit 128; fi; done
|
||||
@@ -80,6 +91,7 @@ exec "$RELEASEKIT_TEST_REAL_GIT" "$@"
|
||||
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
t.Setenv("RELEASEKIT_TEST_REAL_GIT", realGit)
|
||||
t.Setenv("RELEASEKIT_TEST_PUSH_MARKER", marker)
|
||||
t.Setenv("RELEASEKIT_TEST_MOVED_ENDPOINT", fetch)
|
||||
}
|
||||
command := exec.Command("./scripts/release", mode.version)
|
||||
command.Dir = repository
|
||||
@@ -95,6 +107,26 @@ exec "$RELEASEKIT_TEST_REAL_GIT" "$@"
|
||||
if status != mode.status {
|
||||
t.Fatalf("status=%d want=%d output=%s", status, mode.status, output)
|
||||
}
|
||||
if mode.name == "unknown" {
|
||||
if !strings.Contains(string(output), fmt.Sprintf("endpoint=%q", remote)) {
|
||||
t.Fatalf("captured endpoint missing: %s", output)
|
||||
}
|
||||
query := exec.Command(realGit, "ls-remote", "--refs", "--", remote, "refs/tags/v1.2.3")
|
||||
query.Dir = repository
|
||||
found, err := query.Output()
|
||||
if err != nil || len(found) == 0 {
|
||||
t.Fatalf("captured endpoint lost published tag: %q %v", found, err)
|
||||
}
|
||||
if !strings.Contains(string(found), cliGitOutput(t, repository, "rev-parse", "refs/tags/v1.2.3")) {
|
||||
t.Fatalf("wrong recovered tag: %s", found)
|
||||
}
|
||||
fetchQuery := exec.Command(realGit, "ls-remote", "--refs", "origin", "refs/tags/v1.2.3")
|
||||
fetchQuery.Dir = repository
|
||||
stale, err := fetchQuery.Output()
|
||||
if err != nil || len(stale) != 0 {
|
||||
t.Fatalf("fetch fixture unexpectedly found tag: %q %v", stale, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user