diff --git a/.drone.yml b/.drone.yml index 9362210..693703d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,18 +1,40 @@ -workspace: - base: /go - path: src/github.com/drone/drone-template-lib +--- +kind: pipeline +name: testing -pipeline: - deps: - image: golang:1.10 - pull: true - commands: - - go get -u github.com/golang/dep/cmd/dep - - dep ensure +platform: + os: linux + arch: amd64 - test: - image: golang:1.10 - pull: true - commands: - - go vet ./... - - go test -cover ./... +steps: +- name: vet + pull: always + image: golang:1.11 + commands: + - go vet ./... + environment: + GO111MODULE: on + volumes: + - name: gopath + path: /go + +- name: test + pull: always + image: golang:1.11 + commands: + - go test -cover ./... + environment: + GO111MODULE: on + volumes: + - name: gopath + path: /go + +volumes: +- name: gopath + temp: {} + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index bf10f16..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,38 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/aymerick/raymond" - packages = [ - ".", - "ast", - "lexer", - "parser" - ] - revision = "2eebd0f5dd9564c0c6e439df11d8a3c7b9b9ab11" - version = "v2.0.2" - -[[projects]] - branch = "master" - name = "github.com/bouk/monkey" - packages = ["."] - revision = "5df1f207ff77e025801505ae4d903133a0b4353f" - -[[projects]] - name = "github.com/pkg/errors" - packages = ["."] - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" - -[[projects]] - branch = "master" - name = "github.com/tkuchiki/faketime" - packages = ["."] - revision = "a4500a4f4643cbc8c5855ed1dbbf161d6cfc77a5" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "1ad80a88b5f0b1ddd8f2a548af68aea9c1c6e25c6fc0870a5fa5a5b03b25d414" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index d65cc24..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,15 +0,0 @@ -[[constraint]] - name = "github.com/aymerick/raymond" - version = "2.0.2" - -[[constraint]] - name = "github.com/pkg/errors" - version = "0.8.0" - -[prune] - go-tests = true - unused-packages = true - -[[constraint]] - branch = "master" - name = "github.com/tkuchiki/faketime" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0043237 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module github.com/drone/drone-template-lib + +require ( + github.com/Masterminds/goutils v1.1.0 // indirect + github.com/Masterminds/semver v1.4.2 // indirect + github.com/Masterminds/sprig v2.18.0+incompatible + github.com/aymerick/raymond v2.0.2+incompatible + github.com/bouk/monkey v1.0.0 + github.com/google/uuid v1.1.0 // indirect + github.com/huandu/xstrings v1.2.0 // indirect + github.com/imdario/mergo v0.3.7 // indirect + github.com/pkg/errors v0.8.0 + github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643 + golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f4a900d --- /dev/null +++ b/go.sum @@ -0,0 +1,22 @@ +github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= +github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= +github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsLuDE6FEcNbWEpw+lI= +github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= +github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= +github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= +github.com/bouk/monkey v1.0.0 h1:k6z8fLlPhETfn5l9rlWVE7Q6B23DoaqosTdArvNQRdc= +github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE= +github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= +github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= +github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= +github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= +github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643 h1:ii/sHfgFMByozryLeiDmn1ClZ/Pena4NgpJ4P7UuX9o= +github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= diff --git a/template/helpers.go b/template/helpers.go index 8825b0e..ce84b48 100644 --- a/template/helpers.go +++ b/template/helpers.go @@ -23,6 +23,7 @@ import ( "unicode" "unicode/utf8" + "github.com/Masterminds/sprig" "github.com/aymerick/raymond" ) @@ -38,13 +39,19 @@ var ( "uppercasefirst": uppercaseFirst, "uppercase": strings.ToUpper, "lowercase": strings.ToLower, - "trim": strings.TrimSpace, - "title": strings.Title, "regexReplace": regexReplace, } ) func init() { + for name, function := range sprig.GenericFuncMap() { + if invalidHelper(name) { + continue + } + + funcs[name] = function + } + raymond.RegisterHelpers(funcs) } @@ -124,3 +131,23 @@ func regexReplace(pattern string, input string, replacement string) string { re := regexp.MustCompile(pattern) return re.ReplaceAllString(input, replacement) } + +func invalidHelper(name string) bool { + invalids := []string{ + "buildCustomCert", + "fail", + "genSelfSignedCert", + "genSignedCert", + "genCA", + "semver", + "semverCompare", + } + + for _, invalid := range invalids { + if name == invalid { + return true + } + } + + return false +}