Skip to content

Commit

Permalink
Merge pull request #135 from zaquestion/ci
Browse files Browse the repository at this point in the history
[#74] Add (beta) CI Pipeline interface: live view-only
  • Loading branch information
zaquestion authored Apr 23, 2018
2 parents df3daec + e9d401b commit 2d1a880
Show file tree
Hide file tree
Showing 15 changed files with 1,210 additions and 142 deletions.
97 changes: 66 additions & 31 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
version = "0.1.2"

[[constraint]]
branch = "master"
name = "github.com/xanzy/go-gitlab"
revision = "266c87ba209d842f6c190920a55db959e5b13971"

[[constraint]]
name = "github.com/gdamore/tcell"
revision = "2f258105ca8ce35819115b49f5ac58197241653e"
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ test:
bash -c "trap 'trap - SIGINT SIGTERM ERR; mv testdata/.git testdata/test.git; rm coverage-* 2>&1 > /dev/null; exit 1' SIGINT SIGTERM ERR; $(MAKE) internal-test"

internal-test:
dep ensure
rm coverage-* 2>&1 > /dev/null || true
mv testdata/test.git testdata/.git
go test -coverprofile=coverage-main.out -covermode=count -coverpkg ./... -run=$(run) github.com/zaquestion/lab/cmd github.com/zaquestion/lab/internal/...
Expand Down
4 changes: 1 addition & 3 deletions cmd/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
// ciCmd represents the ci command
var ciCmd = &cobra.Command{
Use: "ci",
Short: "",
Short: "Work with GitLab CI pipelines and jobs",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
},
}

func init() {
Expand Down
32 changes: 15 additions & 17 deletions cmd/ciTrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// ciLintCmd represents the lint command
var ciTraceCmd = &cobra.Command{
Use: "trace [remote [[<tree-ish>:]job]]",
Use: "trace [remote [[branch:]job]]",
Aliases: []string{"logs"},
Short: "Trace the output of a ci job",
Long: `If a job is not specified the latest running job or last job in the pipeline is used`,
Expand All @@ -27,16 +27,26 @@ var ciTraceCmd = &cobra.Command{
remote string
jobName string
)

branch, err := git.CurrentBranch()
if err != nil {
log.Fatal(err)
}
if len(args) > 1 {
jobName = args[1]
if strings.Contains(args[1], ":") {
ps := strings.Split(args[1], ":")
branch, jobName = ps[0], ps[1]
}
}
remote = determineSourceRemote(branch)
if len(args) > 0 {
ok, err := git.IsRemote(args[0])
if err != nil || !ok {
log.Fatal(args[0], "is not a remote:", err)
}
remote = args[0]
}
if remote == "" {
remote = forkedFromRemote
}

rn, err := git.PathWithNameSpace(remote)
if err != nil {
Expand All @@ -46,25 +56,13 @@ var ciTraceCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}
var ref = "HEAD"
if len(args) > 1 {
jobName = args[1]
if strings.Contains(args[1], ":") {
ps := strings.Split(args[1], ":")
ref, jobName = ps[0], ps[1]
}
}
sha, err := git.Sha(ref)
if err != nil {
log.Fatal(err)
}
var (
once sync.Once
offset int64
)
FOR:
for range time.NewTicker(time.Second * 3).C {
trace, job, err := lab.CITrace(project.ID, sha, jobName)
trace, job, err := lab.CITrace(project.ID, branch, jobName)
if job == nil {
log.Fatal(errors.Wrap(err, "failed to find job"))
}
Expand Down
17 changes: 12 additions & 5 deletions cmd/ciTrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func Test_ciTrace(t *testing.T) {
t.Fatal(err)
}

cmd = exec.Command("../lab_bin", "checkout", "-b", "ci_test_pipeline")
cmd.Dir = repo
if b, err := cmd.CombinedOutput(); err != nil {
t.Log(string(b))
t.Fatal(err)
}

tests := []struct {
desc string
args []string
Expand All @@ -33,7 +40,7 @@ func Test_ciTrace(t *testing.T) {
desc: "noargs",
args: []string{},
assertContains: func(t *testing.T, out string) {
assert.Contains(t, out, "Showing logs for deploy10 job #62958489")
assert.Contains(t, out, "Showing logs for deploy10")
assert.Contains(t, out, "Checking out 09b519cb as ci_test_pipeline...")
assert.Contains(t, out, "For example you might run an update here or install a build dependency")
assert.Contains(t, out, "$ echo \"Or perhaps you might print out some debugging details\"")
Expand All @@ -51,18 +58,18 @@ func Test_ciTrace(t *testing.T) {
desc: "arg job name",
args: []string{"origin", "deploy1"},
assertContains: func(t *testing.T, out string) {
assert.Contains(t, out, "Showing logs for deploy1 job #62958479")
assert.Contains(t, out, "Showing logs for deploy1")
assert.Contains(t, out, "Checking out 09b519cb as ci_test_pipeline...")
assert.Contains(t, out, "For example you might run an update here or install a build dependency")
assert.Contains(t, out, "$ echo \"Or perhaps you might print out some debugging details\"")
assert.Contains(t, out, "Job succeeded")
},
},
{
desc: "explicit sha:job",
args: []string{"origin", "09b519cba018b707c98fc56e37df15806d89d866:deploy1"},
desc: "explicit branch:job",
args: []string{"origin", "ci_test_pipeline:deploy1"},
assertContains: func(t *testing.T, out string) {
assert.Contains(t, out, "Showing logs for deploy1 job #62958479")
assert.Contains(t, out, "Showing logs for deploy1")
assert.Contains(t, out, "Checking out 09b519cb as ci_test_pipeline...")
assert.Contains(t, out, "For example you might do some cleanup here")
assert.Contains(t, out, "Job succeeded")
Expand Down
Loading

0 comments on commit 2d1a880

Please sign in to comment.