package e2e import ( "net/url" "os" "path/filepath" "strings" "testing" ) // TestReleaseAndBuildWeb creates and edits a release and triggers a build // from the browser, each through the command the CLI runs. func TestReleaseAndBuildWeb(t *testing.T) { t.Parallel() inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n") inst.runner = buildRunner(t) aliceKey := inst.newKey(t, "alice") inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub", "--email", "alice@example.test", "--verified") runnerKey := inst.newKey(t, "ci") inst.admin(t, "admin", "user", "create", "ci", "--key", runnerKey+".pub", "--admin") if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 { t.Fatalf("repo create: %s", errOut) } env := inst.gitEnv(aliceKey) work := t.TempDir() mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w") dir := filepath.Join(work, "w") os.MkdirAll(filepath.Join(dir, ".gitbay"), 0o755) os.WriteFile(filepath.Join(dir, ".gitbay", "ci.yml"), []byte("jobs:\n smoke:\n steps:\n - echo ok\n"), 0o644) os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a\n"), 0o644) mustGit(t, dir, env, "checkout", "-q", "-b", "main") mustGit(t, dir, env, "add", ".") mustGit(t, dir, env, "commit", "-q", "-m", "base") mustGit(t, dir, env, "tag", "-a", "v1.0", "-m", "first") mustGit(t, dir, env, "push", "-q", "origin", "main", "v1.0") alice := inst.login(t, aliceKey) base := inst.base() + "/alice/app" // The pushed tag is offered, and creating from it works. _, page := browserGet(t, alice, base+"/releases") if !strings.Contains(page, `value="v1.0"`) { t.Fatalf("tag not offered:\n%s", page) } if status, _ := browserPost(t, alice, base+"/releases", url.Values{ "tag": {"v1.0"}, "title": {"First light"}, "notes": {"the **first** one"}}); status != 200 { t.Fatal("release create failed") } out, _, _ := inst.ssh(t, aliceKey, "", "release", "show", "alice/app", "v1.0", "--json") if !strings.Contains(out, "First light") || !strings.Contains(out, "the **first** one") { t.Fatalf("release not created:\n%s", out) } // Editing keeps the tag and replaces the fields. if status, _ := browserPost(t, alice, base+"/releases", url.Values{ "action": {"edit"}, "tag": {"v1.0"}, "title": {"Second light"}, "notes": {"revised"}}); status != 200 { t.Fatal("release edit failed") } out, _, _ = inst.ssh(t, aliceKey, "", "release", "show", "alice/app", "v1.0", "--json") if !strings.Contains(out, "Second light") || !strings.Contains(out, "revised") { t.Fatalf("release not edited:\n%s", out) } // Summarize changes fills the notes box with one line per merge // request landed since the previous release, after what was typed, // and writes nothing (#331). mustGit(t, dir, env, "checkout", "-q", "-b", "feat") os.WriteFile(filepath.Join(dir, "b.txt"), []byte("b\n"), 0o644) mustGit(t, dir, env, "add", ".") mustGit(t, dir, env, "commit", "-q", "-m", "feat") mustGit(t, dir, env, "push", "-q", "origin", "feat") if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app", "--source", "feat", "--target", "main", "--title", "add-b"); code != 0 { t.Fatalf("mr create: %s", errOut) } if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1"); code != 0 { t.Fatalf("mr merge: %s", errOut) } mustGit(t, dir, env, "fetch", "-q", "origin") mustGit(t, dir, env, "tag", "v2.0", "origin/main") mustGit(t, dir, env, "push", "-q", "origin", "v2.0") status, page := browserPost(t, alice, base+"/releases", url.Values{ "tag": {"v2.0"}, "notes": {"Second cut."}, "summarize": {"1"}}) if status != 200 || !strings.Contains(page, "Second cut.\n\n- add-b (!1) by @alice\n") || !strings.Contains(page, `