Beispiel #1
0
func main() {
	d := bigtext.Client{
		Name:    "bigtext",
		LogoURL: "http://icons.iconarchive.com/icons/xenatt/the-circle/512/App-Terminal-icon.png",
		OpenURL: "https://google.com",
	}
	log.Fatal(d.Display("why hello there"))
}
Beispiel #2
0
func Wait(branch string) error {
	remote, err := git.GetRemoteURL("origin")
	if err != nil {
		return err
	}
	tip, err := git.Tip(branch)
	if err != nil {
		return err
	}
	fmt.Println("Waiting for latest build on", branch, "to complete")
	// Give CircleCI a little bit of time to start
	time.Sleep(1 * time.Second)
	for {
		cr, err := circle.GetTree(remote.Path, remote.RepoName, branch)
		if err != nil {
			if isHttpError(err) {
				fmt.Printf("Caught network error: %s. Continuing\n", err.Error())
				time.Sleep(2 * time.Second)
				continue
			}
			return err
		}
		if len(*cr) == 0 {
			return fmt.Errorf("No results, are you sure there are tests for %s/%s?\n",
				remote.Path, remote.RepoName)
		}
		latestBuild := (*cr)[0]
		var vcsLen int
		var tipLen int
		if len(latestBuild.VCSRevision) > 8 {
			vcsLen = 8
		} else {
			vcsLen = len(latestBuild.VCSRevision)
		}
		if len(tip) > 8 {
			tipLen = 8
		} else {
			tipLen = len(tip)
		}
		if latestBuild.VCSRevision[:tipLen] != tip {
			fmt.Printf("Latest build in Circle is %s, waiting for %s...\n",
				latestBuild.VCSRevision[:vcsLen], tip[:tipLen])
			time.Sleep(5 * time.Second)
			continue
		}
		var duration time.Duration
		if latestBuild.QueuedAt.Valid {
			if latestBuild.StopTime.Valid {
				duration = latestBuild.StopTime.Time.Sub(latestBuild.QueuedAt.Time)
			} else {
				duration = time.Now().Sub(latestBuild.QueuedAt.Time)
			}
		} else if latestBuild.UsageQueuedAt.Valid {
			if latestBuild.StopTime.Valid {
				duration = latestBuild.StopTime.Time.Sub(latestBuild.UsageQueuedAt.Time)
			} else {
				duration = time.Now().Sub(latestBuild.UsageQueuedAt.Time)
			}
		}
		duration = roundDuration(duration, time.Second)
		if latestBuild.Passed() {
			fmt.Printf("Build on %s succeeded!\n\n", branch)
			fmt.Printf(getStats(remote.Path, remote.RepoName, latestBuild.BuildNum))
			fmt.Printf("\nTests on %s took %s. Quitting.\n", branch, duration.String())
			c := bigtext.Client{
				Name:    fmt.Sprintf("%s (go-circle)", remote.RepoName),
				OpenURL: latestBuild.BuildURL,
			}
			c.Display(fmt.Sprintf("%s build complete!", branch))
			break
		} else if latestBuild.Failed() {
			fmt.Printf(getStats(remote.Path, remote.RepoName, latestBuild.BuildNum))
			fmt.Printf("\nURL: %s\n", latestBuild.BuildURL)
			err = fmt.Errorf("Build on %s failed!\n\n", branch)
			c := bigtext.Client{
				Name:    fmt.Sprintf("%s (go-circle)", remote.RepoName),
				OpenURL: latestBuild.BuildURL,
			}
			c.Display("build failed")
			return err
		} else {
			if latestBuild.Status == "running" {
				fmt.Printf("Running (%s elapsed)\n", duration.String())
			} else if latestBuild.NotRunning() {
				cost := getEffectiveCost(duration)
				centsPortion := cost % 100
				dollarPortion := cost / 100
				costStr := fmt.Sprintf("$%d.%.2d", dollarPortion, centsPortion)
				fmt.Printf("Status is %s (queued for %s, cost %s), trying again\n",
					latestBuild.Status, duration.String(), costStr)
			} else {
				fmt.Printf("Status is %s, trying again\n", latestBuild.Status)
			}
			// Sleep less and less as we approach the duration of the previous
			// successful build
			buildDuration := time.Duration(latestBuild.Previous.BuildDurationMs) * time.Millisecond
			if latestBuild.Previous.Status == "success" || latestBuild.Previous.Status == "fixed" {
				if duration < time.Minute {
					// First minute, errors are slightly more likely.
					time.Sleep(5 * time.Second)
				} else {
					timeRemaining := buildDuration - duration
					if timeRemaining > 5*time.Minute {
						time.Sleep(30 * time.Second)
					} else if timeRemaining > 3*time.Minute {
						time.Sleep(20 * time.Second)
					} else if timeRemaining > time.Minute {
						time.Sleep(15 * time.Second)
					} else if timeRemaining > 30*time.Second {
						time.Sleep(10 * time.Second)
					} else if timeRemaining > 10*time.Second {
						time.Sleep(5 * time.Second)
					} else {
						time.Sleep(3 * time.Second)
					}
				}
			} else {
				if float32(duration) < (2.5 * float32(time.Minute)) {
					time.Sleep(10 * time.Second)
				} else {
					time.Sleep(5 * time.Second)
				}
			}
		}
	}
	return nil
}