mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-03-05 14:57:01 -05:00
ci: enhance linting and string manipulations in plugin code
- Update golangci-lint action to v7 and specify version v2.0 in the GitHub testing workflow - Add `.golangci.yaml` configuration file with various linters and settings - Refactor string concatenation method for destination file name in `plugin.go` - Use `strings.ReplaceAll` for replacing spaces in target paths in `plugin.go` - Change error handling to use `errors.As` for type assertion in `plugin.go` Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
parent
7a4b5f1fad
commit
e2a386e6ec
4
.github/workflows/testing.yml
vendored
4
.github/workflows/testing.yml
vendored
@ -18,9 +18,9 @@ jobs:
|
|||||||
check-latest: true
|
check-latest: true
|
||||||
|
|
||||||
- name: Setup golangci-lint
|
- name: Setup golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v7
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: v2.0
|
||||||
args: --verbose
|
args: --verbose
|
||||||
|
|
||||||
- uses: hadolint/hadolint-action@v3.1.0
|
- uses: hadolint/hadolint-action@v3.1.0
|
||||||
|
|||||||
54
.golangci.yaml
Normal file
54
.golangci.yaml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
version: "2"
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- asciicheck
|
||||||
|
- durationcheck
|
||||||
|
- errorlint
|
||||||
|
- gosec
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- nilerr
|
||||||
|
- nolintlint
|
||||||
|
- perfsprint
|
||||||
|
- revive
|
||||||
|
- usestdlibvars
|
||||||
|
- wastedassign
|
||||||
|
settings:
|
||||||
|
gosec:
|
||||||
|
includes:
|
||||||
|
- G102
|
||||||
|
- G106
|
||||||
|
- G108
|
||||||
|
- G109
|
||||||
|
- G111
|
||||||
|
- G112
|
||||||
|
- G201
|
||||||
|
- G203
|
||||||
|
perfsprint:
|
||||||
|
int-conversion: true
|
||||||
|
err-error: true
|
||||||
|
errorf: true
|
||||||
|
sprintf1: true
|
||||||
|
strconcat: true
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
presets:
|
||||||
|
- comments
|
||||||
|
- common-false-positives
|
||||||
|
- legacy
|
||||||
|
- std-error-handling
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
formatters:
|
||||||
|
enable:
|
||||||
|
- gci
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
@ -234,7 +234,7 @@ func (p *Plugin) Exec() error {
|
|||||||
return errMissingHost
|
return errMissingHost
|
||||||
}
|
}
|
||||||
|
|
||||||
p.DestFile = fmt.Sprintf("%s.tar.gz", random.String(10))
|
p.DestFile = random.String(10) + ".tar.gz"
|
||||||
|
|
||||||
// create a temporary file for the archive
|
// create a temporary file for the archive
|
||||||
dir := os.TempDir()
|
dir := os.TempDir()
|
||||||
@ -310,7 +310,7 @@ func (p *Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, target := range p.Config.Target {
|
for _, target := range p.Config.Target {
|
||||||
target = strings.Replace(target, " ", "\\ ", -1)
|
target = strings.ReplaceAll(target, " ", "\\ ")
|
||||||
// remove target folder before upload data
|
// remove target folder before upload data
|
||||||
if p.Config.Remove {
|
if p.Config.Remove {
|
||||||
p.log(host, "Remove target folder:", target)
|
p.log(host, "Remove target folder:", target)
|
||||||
@ -376,7 +376,8 @@ func (p *Plugin) Exec() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c := color.New(color.FgRed)
|
c := color.New(color.FgRed)
|
||||||
c.Println("drone-scp error: ", err)
|
c.Println("drone-scp error: ", err)
|
||||||
if _, ok := err.(copyError); !ok {
|
var cerr copyError
|
||||||
|
if !errors.As(err, &cerr) {
|
||||||
fmt.Println("drone-scp rollback: remove all target tmp file")
|
fmt.Println("drone-scp rollback: remove all target tmp file")
|
||||||
if err := p.removeAllDestFile(); err != nil {
|
if err := p.removeAllDestFile(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user