This commit is contained in:
Brad Rydzewski 2019-03-14 10:16:19 -07:00
parent 5013cfa993
commit 4e4932512c
10 changed files with 32 additions and 35 deletions

View file

@ -245,6 +245,13 @@ func (m *Manager) Details(ctx context.Context, id int64) (*Context, error) {
logger.Warnln("manager: cannot find build")
return nil, err
}
stages, err := m.Stages.List(ctx, stage.BuildID)
if err != nil {
logger = logger.WithError(err)
logger.Warnln("manager: cannot list stages")
return nil, err
}
build.Stages = stages
repo, err := m.Repos.Find(noContext, build.RepoID)
if err != nil {
logger = logger.WithError(err)

View file

@ -372,13 +372,23 @@ func (r *Runner) Run(ctx context.Context, id int64) error {
s.Step.Envs["DRONE_JOB_STATUS"] = "success"
s.Step.Envs["DRONE_JOB_STARTED"] = strconv.FormatInt(s.Runtime.Time, 10)
s.Step.Envs["DRONE_JOB_FINISHED"] = strconv.FormatInt(time.Now().Unix(), 10)
s.Step.Envs["DRONE_STAGE_STATUS"] = "success"
s.Step.Envs["DRONE_STAGE_STARTED"] = strconv.FormatInt(s.Runtime.Time, 10)
s.Step.Envs["DRONE_STAGE_FINISHED"] = strconv.FormatInt(time.Now().Unix(), 10)
if s.Runtime.Error != nil {
s.Step.Envs["CI_BUILD_STATUS"] = "failure"
s.Step.Envs["CI_JOB_STATUS"] = "failure"
s.Step.Envs["DRONE_BUILD_STATUS"] = "failure"
s.Step.Envs["DRONE_STAGE_STATUS"] = "failure"
s.Step.Envs["DRONE_JOB_STATUS"] = "failure"
}
for _, stage := range m.Build.Stages {
if stage.IsFailed() {
s.Step.Envs["DRONE_BUILD_STATUS"] = "failure"
break
}
}
step, ok := steps[s.Step.Metadata.Name]
if ok {

View file

@ -315,7 +315,7 @@ CREATE TABLE IF NOT EXISTS builds (
,build_source VARCHAR(500)
,build_target VARCHAR(500)
,build_author VARCHAR(500)
,build_author_name VARCHAR(500)
,build_author_name VARCHAR(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
,build_author_email VARCHAR(500)
,build_author_avatar VARCHAR(1000)
,build_sender VARCHAR(500)

View file

@ -41,8 +41,8 @@ var migrations = []struct {
stmt: createTableBuilds,
},
{
name: "create-index-builds-in-progress",
stmt: createIndexBuildsInProgress,
name: "create-index-builds-incomplete",
stmt: createIndexBuildsIncomplete,
},
{
name: "create-index-builds-repo",
@ -220,7 +220,7 @@ CREATE TABLE IF NOT EXISTS users (
var createTableRepos = `
CREATE TABLE IF NOT EXISTS repos (
repo_id SERIAL PRIMARY KEY
repo_id SERIAL PRIMARY KEY
,repo_uid VARCHAR(250)
,repo_user_id INTEGER
,repo_namespace VARCHAR(250)
@ -326,9 +326,9 @@ CREATE TABLE IF NOT EXISTS builds (
);
`
var createIndexBuildsInProgress = `
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON builds (build_status)
WHERE build_status IN ('pending', 'running');
var createIndexBuildsIncomplete = `
CREATE INDEX IF NOT EXISTS ix_build_incomplete ON builds (build_status)
WHERE build_status IN ('pending', 'running');
`
var createIndexBuildsRepo = `
@ -345,9 +345,6 @@ CREATE INDEX IF NOT EXISTS ix_build_sender ON builds (build_sender);
var createIndexBuildsRef = `
CREATE INDEX IF NOT EXISTS ix_build_ref ON builds (build_repo_id, build_ref);
CREATE INDEX IF NOT EXISTS ix_build_incomplete ON builds (build_status)
WHERE build_status IN ('pending', 'running');
`
//
@ -391,7 +388,7 @@ CREATE INDEX IF NOT EXISTS ix_stages_build ON stages (stage_build_id);
`
var createIndexStagesStatus = `
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON stages (stage_status)
CREATE INDEX IF NOT EXISTS ix_stage_in_progress ON stages (stage_status)
WHERE stage_status IN ('pending', 'running');
`

View file

@ -1,7 +1,7 @@
-- name: create-table-repos
CREATE TABLE IF NOT EXISTS repos (
repo_id SERIAL PRIMARY KEY
repo_id SERIAL PRIMARY KEY
,repo_uid VARCHAR(250)
,repo_user_id INTEGER
,repo_namespace VARCHAR(250)

View file

@ -37,10 +37,10 @@ CREATE TABLE IF NOT EXISTS builds (
--,FOREIGN KEY(build_repo_id) REFERENCES repos(repo_id) ON DELETE CASCADE
);
-- name: create-index-builds-in-progress
-- name: create-index-builds-incomplete
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON builds (build_status)
WHERE build_status IN ('pending', 'running');
CREATE INDEX IF NOT EXISTS ix_build_incomplete ON builds (build_status)
WHERE build_status IN ('pending', 'running');
-- name: create-index-builds-repo
@ -57,6 +57,3 @@ CREATE INDEX IF NOT EXISTS ix_build_sender ON builds (build_sender);
-- name: create-index-builds-ref
CREATE INDEX IF NOT EXISTS ix_build_ref ON builds (build_repo_id, build_ref);
CREATE INDEX IF NOT EXISTS ix_build_incomplete ON builds (build_status)
WHERE build_status IN ('pending', 'running');

View file

@ -36,5 +36,5 @@ CREATE INDEX IF NOT EXISTS ix_stages_build ON stages (stage_build_id);
-- name: create-index-stages-status
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON stages (stage_status)
CREATE INDEX IF NOT EXISTS ix_stage_in_progress ON stages (stage_status)
WHERE stage_status IN ('pending', 'running');

View file

@ -40,10 +40,6 @@ var migrations = []struct {
name: "create-table-builds",
stmt: createTableBuilds,
},
{
name: "create-index-builds-in-progress",
stmt: createIndexBuildsInProgress,
},
{
name: "create-index-builds-repo",
stmt: createIndexBuildsRepo,
@ -329,11 +325,6 @@ CREATE TABLE IF NOT EXISTS builds (
);
`
var createIndexBuildsInProgress = `
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON builds (build_status)
WHERE build_status IN ('pending', 'running');
`
var createIndexBuildsRepo = `
CREATE INDEX IF NOT EXISTS ix_build_repo ON builds (build_repo_id);
`
@ -397,7 +388,7 @@ CREATE INDEX IF NOT EXISTS ix_stages_build ON stages (stage_build_id);
`
var createIndexStagesStatus = `
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON stages (stage_status)
CREATE INDEX IF NOT EXISTS ix_stage_in_progress ON stages (stage_status)
WHERE stage_status IN ('pending', 'running');
`

View file

@ -36,11 +36,6 @@ CREATE TABLE IF NOT EXISTS builds (
--,FOREIGN KEY(build_repo_id) REFERENCES repos(repo_id) ON DELETE CASCADE
);
-- name: create-index-builds-in-progress
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON builds (build_status)
WHERE build_status IN ('pending', 'running');
-- name: create-index-builds-repo
CREATE INDEX IF NOT EXISTS ix_build_repo ON builds (build_repo_id);

View file

@ -37,5 +37,5 @@ CREATE INDEX IF NOT EXISTS ix_stages_build ON stages (stage_build_id);
-- name: create-index-stages-status
CREATE INDEX IF NOT EXISTS ix_build_in_progress ON stages (stage_status)
CREATE INDEX IF NOT EXISTS ix_stage_in_progress ON stages (stage_status)
WHERE stage_status IN ('pending', 'running');