build

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// These flags override values in build env.
	GitCommitFlag   = flag.String("git-commit", "", `Overrides git commit hash embedded into executables`)
	GitBranchFlag   = flag.String("git-branch", "", `Overrides git branch being built`)
	GitTagFlag      = flag.String("git-tag", "", `Overrides git tag being built`)
	BuildnumFlag    = flag.String("buildnum", "", `Overrides CI build number`)
	PullRequestFlag = flag.Bool("pull-request", false, `Overrides pull request status of the build`)
	CronJobFlag     = flag.Bool("cron-job", false, `Overrides cron job status of the build`)
)
View Source
var DryRunFlag = flag.Bool("n", false, "dry run, don't execute commands")
View Source
var (
	ErrReleaseNotFound = errors.New("release is not found")
)

ErrReleaseNotFound contains the error for when a release is not found

Functions

func AddFile

func AddFile(a Archive, file string) error

AddFile appends an existing file to an archive.

func ExtractArchive added in v0.6.0

func ExtractArchive(archive string, dest string) error

ExtractArchive unpacks a .zip or .tar.gz archive to the destination directory.

func GoTool

func GoTool(tool string, args ...string) *exec.Cmd

GoTool returns the command that runs a go tool. This uses go from GOROOT instead of PATH so that go commands executed by build use the same version of Go as the 'host' that runs build code. e.g.

go run build/ci.go ...

runs using go 1.12.1 and invokes go 1.12.1 tools from the same GOROOT. This is also important because runtime.Version checks on the host should match the tools that are run.

func LocalAssets added in v0.7.0

func LocalAssets(path string) ([]string, error)

LocalAssets contains the local objects to be uploaded

func MustRun

func MustRun(cmd *exec.Cmd)

MustRun executes the given command and exits the host process for any error.

func MustRunCommand

func MustRunCommand(cmd string, args ...string)

func Render

func Render(templateFile, outputFile string, outputPerm os.FileMode, x interface{})

Render renders the given template file into outputFile.

func RenderString

func RenderString(templateContent, outputFile string, outputPerm os.FileMode, x interface{})

RenderString renders the given template string into outputFile.

func RunGit

func RunGit(args ...string) string

RunGit runs a git subcommand and returns its output. The command must complete successfully.

func SHA256Assets added in v0.7.0

func SHA256Assets(files []string) ([]string, error)

SHA256Assets contains the local objects SHA Hashes

func UploadSFTP

func UploadSFTP(identityFile, host, dir string, files []string) error

UploadSFTP uploads files to a remote host using the sftp command line tool. The destination host may be specified either as [user@]host[: or as a URI in the form sftp://[user@]host[:port].

func WriteArchive

func WriteArchive(name string, files []string) (err error)

WriteArchive creates an archive containing the given files.

Types

type Archive

type Archive interface {
	// Directory adds a new directory entry to the archive and sets the
	// directory for subsequent calls to Header.
	Directory(name string) error

	// Header adds a new file to the archive. The file is added to the directory
	// set by Directory. The content of the file must be written to the returned
	// writer.
	Header(os.FileInfo) (io.Writer, error)

	// Close flushes the archive and closes the underlying file.
	Close() error
}

func NewArchive

func NewArchive(file *os.File) (Archive, string)

func NewTarballArchive

func NewTarballArchive(w io.WriteCloser) Archive

func NewZipArchive

func NewZipArchive(w io.WriteCloser) Archive

type ChecksumDB

type ChecksumDB struct {
	// contains filtered or unexported fields
}

ChecksumDB keeps file checksums.

func MustLoadChecksums

func MustLoadChecksums(file string) *ChecksumDB

MustLoadChecksums loads a file containing checksums.

func (*ChecksumDB) DownloadFile

func (db *ChecksumDB) DownloadFile(url, dstPath string) error

DownloadFile downloads a file and verifies its checksum.

func (*ChecksumDB) Verify

func (db *ChecksumDB) Verify(path string) error

Verify checks whether the given file is valid according to the checksum database.

type Environment

type Environment struct {
	Name                      string // name of the environment
	Repo                      string // name of GitHub repo
	Commit, Date, Branch, Tag string // Git info
	Buildnum                  string
	IsPullRequest             bool
	IsCronJob                 bool
}

Environment contains metadata provided by the build environment.

func Env

func Env() Environment

func LocalEnv

func LocalEnv() Environment

LocalEnv returns build environment metadata gathered from git.

func (Environment) String

func (env Environment) String() string

type GitHub added in v0.7.0

type GitHub interface {
	CreateRelease(ctx context.Context, req *github.RepositoryRelease) (*github.RepositoryRelease, error)
	GetRelease(ctx context.Context, tag string) (*github.RepositoryRelease, error)
	EditRelease(ctx context.Context, releaseID int64, req *github.RepositoryRelease) (*github.RepositoryRelease, error)
	DeleteRelease(ctx context.Context, releaseID int64) error
	DeleteTag(ctx context.Context, tag string) error

	UploadAsset(ctx context.Context, releaseID int64, filename string) (*github.ReleaseAsset, error)
	DeleteAsset(ctx context.Context, assetID int64) error
	ListAssets(ctx context.Context, releaseID int64) ([]*github.ReleaseAsset, error)

	SetUploadURL(urlStr string) error
}

GitHub contains the functions necessary for interacting with GitHub release objects

func NewGitHubClient added in v0.7.0

func NewGitHubClient(owner, repo, token, urlStr string) (GitHub, error)

NewGitHubClient creates and initializes a new GitHubClient

type GitHubClient added in v0.7.0

type GitHubClient struct {
	Owner, Repo string
	*github.Client
}

GitHubClient is the client for interacting with the GitHub API

func (*GitHubClient) CreateRelease added in v0.7.0

CreateRelease creates a new release object in the GitHub API

func (*GitHubClient) DeleteAsset added in v0.7.0

func (c *GitHubClient) DeleteAsset(ctx context.Context, assetID int64) error

DeleteAsset deletes assets from a given release object

func (*GitHubClient) DeleteRelease added in v0.7.0

func (c *GitHubClient) DeleteRelease(ctx context.Context, releaseID int64) error

DeleteRelease deletes a release object within the GitHub API

func (*GitHubClient) DeleteTag added in v0.7.0

func (c *GitHubClient) DeleteTag(ctx context.Context, tag string) error

DeleteTag deletes a tag from the GitHub API

func (*GitHubClient) EditRelease added in v0.7.0

func (c *GitHubClient) EditRelease(ctx context.Context, releaseID int64, req *github.RepositoryRelease) (*github.RepositoryRelease, error)

EditRelease edit a release object within the GitHub API

func (*GitHubClient) GetRelease added in v0.7.0

func (c *GitHubClient) GetRelease(ctx context.Context, tag string) (*github.RepositoryRelease, error)

GetRelease queries the GitHub API for a specified release object

func (*GitHubClient) ListAssets added in v0.7.0

func (c *GitHubClient) ListAssets(ctx context.Context, releaseID int64) ([]*github.ReleaseAsset, error)

ListAssets lists assets associated with a given release

func (*GitHubClient) SetUploadURL added in v0.7.0

func (c *GitHubClient) SetUploadURL(urlStr string) error

SetUploadURL constructs the upload URL for a release

func (*GitHubClient) UploadAsset added in v0.7.0

func (c *GitHubClient) UploadAsset(ctx context.Context, releaseID int64, filename string) (*github.ReleaseAsset, error)

UploadAsset uploads specified assets to a given release object

type TarballArchive

type TarballArchive struct {
	// contains filtered or unexported fields
}

func (*TarballArchive) Close

func (a *TarballArchive) Close() error

func (*TarballArchive) Directory

func (a *TarballArchive) Directory(name string) error

func (*TarballArchive) Header

func (a *TarballArchive) Header(fi os.FileInfo) (io.Writer, error)

type ZipArchive

type ZipArchive struct {
	// contains filtered or unexported fields
}

func (*ZipArchive) Close

func (a *ZipArchive) Close() error

func (*ZipArchive) Directory

func (a *ZipArchive) Directory(name string) error

func (*ZipArchive) Header

func (a *ZipArchive) Header(fi os.FileInfo) (io.Writer, error)

Jump to

Keyboard shortcuts

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