From 77b5c6246d8650d82c2b51000dd05db2b53ff8b3 Mon Sep 17 00:00:00 2001 From: glaszig Date: Fri, 11 Dec 2015 01:44:14 +0100 Subject: [PATCH 1/4] skip build with any combination of "skip" and "ci" a commit message containing any case-insensitive variant of the above two words wrapped in square brackets will skip the build. examples: [ci skip], [skip CI] this reintroduces pr #1134 and additionally logs the matched skip instruction. --- controller/hook.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/controller/hook.go b/controller/hook.go index f761bf0f6..569e29805 100644 --- a/controller/hook.go +++ b/controller/hook.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "regexp" log "github.com/Sirupsen/logrus" "github.com/drone/drone/engine" @@ -38,10 +39,12 @@ func PostHook(c *gin.Context) { return } - // a build may be skipped if the text [CI SKIP] - // is found inside the commit message - if strings.Contains(build.Message, "[CI SKIP]") { - log.Infof("ignoring hook. [ci skip] found for %s") + // skip the build if any case-insensitive combination of the words "skip" and "ci" + // wrapped in square brackets appear in the commit message + skipRe := regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`) + skipMatches := skipRe.FindStringSubmatch(build.Message) + if len(skipMatches) > 0 { + log.Infof("ignoring hook. %s found in %s", skipMatches[0], build.Commit) c.Writer.WriteHeader(204) return } From 845d437256f84aec0dd1bb3647ec3786b88641fe Mon Sep 17 00:00:00 2001 From: glaszig Date: Fri, 11 Dec 2015 02:06:56 +0100 Subject: [PATCH 2/4] move build skipping regular expression variable into global scope --- controller/hook.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controller/hook.go b/controller/hook.go index 569e29805..329fcac01 100644 --- a/controller/hook.go +++ b/controller/hook.go @@ -20,6 +20,8 @@ import ( "github.com/drone/drone/yaml/matrix" ) +var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`) + func PostHook(c *gin.Context) { remote_ := remote.FromContext(c) @@ -41,7 +43,6 @@ func PostHook(c *gin.Context) { // skip the build if any case-insensitive combination of the words "skip" and "ci" // wrapped in square brackets appear in the commit message - skipRe := regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`) skipMatches := skipRe.FindStringSubmatch(build.Message) if len(skipMatches) > 0 { log.Infof("ignoring hook. %s found in %s", skipMatches[0], build.Commit) From cb0139497734113b9b382bc20fc645e8610cbdce Mon Sep 17 00:00:00 2001 From: glaszig Date: Fri, 11 Dec 2015 02:12:27 +0100 Subject: [PATCH 3/4] simplified regexp matching of skip ci instruction in commit message --- controller/hook.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controller/hook.go b/controller/hook.go index 329fcac01..f435c3266 100644 --- a/controller/hook.go +++ b/controller/hook.go @@ -43,9 +43,9 @@ func PostHook(c *gin.Context) { // skip the build if any case-insensitive combination of the words "skip" and "ci" // wrapped in square brackets appear in the commit message - skipMatches := skipRe.FindStringSubmatch(build.Message) - if len(skipMatches) > 0 { - log.Infof("ignoring hook. %s found in %s", skipMatches[0], build.Commit) + skipMatch := skipRe.FindString(build.Message) + if len(skipMatch) > 0 { + log.Infof("ignoring hook. %s found in %s", skipMatch, build.Commit) c.Writer.WriteHeader(204) return } From 08fc17986a2771789e8c8653ce9c3aea3a3f7558 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sun, 13 Dec 2015 02:42:21 +0100 Subject: [PATCH 4/4] amending docs with build skipping tags --- docs/build/build.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/build/build.md b/docs/build/build.md index bfcc21ec9..e702d84c4 100644 --- a/docs/build/build.md +++ b/docs/build/build.md @@ -48,4 +48,5 @@ image: index.docker.io/library/golang:1.4 ## Skipping builds -Skip a build by including the text `[CI SKIP]` in your commit message. +Skip a build by including any combination of `ci` and `skip` wrapped in square brackets +in your commit message. Examples: `[skip CI]` `[ci skip]`