circle

package module
v0.0.0-...-403f3a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 20 Imported by: 0

README

go-circle

CircleCI

This is a wrapper for the CircleCI API. Currently we use it to fetch the latest build for a branch, and wait for tests to finish on that branch. This fork exists because I left Shyp and wanted to keep developing the tool.

Usage

$ circle
The circle binary interacts with a server that runs your tests.

Usage:

	circle command [arguments]

The commands are:

	cancel              Cancel the current build.
	enable              Enable CircleCI tests for this project.
	open                Open the latest branch build in a browser.
	rebuild             Rebuild a given test branch.
	version             Print the current version
	wait                Wait for tests to finish on a branch.
	download-artifacts  Download all artifacts.

Use "circle help [command]" for more information about a command.

In particular, circle wait will print live statistics about how long each of your build steps are taking in each container. If the build fails, circle wait will download the console output from the failed build step, and display it in the console. wait also displays statistics about how long each step of your build took.

$ circle wait
Waiting for latest build on my-branch to complete
Build on my-branch succeeded!

Step                                         0
=====================================================
Spin up Environment                          1.07s
Checkout code                                730ms
Restoring Cache                              250ms
make race-test                               16.76s
Saving Cache                                 80ms

Tests on my-branch took 21s. Quitting.

Token Management

This library will look for your Circle API token in ~/cfg/circleci and (if that does not exist, in ~/.circlerc). The configuration file should look like this:

[organizations]

    [organizations.kevinburke]
    token = "aabbccddeeff00"

You can specify any organization name you want.

Installation

Find your target operating system (darwin, windows, linux) and desired bin directory, and modify the command below as appropriate:

curl --silent --location --output /usr/local/bin/circle https://github.com/kevinburke/go-circle/releases/download/0.33/circle-linux-amd64 && chmod 755 /usr/local/bin/circle

The latest version is 0.33.

If you have a Go development environment, you can also install via source code:

go get -u github.com/kevinburke/go-circle/...

This should place a circle binary in $GOPATH/bin, so for me, ~/bin/circle.

Documentation

Index

Constants

View Source
const VERSION = "0.34"

Variables

This section is empty.

Functions

func DownloadArtifact

func DownloadArtifact(ctx context.Context, artifact *CircleArtifact, directory string, org string) error

func Enable

func Enable(ctx context.Context, host string, org string, repoName string) error

func Rebuild

func Rebuild(ctx context.Context, tb *TreeBuild) error

Types

type Action

type Action struct {
	Name         string         `json:"name"`
	AllocationID string         `json:"allocation_id"`
	Index        uint16         `json:"index"`
	OutputURL    URL            `json:"output_url"`
	Runtime      CircleDuration `json:"run_time_millis"`
	Status       string         `json:"status"`
	Step         int            `json:"step"`

	// Failed is a boolean, but we defined it already as a function on the
	// Action so for compat we should pick a different name when we destructure
	// it.
	HasFailed bool `json:"failed"`
}

func (Action) Failed

func (a Action) Failed() bool

type CircleArtifact

type CircleArtifact struct {
	Path       string `json:"path"`
	PrettyPath string `json:"pretty_path"`
	NodeIndex  uint8  `json:"node_index"`
	Url        string `json:"url"`
}

func GetArtifactsForBuild

func GetArtifactsForBuild(ctx context.Context, host, org string, project string, buildNum int) ([]*CircleArtifact, error)

type CircleBuild

type CircleBuild struct {
	BuildNum                uint32         `json:"build_num"`
	Parallel                uint8          `json:"parallel"`
	Platform                string         `json:"platform"`
	PreviousSuccessfulBuild PreviousBuild  `json:"previous_successful_build"`
	QueuedAt                types.NullTime `json:"queued_at"`
	RepoName                string         `json:"reponame"` // "go"
	StartTime               types.NullTime `json:"start_time"`
	Status                  string         `json:"status"`
	Steps                   []Step         `json:"steps"`
	StopTime                types.NullTime `json:"stop_time"`
	VCSType                 string         `json:"vcs_type"` // "github", "bitbucket"
	UsageQueuedAt           types.NullTime `json:"usage_queued_at"`
	Username                string         `json:"username"` // "golang"
}

func CancelBuild

func CancelBuild(ctx context.Context, host, org, project string, buildNum int) (*CircleBuild, error)

func GetBuild

func GetBuild(ctx context.Context, host, org string, project string, buildNum int) (*CircleBuild, error)

func (*CircleBuild) Elapsed

func (cb *CircleBuild) Elapsed() time.Duration

Elapsed gives our best estimate of the amount of time that has elapsed since CircleCI found out about the build.

func (CircleBuild) FailureTexts

func (cb CircleBuild) FailureTexts(ctx context.Context) ([]string, error)

func (CircleBuild) Failures

func (cb CircleBuild) Failures() [][2]int

Failures returns an array of (buildStep, containerID) integers identifying the IDs of container/build step pairs that failed.

func (*CircleBuild) Statistics

func (cb *CircleBuild) Statistics(tty bool) string

Statistics prints out statistics for the given build. If stdout is a TTY, failed builds will be surrounded by red ANSI escape sequences.

type CircleConfig

type CircleConfig struct {
	Organizations map[string]organization
}

type CircleDuration

type CircleDuration time.Duration

func (*CircleDuration) UnmarshalJSON

func (cd *CircleDuration) UnmarshalJSON(b []byte) error

type CircleOutput

type CircleOutput struct {
	Message string    `json:"message"`
	Time    time.Time `json:"time"`
	Type    string    `json:"type"`
}

type CircleOutputs

type CircleOutputs []*CircleOutput

type CircleTreeResponse

type CircleTreeResponse []TreeBuild

func GetTree

func GetTree(host, org string, project string, branch string) (*CircleTreeResponse, error)

func GetTreeContext

func GetTreeContext(ctx context.Context, host, org, project, branch string) (*CircleTreeResponse, error)

type FollowResponse

type FollowResponse struct {
	Following bool `json:"following"`
}

type PreviousBuild

type PreviousBuild struct {
	BuildNum int `json:"build_num"`
	// would be neat to make this a time.Duration, easier to use the passed in
	// value.
	Status string `json:"status"`

	BuildDurationMs int `json:"build_time_millis"`
}

type Step

type Step struct {
	Name    string   `json:"name"`
	Actions []Action `json:"actions"`
}

type TreeBuild

type TreeBuild struct {
	BuildNum   int    `json:"build_num"`
	BuildURL   string `json:"build_url"`
	CompareURL string `json:"compare"`
	// Tree builds have a `previous_successful_build` field but as far as I can
	// tell it is always null. Instead this field is set
	Previous      PreviousBuild  `json:"previous"`
	QueuedAt      types.NullTime `json:"queued_at"`
	RepoName      string         `json:"reponame"`
	Status        string         `json:"status"`
	StartTime     types.NullTime `json:"start_time"`
	StopTime      types.NullTime `json:"stop_time"`
	UsageQueuedAt types.NullTime `json:"usage_queued_at"`
	Username      string         `json:"username"`
	VCSRevision   string         `json:"vcs_revision"`
	VCSType       string         `json:"vcs_type"`
}

func (*TreeBuild) Elapsed

func (tb *TreeBuild) Elapsed() time.Duration

Elapsed gives our best estimate of the amount of time that has elapsed since CircleCI found out about the build.

func (TreeBuild) Failed

func (tb TreeBuild) Failed() bool

func (TreeBuild) NotRunning

func (tb TreeBuild) NotRunning() bool

func (TreeBuild) Passed

func (tb TreeBuild) Passed() bool

func (TreeBuild) Running

func (tb TreeBuild) Running() bool

type URL

type URL struct {
	*url.URL
}

Unmarshallable URL

func (*URL) UnmarshalJSON

func (oururl *URL) UnmarshalJSON(b []byte) error

type VCS

type VCS string
const VCSTypeBitbucket VCS = "bitbucket"
const VCSTypeGithub VCS = "github"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL