diff --git a/go.mod b/go.mod index 6f226893..3157f288 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/drone/drone-go v0.0.0-20190217024616-3e8b71333e59 github.com/drone/drone-runtime v0.0.0-20190210191445-ad403a0ca24e github.com/drone/drone-ui v0.0.0-20190223014501-189a4d227db5 - github.com/drone/drone-yaml v1.0.2 + github.com/drone/drone-yaml v1.0.3 github.com/drone/envsubst v1.0.1 github.com/drone/go-license v1.0.2 github.com/drone/go-login v1.0.4-0.20190311170324-2a4df4f242a2 diff --git a/go.sum b/go.sum index c7869a50..8cfd378d 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/drone/drone-yaml v1.0.1 h1:a5t5zCqDFRa791B6/7i19rSpuT9slublvCGt5v0tl+ github.com/drone/drone-yaml v1.0.1/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI= github.com/drone/drone-yaml v1.0.2 h1:nj66Fi8LcFUHqSACjDou8QbWgU+3ZLFvsbafQCrfH1w= github.com/drone/drone-yaml v1.0.2/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI= +github.com/drone/drone-yaml v1.0.3 h1:9uTWC9xkIq4bv/2/hGd627VEc06Is576wFYxdOjUll0= +github.com/drone/drone-yaml v1.0.3/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI= github.com/drone/envsubst v1.0.1 h1:NOOStingM2sbBwsIUeQkKUz8ShwCUzmqMxWrpXItfPE= github.com/drone/envsubst v1.0.1/go.mod h1:bkZbnc/2vh1M12Ecn7EYScpI4YGYU0etwLJICOWi8Z0= github.com/drone/go-license v1.0.2 h1:7OwndfYk+Lp/cGHkxe4HUn/Ysrrw3WYH2pnd99yrkok= @@ -117,7 +119,6 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6 h1:qCv4319q2q7XKn0MQbi8p37hsJ+9Xo8e6yojA73JVxk= github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6/go.mod h1:fXcdFsQoipQa7mwORhKad5jmDCeSy/RCGzWA08PO0lM= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/nomad v0.0.0-20190125003214-134391155854 h1:L7WhLZt2ory/kQWxqkMwOiBpIoa4BWoadN7yx8LHEtk= diff --git a/operator/manager/manager.go b/operator/manager/manager.go index ee44d3c5..ba51f3f3 100644 --- a/operator/manager/manager.go +++ b/operator/manager/manager.go @@ -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) diff --git a/operator/runner/runner.go b/operator/runner/runner.go index fd903e0d..22c1c6e9 100644 --- a/operator/runner/runner.go +++ b/operator/runner/runner.go @@ -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 { diff --git a/store/shared/migrate/mysql/ddl_gen.go b/store/shared/migrate/mysql/ddl_gen.go index 4777cef4..03bda8f5 100644 --- a/store/shared/migrate/mysql/ddl_gen.go +++ b/store/shared/migrate/mysql/ddl_gen.go @@ -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) diff --git a/store/shared/migrate/postgres/ddl_gen.go b/store/shared/migrate/postgres/ddl_gen.go index 427eb6d5..d5056de3 100644 --- a/store/shared/migrate/postgres/ddl_gen.go +++ b/store/shared/migrate/postgres/ddl_gen.go @@ -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'); ` diff --git a/store/shared/migrate/postgres/files/002_create_table_repos.sql b/store/shared/migrate/postgres/files/002_create_table_repos.sql index 4d5324b2..8b5078f8 100644 --- a/store/shared/migrate/postgres/files/002_create_table_repos.sql +++ b/store/shared/migrate/postgres/files/002_create_table_repos.sql @@ -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) diff --git a/store/shared/migrate/postgres/files/004_create_table_builds.sql b/store/shared/migrate/postgres/files/004_create_table_builds.sql index 6aa4db59..fa6fe527 100644 --- a/store/shared/migrate/postgres/files/004_create_table_builds.sql +++ b/store/shared/migrate/postgres/files/004_create_table_builds.sql @@ -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'); \ No newline at end of file diff --git a/store/shared/migrate/postgres/files/005_create_table_stages.sql b/store/shared/migrate/postgres/files/005_create_table_stages.sql index 4c20548c..7900a2cd 100644 --- a/store/shared/migrate/postgres/files/005_create_table_stages.sql +++ b/store/shared/migrate/postgres/files/005_create_table_stages.sql @@ -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'); diff --git a/store/shared/migrate/sqlite/ddl_gen.go b/store/shared/migrate/sqlite/ddl_gen.go index fce2e820..6e4ba500 100644 --- a/store/shared/migrate/sqlite/ddl_gen.go +++ b/store/shared/migrate/sqlite/ddl_gen.go @@ -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'); ` diff --git a/store/shared/migrate/sqlite/files/004_create_table_builds.sql b/store/shared/migrate/sqlite/files/004_create_table_builds.sql index 5ad2b802..9f15fe3d 100644 --- a/store/shared/migrate/sqlite/files/004_create_table_builds.sql +++ b/store/shared/migrate/sqlite/files/004_create_table_builds.sql @@ -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); diff --git a/store/shared/migrate/sqlite/files/005_create_table_stages.sql b/store/shared/migrate/sqlite/files/005_create_table_stages.sql index 24f17373..16c91453 100644 --- a/store/shared/migrate/sqlite/files/005_create_table_stages.sql +++ b/store/shared/migrate/sqlite/files/005_create_table_stages.sql @@ -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');