build

package
v0.0.0-...-0fa9925 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 16 Imported by: 70

Documentation

Overview

Package build models a build, a set of tasks that run on a variant. A variant is typically an operating system and some metadata. For example, it could run lint tasks on a Linux distribution.

Index

Constants

View Source
const Collection = "builds"

The MongoDB collection for build documents.

View Source
const IdTimeLayout = "06_01_02_15_04_05"

IdTimeLayout is used time time.Time.Format() to produce timestamps for our ids.

Variables

View Source
var (
	// bson fields for the build struct
	IdKey                         = bsonutil.MustHaveTag(Build{}, "Id")
	CreateTimeKey                 = bsonutil.MustHaveTag(Build{}, "CreateTime")
	StartTimeKey                  = bsonutil.MustHaveTag(Build{}, "StartTime")
	FinishTimeKey                 = bsonutil.MustHaveTag(Build{}, "FinishTime")
	VersionKey                    = bsonutil.MustHaveTag(Build{}, "Version")
	ProjectKey                    = bsonutil.MustHaveTag(Build{}, "Project")
	RevisionKey                   = bsonutil.MustHaveTag(Build{}, "Revision")
	BuildVariantKey               = bsonutil.MustHaveTag(Build{}, "BuildVariant")
	StatusKey                     = bsonutil.MustHaveTag(Build{}, "Status")
	GithubCheckStatusKey          = bsonutil.MustHaveTag(Build{}, "GithubCheckStatus")
	ActivatedKey                  = bsonutil.MustHaveTag(Build{}, "Activated")
	ActivatedByKey                = bsonutil.MustHaveTag(Build{}, "ActivatedBy")
	ActivatedTimeKey              = bsonutil.MustHaveTag(Build{}, "ActivatedTime")
	RevisionOrderNumberKey        = bsonutil.MustHaveTag(Build{}, "RevisionOrderNumber")
	TasksKey                      = bsonutil.MustHaveTag(Build{}, "Tasks")
	TimeTakenKey                  = bsonutil.MustHaveTag(Build{}, "TimeTaken")
	DisplayNameKey                = bsonutil.MustHaveTag(Build{}, "DisplayName")
	RequesterKey                  = bsonutil.MustHaveTag(Build{}, "Requester")
	PredictedMakespanKey          = bsonutil.MustHaveTag(Build{}, "PredictedMakespan")
	ActualMakespanKey             = bsonutil.MustHaveTag(Build{}, "ActualMakespan")
	IsGithubCheckKey              = bsonutil.MustHaveTag(Build{}, "IsGithubCheck")
	AbortedKey                    = bsonutil.MustHaveTag(Build{}, "Aborted")
	AllTasksBlockedKey            = bsonutil.MustHaveTag(Build{}, "AllTasksBlocked")
	HasUnfinishedEssentialTaskKey = bsonutil.MustHaveTag(Build{}, "HasUnfinishedEssentialTask")

	TaskCacheIdKey = bsonutil.MustHaveTag(TaskCache{}, "Id")
)
View Source
var All = db.Query(nil)

All returns all builds.

Functions

func ByAfterRevision

func ByAfterRevision(project, buildVariant string, revision int) db.Q

ByAfterRevision builds a query that returns all builds that happened at or after the given revision for the project/variant. Results are sorted by revision order, ascending.

func ByBeforeRevision

func ByBeforeRevision(project, buildVariant string, revision int) db.Q

ByBeforeRevision builds a query that returns all builds that happened before the given revision for the project/variant. Results are sorted by revision order, descending.

func ByBetweenBuilds

func ByBetweenBuilds(current, previous *Build) db.Q

ByBetweenBuilds returns all builds that happened between the current and previous build.

func ByFinishedAfter

func ByFinishedAfter(finishTime time.Time, project string, requester string) db.Q

ByFinishedAfter creates a query that returns all builds for a project/requester that were finished after the given time.

func ById

func ById(id string) db.Q

ById creates a query that finds a build by its _id.

func ByIds

func ByIds(ids []string) db.Q

ByIds creates a query that finds all builds with the given ids.

func ByProject

func ByProject(proj string) db.Q

ByProject creates a query that finds all builds for a given project id.

func ByProjectAndVariant

func ByProjectAndVariant(project, variant, requester string, statuses []string) db.Q

ByProjectAndVariant creates a query that finds all completed builds for a given project and variant, while also specifying a requester

func ByRecentlySuccessfulForProjectAndVariant

func ByRecentlySuccessfulForProjectAndVariant(revision int, project, variant string) db.Q

ByRecentlySuccessfulForProjectAndVariant builds a query that returns all builds before a given revision that were successful for a project + variant. Builds are sorted from most to least recent.

func ByRevisionAndVariant

func ByRevisionAndVariant(revision, variant string) db.Q

ByRevisionAndVariant creates a query that returns the non-patch build for a revision + buildvariant combination.

func ByRevisionWithSystemVersionRequester

func ByRevisionWithSystemVersionRequester(revision string) db.Q

ByRevisionWithSystemVersionRequester creates a query that returns all builds for a revision.

func ByVersion

func ByVersion(version string) db.Q

ByVersion creates a query that returns all builds for a given version.

func ByVersionAndVariant

func ByVersionAndVariant(version, bv string) db.Q

ByVersionAndVariant creates a query that finds all builds in a version for a given variant.

func ByVersions

func ByVersions(vIds []string) db.Q

ByVersions creates a query that finds all builds with the given version ids.

func FindProjectForBuild

func FindProjectForBuild(buildID string) (string, error)

func Remove

func Remove(id string) error

Remove deletes the build of the given id from the database

func SetBuildStartedForTasks

func SetBuildStartedForTasks(tasks []task.Task, caller string) error

SetBuildStartedForTasks sets tasks' builds status to started and activates them

func SetTasksCache

func SetTasksCache(buildId string, tasks []TaskCache) error

SetTasksCache updates one build with the given id to contain the given task caches.

func TryMarkStarted

func TryMarkStarted(buildId string, startTime time.Time) error

TryMarkStarted attempts to mark a build as started if it isn't already marked as such

func UpdateActivation

func UpdateActivation(buildIds []string, active bool, caller string) error

UpdateActivation updates builds with the given ids to the given activation setting.

func UpdateAllBuilds

func UpdateAllBuilds(query interface{}, update interface{}) error

func UpdateOne

func UpdateOne(query interface{}, update interface{}) error

UpdateOne updates one build.

Types

type Build

type Build struct {
	Id                  string        `bson:"_id" json:"_id"`
	CreateTime          time.Time     `bson:"create_time" json:"create_time,omitempty"`
	StartTime           time.Time     `bson:"start_time" json:"start_time,omitempty"`
	FinishTime          time.Time     `bson:"finish_time" json:"finish_time,omitempty"`
	Version             string        `bson:"version" json:"version,omitempty"`
	Project             string        `bson:"branch" json:"branch,omitempty"`
	Revision            string        `bson:"gitspec" json:"gitspec,omitempty"`
	BuildVariant        string        `bson:"build_variant" json:"build_variant,omitempty"`
	Status              string        `bson:"status" json:"status,omitempty"`
	Activated           bool          `bson:"activated" json:"activated,omitempty"`
	ActivatedBy         string        `bson:"activated_by" json:"activated_by,omitempty"`
	ActivatedTime       time.Time     `bson:"activated_time" json:"activated_time,omitempty"`
	RevisionOrderNumber int           `bson:"order,omitempty" json:"order,omitempty"`
	Tasks               []TaskCache   `bson:"tasks" json:"tasks"`
	TimeTaken           time.Duration `bson:"time_taken" json:"time_taken,omitempty"`
	DisplayName         string        `bson:"display_name" json:"display_name,omitempty"`
	PredictedMakespan   time.Duration `bson:"predicted_makespan" json:"predicted_makespan,omitempty"`
	ActualMakespan      time.Duration `bson:"actual_makespan" json:"actual_makespan,omitempty"`
	Aborted             bool          `bson:"aborted" json:"aborted,omitempty"`

	// The status of the subset of the build that's used for github checks
	GithubCheckStatus string `bson:"github_check_status,omitempty" json:"github_check_status,omitempty"`
	// does the build contain tasks considered for mainline github checks
	IsGithubCheck bool `bson:"is_github_check,omitempty" json:"is_github_check,omitempty"`

	// build requester - this is used to help tell the
	// reason this build was created. e.g. it could be
	// because the repotracker requested it (via tracking the
	// repository) or it was triggered by a developer
	// patch request
	Requester string `bson:"r" json:"r,omitempty"`

	// builds that are part of a child patch will store the id and number of the parent patch
	ParentPatchID     string `bson:"parent_patch_id,omitempty" json:"parent_patch_id,omitempty"`
	ParentPatchNumber int    `bson:"parent_patch_number,omitempty" json:"parent_patch_number,omitempty"`

	// Fields set if triggered by an upstream build
	TriggerID    string `bson:"trigger_id,omitempty" json:"trigger_id,omitempty"`
	TriggerType  string `bson:"trigger_type,omitempty" json:"trigger_type,omitempty"`
	TriggerEvent string `bson:"trigger_event,omitempty" json:"trigger_event,omitempty"`

	// Set to true if all tasks in the build are blocked.
	// Should not be exposed, only for internal use.
	AllTasksBlocked bool `bson:"all_tasks_blocked"`
	// HasUnfinishedEssentialTask tracks whether or not this build has at least
	// one unfinished essential task. The build cannot be in a finished state
	// until all of its essential tasks have finished.
	HasUnfinishedEssentialTask bool `bson:"has_unfinished_essential_task"`
}

Build represents a set of tasks on one variant of a Project e.g. one build might be "Ubuntu with Python 2.4" and another might be "OSX with Python 3.0", etc.

func Find

func Find(query db.Q) ([]Build, error)

Find returns all builds that satisfy the query.

func FindBuildsByVersions

func FindBuildsByVersions(versionIds []string) ([]Build, error)

FindBuildsByVersions finds builds matching the version. This only populates a subset of the build fields.

func FindBuildsForTasks

func FindBuildsForTasks(tasks []task.Task) ([]Build, error)

FindBuildsForTasks returns all builds that cover the given tasks

func FindOne

func FindOne(query db.Q) (*Build, error)

FindOne returns one build that satisfies the query.

func FindOneId

func FindOneId(id string) (*Build, error)

FindOneId returns one build by Id.

func (*Build) AllUnblockedTasksFinished

func (b *Build) AllUnblockedTasksFinished(tasks []task.Task) (bool, string, error)

AllUnblockedTasksOrCompileFinished returns true when all activated tasks in the build have one of the statuses in IsFinishedTaskStatus or the task is considered blocked

returns boolean to indicate if tasks are complete, string with either BuildFailed or BuildSucceeded. The string is only valid when the boolean is true

func (*Build) FindBuildOnBaseCommit

func (b *Build) FindBuildOnBaseCommit() (*Build, error)

FindBuildOnBaseCommit returns the build that a patch build is based on.

func (*Build) GetPRNotificationDescription

func (b *Build) GetPRNotificationDescription(tasks []task.Task) string

GetPRNotificationDescription returns a GitHub PR status description based on the statuses of tasks in the build, to be used by jobs and notification processing.

func (*Build) GetTimeSpent

func (b *Build) GetTimeSpent() (time.Duration, time.Duration, error)

func (*Build) GetURL

func (b *Build) GetURL(uiBase string) string

GetURL returns a url to the build page.

func (*Build) Insert

func (b *Build) Insert() error

Insert writes the b to the db.

func (*Build) IsFinished

func (b *Build) IsFinished() bool

Returns whether or not the build has finished, based on its status. In spite of the name, a build with status BuildFailed may still be in progress; use AllCachedTasksFinished

func (*Build) MarkFinished

func (b *Build) MarkFinished(status string, finishTime time.Time) error

MarkFinished sets the build to finished status in the database (this does not update task or version data).

func (*Build) MarshalBSON

func (b *Build) MarshalBSON() ([]byte, error)

func (*Build) PreviousSuccessful

func (b *Build) PreviousSuccessful() (*Build, error)

Find the most recent b on with the same build variant + requester + project as the current build, with any of the specified statuses.

func (*Build) SetAborted

func (b *Build) SetAborted(aborted bool) error

SetAborted sets the build aborted field to the given boolean.

func (*Build) SetActivated

func (b *Build) SetActivated(activated bool) error

SetActivated sets the build activated field to the given boolean.

func (*Build) SetAllTasksBlocked

func (b *Build) SetAllTasksBlocked(blocked bool) error

SetAllTasksBlocked sets the build AllTasksBlocked field to the given boolean.

func (*Build) SetHasUnfinishedEssentialTask

func (b *Build) SetHasUnfinishedEssentialTask(hasUnfinishedEssentialTask bool) error

SetHasUnfinishedEssentialTask sets whether or not the build has at least one unfinished essential task.

func (*Build) SetIsGithubCheck

func (b *Build) SetIsGithubCheck() error

func (*Build) UnmarshalBSON

func (b *Build) UnmarshalBSON(in []byte) error

func (*Build) UpdateGithubCheckStatus

func (b *Build) UpdateGithubCheckStatus(status string) error

func (*Build) UpdateMakespans

func (b *Build) UpdateMakespans(predictedMakespan, actualMakespan time.Duration) error

UpdateMakespans sets the builds predicted and actual makespans to given durations

func (*Build) UpdateStatus

func (b *Build) UpdateStatus(status string) error

UpdateStatus sets the build status to the given string.

type Builds

type Builds []*Build

func (Builds) InsertMany

func (b Builds) InsertMany(ctx context.Context, ordered bool) error

type TaskCache

type TaskCache struct {
	Id string `bson:"id" json:"id"`
}

TaskCache references the id of a task in the build

Jump to

Keyboard shortcuts

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