From 96d1a99428364145987ad8cd4f628bf73f47ed2e Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 9 Nov 2020 15:32:17 -0500 Subject: [PATCH] add debug field to build --- core/build.go | 1 + core/hook.go | 1 + go.mod | 2 +- go.sum | 2 ++ handler/api/repos/builds/retry.go | 4 ++++ store/build/build.go | 3 +++ store/build/scan.go | 2 ++ store/repos/repos.go | 1 + store/repos/scan.go | 1 + store/repos/type.go | 2 ++ store/shared/migrate/mysql/ddl_gen.go | 8 ++++++++ .../migrate/mysql/files/004_create_table_builds.sql | 6 +++++- store/shared/migrate/postgres/ddl_gen.go | 8 ++++++++ .../migrate/postgres/files/004_create_table_builds.sql | 4 ++++ store/shared/migrate/sqlite/ddl_gen.go | 8 ++++++++ .../migrate/sqlite/files/004_create_table_builds.sql | 4 ++++ trigger/trigger.go | 3 +++ 17 files changed, 58 insertions(+), 2 deletions(-) diff --git a/core/build.go b/core/build.go index 28b092bd..c164535c 100644 --- a/core/build.go +++ b/core/build.go @@ -46,6 +46,7 @@ type Build struct { Cron string `db:"build_cron" json:"cron,omitempty"` Deploy string `db:"build_deploy" json:"deploy_to,omitempty"` DeployID int64 `db:"build_deploy_id" json:"deploy_id,omitempty"` + Debug bool `db:"build_debug" json:"debug,omitempty"` Started int64 `db:"build_started" json:"started"` Finished int64 `db:"build_finished" json:"finished"` Created int64 `db:"build_created" json:"created"` diff --git a/core/hook.go b/core/hook.go index ef8fc1d3..6b050956 100644 --- a/core/hook.go +++ b/core/hook.go @@ -50,6 +50,7 @@ type Hook struct { AuthorAvatar string `json:"author_avatar"` Deployment string `json:"deploy_to"` DeploymentID int64 `json:"deploy_id"` + Debug bool `json:"debug"` Cron string `json:"cron"` Sender string `json:"sender"` Params map[string]string `json:"params"` diff --git a/go.mod b/go.mod index 02d7ab38..4df793fc 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/dchest/authcookie v0.0.0-20120917135355-fbdef6e99866 github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9 github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/drone/drone-go v1.3.2-0.20200826185551-24929e4d2cfc + github.com/drone/drone-go v1.4.1-0.20201109202657-b9e58bbbcf27 github.com/drone/drone-runtime v1.1.1-0.20200623162453-61e33e2cab5d github.com/drone/drone-ui v0.0.0-20200701170131-2b91a041998b github.com/drone/drone-yaml v1.2.4-0.20200326192514-6f4d6dfb39e4 diff --git a/go.sum b/go.sum index 6c5475b3..d614ecb4 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,8 @@ github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/drone/drone-go v1.3.2-0.20200826185551-24929e4d2cfc h1:6AXXCMPilpJqwNqUfG6Zgwakr7HCwnialFiQ/AbqYyQ= github.com/drone/drone-go v1.3.2-0.20200826185551-24929e4d2cfc/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg= +github.com/drone/drone-go v1.4.1-0.20201109202657-b9e58bbbcf27 h1:58xKlW/Kwp/Apz+R5qNGzBUIzfq1Z57L7Udz1B6bgWE= +github.com/drone/drone-go v1.4.1-0.20201109202657-b9e58bbbcf27/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg= github.com/drone/drone-runtime v1.0.7-0.20190729202838-87c84080f4a1/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs= github.com/drone/drone-runtime v1.1.1-0.20200623162453-61e33e2cab5d h1:P5HI/Y9hARTZ3F3EKs0kYijhjXZWQRQHYn1neTi0pWM= github.com/drone/drone-runtime v1.1.1-0.20200623162453-61e33e2cab5d/go.mod h1:4/2QToW5+HGD0y1sTw7X35W1f7YINS14UfDY4isggT8= diff --git a/handler/api/repos/builds/retry.go b/handler/api/repos/builds/retry.go index dccdf65f..01470aae 100644 --- a/handler/api/repos/builds/retry.go +++ b/handler/api/repos/builds/retry.go @@ -83,6 +83,7 @@ func HandleRetry( AuthorAvatar: prev.AuthorAvatar, Deployment: prev.Deploy, DeploymentID: prev.DeployID, + Debug: r.FormValue("debug") == "true", Cron: prev.Cron, Sender: prev.Sender, Params: map[string]string{}, @@ -92,6 +93,9 @@ func HandleRetry( if key == "access_token" { continue } + if key == "debug" { + continue + } if len(value) == 0 { continue } diff --git a/store/build/build.go b/store/build/build.go index 4dcca20f..7ad71f79 100644 --- a/store/build/build.go +++ b/store/build/build.go @@ -470,6 +470,7 @@ SELECT ,build_cron ,build_deploy ,build_deploy_id +,build_debug ,build_started ,build_finished ,build_created @@ -607,6 +608,7 @@ INSERT INTO builds ( ,build_cron ,build_deploy ,build_deploy_id +,build_debug ,build_started ,build_finished ,build_created @@ -640,6 +642,7 @@ INSERT INTO builds ( ,:build_cron ,:build_deploy ,:build_deploy_id +,:build_debug ,:build_started ,:build_finished ,:build_created diff --git a/store/build/scan.go b/store/build/scan.go index a5e83042..ad53dbbf 100644 --- a/store/build/scan.go +++ b/store/build/scan.go @@ -56,6 +56,7 @@ func toParams(build *core.Build) map[string]interface{} { "build_cron": build.Cron, "build_deploy": build.Deploy, "build_deploy_id": build.DeployID, + "build_debug": build.Debug, "build_started": build.Started, "build_finished": build.Finished, "build_created": build.Created, @@ -140,6 +141,7 @@ func scanRow(scanner db.Scanner, dest *core.Build) error { &dest.Cron, &dest.Deploy, &dest.DeployID, + &dest.Debug, &dest.Started, &dest.Finished, &dest.Created, diff --git a/store/repos/repos.go b/store/repos/repos.go index 12413299..22539913 100644 --- a/store/repos/repos.go +++ b/store/repos/repos.go @@ -326,6 +326,7 @@ const queryColsBulds = queryCols + ` ,build_cron ,build_deploy ,build_deploy_id +,build_debug ,build_started ,build_finished ,build_created diff --git a/store/repos/scan.go b/store/repos/scan.go index 8a32291c..8fe1ecc5 100644 --- a/store/repos/scan.go +++ b/store/repos/scan.go @@ -173,6 +173,7 @@ func scanRowBuild(scanner db.Scanner, dest *core.Repository) error { &build.Cron, &build.Deploy, &build.DeployID, + &build.Debug, &build.Started, &build.Finished, &build.Created, diff --git a/store/repos/type.go b/store/repos/type.go index 6dcd7f85..f66cb64f 100644 --- a/store/repos/type.go +++ b/store/repos/type.go @@ -53,6 +53,7 @@ type nullBuild struct { Cron sql.NullString Deploy sql.NullString DeployID sql.NullInt64 + Debug sql.NullBool Started sql.NullInt64 Finished sql.NullInt64 Created sql.NullInt64 @@ -93,6 +94,7 @@ func (b *nullBuild) value() *core.Build { Cron: b.Cron.String, Deploy: b.Deploy.String, DeployID: b.DeployID.Int64, + Debug: b.Debug.Bool, Started: b.Started.Int64, Finished: b.Finished.Int64, Created: b.Created.Int64, diff --git a/store/shared/migrate/mysql/ddl_gen.go b/store/shared/migrate/mysql/ddl_gen.go index 3547d473..5425c34f 100644 --- a/store/shared/migrate/mysql/ddl_gen.go +++ b/store/shared/migrate/mysql/ddl_gen.go @@ -64,6 +64,10 @@ var migrations = []struct { name: "create-index-builds-ref", stmt: createIndexBuildsRef, }, + { + name: "alter-table-builds-add-column-debug", + stmt: alterTableBuildsAddColumnDebug, + }, { name: "create-table-stages", stmt: createTableStages, @@ -382,6 +386,10 @@ var createIndexBuildsRef = ` CREATE INDEX ix_build_ref ON builds (build_repo_id, build_ref); ` +var alterTableBuildsAddColumnDebug = ` +ALTER TABLE builds ADD COLUMN build_debug BOOLEAN NOT NULL DEFAULT false; +` + // // 005_create_table_stages.sql // diff --git a/store/shared/migrate/mysql/files/004_create_table_builds.sql b/store/shared/migrate/mysql/files/004_create_table_builds.sql index 47707db5..b914e07c 100644 --- a/store/shared/migrate/mysql/files/004_create_table_builds.sql +++ b/store/shared/migrate/mysql/files/004_create_table_builds.sql @@ -51,4 +51,8 @@ CREATE INDEX ix_build_sender ON builds (build_sender); -- name: create-index-builds-ref -CREATE INDEX ix_build_ref ON builds (build_repo_id, build_ref); \ No newline at end of file +CREATE INDEX ix_build_ref ON builds (build_repo_id, build_ref); + +-- name: alter-table-builds-add-column-debug + +ALTER TABLE builds ADD COLUMN build_debug BOOLEAN NOT NULL DEFAULT false; diff --git a/store/shared/migrate/postgres/ddl_gen.go b/store/shared/migrate/postgres/ddl_gen.go index cd1fd604..452fc233 100644 --- a/store/shared/migrate/postgres/ddl_gen.go +++ b/store/shared/migrate/postgres/ddl_gen.go @@ -68,6 +68,10 @@ var migrations = []struct { name: "create-index-builds-ref", stmt: createIndexBuildsRef, }, + { + name: "alter-table-builds-add-column-debug", + stmt: alterTableBuildsAddColumnDebug, + }, { name: "create-table-stages", stmt: createTableStages, @@ -383,6 +387,10 @@ var createIndexBuildsRef = ` CREATE INDEX IF NOT EXISTS ix_build_ref ON builds (build_repo_id, build_ref); ` +var alterTableBuildsAddColumnDebug = ` +ALTER TABLE builds ADD COLUMN build_debug BOOLEAN NOT NULL DEFAULT false; +` + // // 005_create_table_stages.sql // 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 fa6fe527..1f54881c 100644 --- a/store/shared/migrate/postgres/files/004_create_table_builds.sql +++ b/store/shared/migrate/postgres/files/004_create_table_builds.sql @@ -57,3 +57,7 @@ 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); + +-- name: alter-table-builds-add-column-debug + +ALTER TABLE builds ADD COLUMN build_debug BOOLEAN NOT NULL DEFAULT false; diff --git a/store/shared/migrate/sqlite/ddl_gen.go b/store/shared/migrate/sqlite/ddl_gen.go index 6573f318..c7e86b03 100644 --- a/store/shared/migrate/sqlite/ddl_gen.go +++ b/store/shared/migrate/sqlite/ddl_gen.go @@ -68,6 +68,10 @@ var migrations = []struct { name: "create-index-build-incomplete", stmt: createIndexBuildIncomplete, }, + { + name: "alter-table-builds-add-column-debug", + stmt: alterTableBuildsAddColumnDebug, + }, { name: "create-table-stages", stmt: createTableStages, @@ -382,6 +386,10 @@ CREATE INDEX IF NOT EXISTS ix_build_incomplete ON builds (build_status) WHERE build_status IN ('pending', 'running'); ` +var alterTableBuildsAddColumnDebug = ` +ALTER TABLE builds ADD COLUMN build_debug BOOLEAN NOT NULL DEFAULT 0; +` + // // 005_create_table_stages.sql // 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 9f15fe3d..9577025a 100644 --- a/store/shared/migrate/sqlite/files/004_create_table_builds.sql +++ b/store/shared/migrate/sqlite/files/004_create_table_builds.sql @@ -56,3 +56,7 @@ 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'); + +-- name: alter-table-builds-add-column-debug + +ALTER TABLE builds ADD COLUMN build_debug BOOLEAN NOT NULL DEFAULT 0; diff --git a/trigger/trigger.go b/trigger/trigger.go index 01bdd5dd..078552b2 100644 --- a/trigger/trigger.go +++ b/trigger/trigger.go @@ -186,6 +186,7 @@ func (t *triggerer) Trigger(ctx context.Context, repo *core.Repository, base *co Cron: base.Cron, Deploy: base.Deployment, DeployID: base.DeploymentID, + Debug: base.Debug, Sender: base.Sender, Created: time.Now().Unix(), Updated: time.Now().Unix(), @@ -367,6 +368,7 @@ func (t *triggerer) Trigger(ctx context.Context, repo *core.Repository, base *co Params: base.Params, Deploy: base.Deployment, DeployID: base.DeploymentID, + Debug: base.Debug, Sender: base.Sender, Cron: base.Cron, Created: time.Now().Unix(), @@ -541,6 +543,7 @@ func (t *triggerer) createBuildError(ctx context.Context, repo *core.Repository, AuthorAvatar: base.AuthorAvatar, Deploy: base.Deployment, DeployID: base.DeploymentID, + Debug: base.Debug, Sender: base.Sender, Created: time.Now().Unix(), Updated: time.Now().Unix(),