mirror of
https://github.com/thegeeklab/wp-ansible.git
synced 2024-11-24 22:50:39 +00:00
refactor: add more linters and fix findings (#129)
This commit is contained in:
parent
530b8687e5
commit
673a2af11c
18
.drone.star
18
.drone.star
@ -31,7 +31,7 @@ def test(ctx):
|
|||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"name": "deps",
|
"name": "deps",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make deps",
|
"make deps",
|
||||||
],
|
],
|
||||||
@ -44,7 +44,7 @@ def test(ctx):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "generate",
|
"name": "generate",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make generate",
|
"make generate",
|
||||||
],
|
],
|
||||||
@ -57,7 +57,7 @@ def test(ctx):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "lint",
|
"name": "lint",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make lint",
|
"make lint",
|
||||||
],
|
],
|
||||||
@ -70,7 +70,7 @@ def test(ctx):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make test",
|
"make test",
|
||||||
],
|
],
|
||||||
@ -109,7 +109,7 @@ def build(ctx):
|
|||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"name": "generate",
|
"name": "generate",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"pull": "always",
|
"pull": "always",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make generate",
|
"make generate",
|
||||||
@ -123,7 +123,7 @@ def build(ctx):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "build",
|
"name": "build",
|
||||||
"image": "techknowlogick/xgo:go-1.19.x",
|
"image": "techknowlogick/xgo:go-1.20.x",
|
||||||
"pull": "always",
|
"pull": "always",
|
||||||
"commands": [
|
"commands": [
|
||||||
"ln -s /drone/src /source",
|
"ln -s /drone/src /source",
|
||||||
@ -138,7 +138,7 @@ def build(ctx):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "executable",
|
"name": "executable",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"pull": "always",
|
"pull": "always",
|
||||||
"commands": [
|
"commands": [
|
||||||
"$(find dist/ -executable -type f -iname drone-ansible-linux-amd64) --help",
|
"$(find dist/ -executable -type f -iname drone-ansible-linux-amd64) --help",
|
||||||
@ -205,7 +205,7 @@ def docker(ctx, arch):
|
|||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"name": "generate",
|
"name": "generate",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"pull": "always",
|
"pull": "always",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make generate",
|
"make generate",
|
||||||
@ -219,7 +219,7 @@ def docker(ctx, arch):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "build",
|
"name": "build",
|
||||||
"image": "golang:1.19",
|
"image": "golang:1.20",
|
||||||
"pull": "always",
|
"pull": "always",
|
||||||
"commands": [
|
"commands": [
|
||||||
"make build",
|
"make build",
|
||||||
|
109
.golangci.yml
109
.golangci.yml
@ -1,25 +1,94 @@
|
|||||||
|
---
|
||||||
linters:
|
linters:
|
||||||
enable:
|
|
||||||
- gosimple
|
|
||||||
- deadcode
|
|
||||||
- typecheck
|
|
||||||
- govet
|
|
||||||
- errcheck
|
|
||||||
- staticcheck
|
|
||||||
- unused
|
|
||||||
- structcheck
|
|
||||||
- varcheck
|
|
||||||
# - dupl
|
|
||||||
- gofmt
|
|
||||||
- misspell
|
|
||||||
- gocritic
|
|
||||||
- bidichk
|
|
||||||
- ineffassign
|
|
||||||
- revive
|
|
||||||
- gofumpt
|
|
||||||
- depguard
|
|
||||||
enable-all: false
|
enable-all: false
|
||||||
disable-all: true
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- typecheck
|
||||||
|
- unused
|
||||||
|
- asasalint
|
||||||
|
- asciicheck
|
||||||
|
- bidichk
|
||||||
|
- bodyclose
|
||||||
|
- containedctx
|
||||||
|
- contextcheck
|
||||||
|
- decorder
|
||||||
|
- depguard
|
||||||
|
- dogsled
|
||||||
|
- dupl
|
||||||
|
- dupword
|
||||||
|
- durationcheck
|
||||||
|
- errchkjson
|
||||||
|
- errname
|
||||||
|
- errorlint
|
||||||
|
- execinquery
|
||||||
|
- exhaustive
|
||||||
|
- exportloopref
|
||||||
|
- forcetypeassert
|
||||||
|
- ginkgolinter
|
||||||
|
- gocheckcompilerdirectives
|
||||||
|
- gochecknoglobals
|
||||||
|
- gochecknoinits
|
||||||
|
- gocognit
|
||||||
|
- goconst
|
||||||
|
- gocritic
|
||||||
|
- gocyclo
|
||||||
|
- godot
|
||||||
|
- godox
|
||||||
|
- goerr113
|
||||||
|
- gofmt
|
||||||
|
- gofumpt
|
||||||
|
- goheader
|
||||||
|
- goimports
|
||||||
|
- gomnd
|
||||||
|
- gomoddirectives
|
||||||
|
- gomodguard
|
||||||
|
- goprintffuncname
|
||||||
|
- gosec
|
||||||
|
- grouper
|
||||||
|
- importas
|
||||||
|
- interfacebloat
|
||||||
|
- ireturn
|
||||||
|
- lll
|
||||||
|
- loggercheck
|
||||||
|
- maintidx
|
||||||
|
- makezero
|
||||||
|
- misspell
|
||||||
|
- musttag
|
||||||
|
- nakedret
|
||||||
|
- nestif
|
||||||
|
- nilerr
|
||||||
|
- nilnil
|
||||||
|
- nlreturn
|
||||||
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- nonamedreturns
|
||||||
|
- nosprintfhostport
|
||||||
|
- prealloc
|
||||||
|
- predeclared
|
||||||
|
- promlinter
|
||||||
|
- reassign
|
||||||
|
- revive
|
||||||
|
- stylecheck
|
||||||
|
- tagliatelle
|
||||||
|
- tenv
|
||||||
|
- testableexamples
|
||||||
|
- thelper
|
||||||
|
- tparallel
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- usestdlibvars
|
||||||
|
- whitespace
|
||||||
|
- wsl
|
||||||
|
## not working in golangci yet
|
||||||
|
# - rowserrcheck
|
||||||
|
# - sqlclosecheck
|
||||||
|
# - structcheck
|
||||||
|
# - wastedassign
|
||||||
fast: false
|
fast: false
|
||||||
|
|
||||||
run:
|
run:
|
||||||
@ -28,4 +97,4 @@ run:
|
|||||||
linters-settings:
|
linters-settings:
|
||||||
gofumpt:
|
gofumpt:
|
||||||
extra-rules: true
|
extra-rules: true
|
||||||
lang-version: "1.19"
|
lang-version: "1.20"
|
||||||
|
2
Makefile
2
Makefile
@ -20,7 +20,7 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
|||||||
|
|
||||||
GENERATE ?= $(IMPORT)/pkg/templates
|
GENERATE ?= $(IMPORT)/pkg/templates
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||||
XGO_VERSION := go-1.19.x
|
XGO_VERSION := go-1.20.x
|
||||||
XGO_TARGETS ?= linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64
|
XGO_TARGETS ?= linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64
|
||||||
|
|
||||||
TAGS ?= netgo
|
TAGS ?= netgo
|
||||||
|
@ -120,7 +120,7 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
|||||||
Name: "forks",
|
Name: "forks",
|
||||||
Usage: "specify number of parallel processes to use",
|
Usage: "specify number of parallel processes to use",
|
||||||
EnvVars: []string{"PLUGIN_FORKS"},
|
EnvVars: []string{"PLUGIN_FORKS"},
|
||||||
Value: 5,
|
Value: plugin.AnsibleForksDefault,
|
||||||
Destination: &settings.Forks,
|
Destination: &settings.Forks,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint:gochecknoglobals
|
||||||
var (
|
var (
|
||||||
BuildVersion = "devel"
|
BuildVersion = "devel"
|
||||||
BuildDate = "00000000"
|
BuildDate = "00000000"
|
||||||
@ -52,19 +53,11 @@ func run(settings *plugin.Settings) cli.ActionFunc {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err := plugin.Validate(); err != nil {
|
if err := plugin.Validate(); err != nil {
|
||||||
if e, ok := err.(errors.ExitCoder); ok {
|
return fmt.Errorf("validation failed: %w", err)
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.ExitMessagef("validation failed: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := plugin.Execute(); err != nil {
|
if err := plugin.Execute(); err != nil {
|
||||||
if e, ok := err.(errors.ExitCoder); ok {
|
return fmt.Errorf("execution failed: %w", err)
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.ExitMessagef("execution failed: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
6
go.mod
6
go.mod
@ -1,18 +1,18 @@
|
|||||||
module github.com/owncloud-ci/drone-ansible
|
module github.com/owncloud-ci/drone-ansible
|
||||||
|
|
||||||
go 1.19
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/drone-plugins/drone-plugin-lib v0.4.0
|
github.com/drone-plugins/drone-plugin-lib v0.4.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/urfave/cli/v2 v2.24.3
|
github.com/urfave/cli/v2 v2.24.3
|
||||||
|
golang.org/x/sys v0.5.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
|
|
||||||
)
|
)
|
||||||
|
17
go.sum
17
go.sum
@ -2,6 +2,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
|||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
|
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
|
||||||
@ -20,11 +21,13 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
|
|||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||||
github.com/urfave/cli/v2 v2.24.3 h1:7Q1w8VN8yE0MJEHP06bv89PjYsN4IHWED2s1v/Zlfm0=
|
github.com/urfave/cli/v2 v2.24.3 h1:7Q1w8VN8yE0MJEHP06bv89PjYsN4IHWED2s1v/Zlfm0=
|
||||||
github.com/urfave/cli/v2 v2.24.3/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
github.com/urfave/cli/v2 v2.24.3/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||||
@ -35,11 +38,13 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
|
|||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=
|
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||||
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||||
|
@ -3,21 +3,30 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"golang.org/x/sys/execabs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
const (
|
||||||
|
AnsibleForksDefault = 5
|
||||||
|
|
||||||
ansibleFolder = "/etc/ansible"
|
ansibleFolder = "/etc/ansible"
|
||||||
ansibleConfig = "/etc/ansible/ansible.cfg"
|
ansibleConfig = "/etc/ansible/ansible.cfg"
|
||||||
|
|
||||||
|
pipBin = "/usr/bin/pip"
|
||||||
|
ansibleBin = "/usr/bin/ansible"
|
||||||
|
ansibleGalaxyBin = "/usr/bin/ansible-galaxy"
|
||||||
|
ansiblePlaybookBin = "/usr/bin/ansible-playbook"
|
||||||
|
|
||||||
|
strictFilePerm = 0o600
|
||||||
)
|
)
|
||||||
|
|
||||||
var ansibleContent = `
|
const ansibleContent = `
|
||||||
[defaults]
|
[defaults]
|
||||||
host_key_checking = False
|
host_key_checking = False
|
||||||
`
|
`
|
||||||
@ -27,7 +36,7 @@ func (p *Plugin) ansibleConfig() error {
|
|||||||
return errors.Wrap(err, "failed to create ansible directory")
|
return errors.Wrap(err, "failed to create ansible directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(ansibleConfig, []byte(ansibleContent), 0o600); err != nil {
|
if err := os.WriteFile(ansibleConfig, []byte(ansibleContent), strictFilePerm); err != nil {
|
||||||
return errors.Wrap(err, "failed to create ansible config")
|
return errors.Wrap(err, "failed to create ansible config")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +58,7 @@ func (p *Plugin) privateKey() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.settings.PrivateKeyFile = tmpfile.Name()
|
p.settings.PrivateKeyFile = tmpfile.Name()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +77,7 @@ func (p *Plugin) vaultPass() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.settings.VaultPasswordFile = tmpfile.Name()
|
p.settings.VaultPasswordFile = tmpfile.Name()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +88,7 @@ func (p *Plugin) playbooks() error {
|
|||||||
files, err := filepath.Glob(p)
|
files, err := filepath.Glob(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
playbooks = append(playbooks, p)
|
playbooks = append(playbooks, p)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,21 +100,22 @@ func (p *Plugin) playbooks() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.settings.Playbooks = *cli.NewStringSlice(playbooks...)
|
p.settings.Playbooks = *cli.NewStringSlice(playbooks...)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) versionCommand() *exec.Cmd {
|
func (p *Plugin) versionCommand() *execabs.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"--version",
|
"--version",
|
||||||
}
|
}
|
||||||
|
|
||||||
return exec.Command(
|
return execabs.Command(
|
||||||
"ansible",
|
ansibleBin,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) requirementsCommand() *exec.Cmd {
|
func (p *Plugin) requirementsCommand() *execabs.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"install",
|
"install",
|
||||||
"--upgrade",
|
"--upgrade",
|
||||||
@ -110,13 +123,13 @@ func (p *Plugin) requirementsCommand() *exec.Cmd {
|
|||||||
p.settings.Requirements,
|
p.settings.Requirements,
|
||||||
}
|
}
|
||||||
|
|
||||||
return exec.Command(
|
return execabs.Command(
|
||||||
"pip",
|
pipBin,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) galaxyCommand() *exec.Cmd {
|
func (p *Plugin) galaxyCommand() *execabs.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"install",
|
"install",
|
||||||
"--force",
|
"--force",
|
||||||
@ -128,13 +141,13 @@ func (p *Plugin) galaxyCommand() *exec.Cmd {
|
|||||||
args = append(args, fmt.Sprintf("-%s", strings.Repeat("v", p.settings.Verbose)))
|
args = append(args, fmt.Sprintf("-%s", strings.Repeat("v", p.settings.Verbose)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return exec.Command(
|
return execabs.Command(
|
||||||
"ansible-galaxy",
|
ansibleGalaxyBin,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) ansibleCommand(inventory string) *exec.Cmd {
|
func (p *Plugin) ansibleCommand(inventory string) *execabs.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"--inventory",
|
"--inventory",
|
||||||
inventory,
|
inventory,
|
||||||
@ -160,8 +173,8 @@ func (p *Plugin) ansibleCommand(inventory string) *exec.Cmd {
|
|||||||
args = append(args, "--list-hosts")
|
args = append(args, "--list-hosts")
|
||||||
args = append(args, p.settings.Playbooks.Value()...)
|
args = append(args, p.settings.Playbooks.Value()...)
|
||||||
|
|
||||||
return exec.Command(
|
return execabs.Command(
|
||||||
"ansible-playbook",
|
ansiblePlaybookBin,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -170,8 +183,8 @@ func (p *Plugin) ansibleCommand(inventory string) *exec.Cmd {
|
|||||||
args = append(args, "--syntax-check")
|
args = append(args, "--syntax-check")
|
||||||
args = append(args, p.settings.Playbooks.Value()...)
|
args = append(args, p.settings.Playbooks.Value()...)
|
||||||
|
|
||||||
return exec.Command(
|
return execabs.Command(
|
||||||
"ansible-playbook",
|
ansiblePlaybookBin,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -192,7 +205,7 @@ func (p *Plugin) ansibleCommand(inventory string) *exec.Cmd {
|
|||||||
args = append(args, "--force-handlers")
|
args = append(args, "--force-handlers")
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.settings.Forks != 5 {
|
if p.settings.Forks != AnsibleForksDefault {
|
||||||
args = append(args, "--forks", strconv.Itoa(p.settings.Forks))
|
args = append(args, "--forks", strconv.Itoa(p.settings.Forks))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,12 +283,12 @@ func (p *Plugin) ansibleCommand(inventory string) *exec.Cmd {
|
|||||||
|
|
||||||
args = append(args, p.settings.Playbooks.Value()...)
|
args = append(args, p.settings.Playbooks.Value()...)
|
||||||
|
|
||||||
return exec.Command(
|
return execabs.Command(
|
||||||
"ansible-playbook",
|
ansiblePlaybookBin,
|
||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func trace(cmd *exec.Cmd) {
|
func trace(cmd *execabs.Cmd) {
|
||||||
fmt.Println("$", strings.Join(cmd.Args, " "))
|
fmt.Println("$", strings.Join(cmd.Args, " "))
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"golang.org/x/sys/execabs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings for the Plugin.
|
// Settings for the Plugin.
|
||||||
@ -86,7 +86,7 @@ func (p *Plugin) Execute() error {
|
|||||||
defer os.Remove(p.settings.VaultPasswordFile)
|
defer os.Remove(p.settings.VaultPasswordFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
commands := []*exec.Cmd{
|
commands := []*execabs.Cmd{
|
||||||
p.versionCommand(),
|
p.versionCommand(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ type Plugin struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
||||||
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
|
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) *Plugin {
|
||||||
return &Plugin{
|
return &Plugin{
|
||||||
settings: settings,
|
settings: settings,
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
|
Loading…
Reference in New Issue
Block a user