mirror of
https://github.com/drone-plugins/drone-npm.git
synced 2026-06-04 18:23:52 +08:00
Update build to run golangci (#63)
Use golang:1.18 for the build/test images. Fix all linter errors. Update go.mod to 1.16 to support os.ReadFile, os.WriteFile. Update libraries.
This commit is contained in:
+8
-35
@@ -29,40 +29,14 @@ def testing(ctx):
|
||||
'arch': 'amd64',
|
||||
},
|
||||
'steps': [
|
||||
{
|
||||
'name': 'staticcheck',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go run honnef.co/go/tools/cmd/staticcheck ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'lint',
|
||||
'image': 'golang:1.15',
|
||||
'image': 'golang:1.18',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go run golang.org/x/lint/golint -set_exit_status ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'vet',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go vet ./...',
|
||||
"go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest",
|
||||
"golangci-lint version",
|
||||
"golangci-lint run",
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
@@ -73,7 +47,7 @@ def testing(ctx):
|
||||
},
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'golang:1.15',
|
||||
'image': 'golang:1.18',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go test -cover ./...',
|
||||
@@ -144,7 +118,7 @@ def linux(ctx, arch):
|
||||
'steps': [
|
||||
{
|
||||
'name': 'environment',
|
||||
'image': 'golang:1.15',
|
||||
'image': 'golang:1.18',
|
||||
'pull': 'always',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
@@ -156,7 +130,7 @@ def linux(ctx, arch):
|
||||
},
|
||||
{
|
||||
'name': 'build',
|
||||
'image': 'golang:1.15',
|
||||
'image': 'golang:1.18',
|
||||
'pull': 'always',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
@@ -165,7 +139,7 @@ def linux(ctx, arch):
|
||||
},
|
||||
{
|
||||
'name': 'executable',
|
||||
'image': 'golang:1.15',
|
||||
'image': 'golang:1.18',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'./release/linux/%s/drone-npm --help' % (arch),
|
||||
@@ -219,4 +193,3 @@ def manifest(ctx):
|
||||
],
|
||||
},
|
||||
}]
|
||||
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
linters-settings:
|
||||
dupl:
|
||||
threshold: 100
|
||||
funlen:
|
||||
lines: 400
|
||||
statements: 100
|
||||
gci:
|
||||
local-prefixes: github.com/golangci/golangci-lint
|
||||
goconst:
|
||||
min-len: 3
|
||||
min-occurrences: 3
|
||||
gocritic:
|
||||
enabled-tags:
|
||||
- diagnostic
|
||||
- experimental
|
||||
- opinionated
|
||||
- performance
|
||||
- style
|
||||
disabled-checks:
|
||||
- dupImport # https://github.com/go-critic/go-critic/issues/845
|
||||
- ifElseChain
|
||||
- octalLiteral
|
||||
- whyNoLint
|
||||
- wrapperFunc
|
||||
gocyclo:
|
||||
min-complexity: 25
|
||||
goimports:
|
||||
local-prefixes: github.com/golangci/golangci-lint
|
||||
gomnd:
|
||||
settings:
|
||||
mnd:
|
||||
# don't include the "operation" and "assign"
|
||||
checks: argument,case,condition,return
|
||||
govet:
|
||||
check-shadowing: true
|
||||
settings:
|
||||
printf:
|
||||
funcs:
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
||||
lll:
|
||||
line-length: 200
|
||||
maligned:
|
||||
suggest-new: true
|
||||
misspell:
|
||||
locale: US
|
||||
nolintlint:
|
||||
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
|
||||
allow-unused: false # report any unused nolint directives
|
||||
require-explanation: false # don't require an explanation for nolint directives
|
||||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
||||
nakedret:
|
||||
max-func-lines: 100
|
||||
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
- errcheck
|
||||
- exportloopref
|
||||
- exhaustive
|
||||
- funlen
|
||||
- gochecknoinits
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
- gomnd
|
||||
- goprintffuncname
|
||||
#- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- lll
|
||||
- misspell
|
||||
- nakedret
|
||||
- noctx
|
||||
- nolintlint
|
||||
- revive
|
||||
- rowserrcheck
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
- whitespace
|
||||
|
||||
# don't enable:
|
||||
# - asciicheck
|
||||
# - dupl
|
||||
# - scopelint
|
||||
# - gochecknoglobals
|
||||
# - gocognit
|
||||
# - godot
|
||||
# - godox
|
||||
# - goerr113
|
||||
# - interfacer
|
||||
# - maligned
|
||||
# - nestif
|
||||
# - prealloc
|
||||
# - testpackage
|
||||
# - revive
|
||||
# - wsl
|
||||
|
||||
issues:
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- gomnd
|
||||
|
||||
# https://github.com/go-critic/go-critic/issues/926
|
||||
- linters:
|
||||
- gocritic
|
||||
text: "unnecessaryDefer:"
|
||||
|
||||
run:
|
||||
skip-files:
|
||||
- _gen\.go
|
||||
@@ -23,7 +23,7 @@ func main() {
|
||||
settings := &plugin.Settings{}
|
||||
|
||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||
godotenv.Overload("/run/drone/env")
|
||||
godotenv.Overload("/run/drone/env") //nolint:errcheck
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
@@ -43,13 +43,13 @@ func run(settings *plugin.Settings) cli.ActionFunc {
|
||||
return func(ctx *cli.Context) error {
|
||||
urfave.LoggingFromContext(ctx)
|
||||
|
||||
plugin := plugin.New(
|
||||
p := plugin.New(
|
||||
*settings,
|
||||
urfave.PipelineFromContext(ctx),
|
||||
urfave.NetworkFromContext(ctx),
|
||||
)
|
||||
|
||||
if err := plugin.Validate(); err != nil {
|
||||
if err := p.Validate(); err != nil {
|
||||
if e, ok := err.(errors.ExitCoder); ok {
|
||||
return e
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func run(settings *plugin.Settings) cli.ActionFunc {
|
||||
return errors.ExitMessagef("validation failed: %w", err)
|
||||
}
|
||||
|
||||
if err := plugin.Execute(); err != nil {
|
||||
if err := p.Execute(); err != nil {
|
||||
if e, ok := err.(errors.ExitCoder); ok {
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module github.com/drone-plugins/drone-npm
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/drone-plugins/drone-plugin-lib v0.3.1
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
github.com/urfave/cli/v2 v2.2.0
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0
|
||||
github.com/joho/godotenv v1.4.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/urfave/cli/v2 v2.8.1
|
||||
)
|
||||
|
||||
@@ -1,27 +1,46 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
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.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
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/drone-plugins/drone-plugin-lib v0.3.1 h1:Br43wRnot2CpDGKPIKOnIxkTsuII5q4xxKROirs5hxc=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.3.1/go.mod h1:ZUKtwSoUmeCj7DXMS3WktDdMAWudW7O6dYAZZRISv4M=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
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/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
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.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
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/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
|
||||
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4=
|
||||
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
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-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
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/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||
|
||||
+22
-23
@@ -9,7 +9,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -55,14 +54,14 @@ const globalRegistry = "https://registry.npmjs.org/"
|
||||
// Validate handles the settings validation of the plugin.
|
||||
func (p *Plugin) Validate() error {
|
||||
// Check authentication options
|
||||
if len(p.settings.Token) == 0 {
|
||||
if len(p.settings.Username) == 0 {
|
||||
if p.settings.Token == "" {
|
||||
if p.settings.Username == "" {
|
||||
return fmt.Errorf("no username provided")
|
||||
}
|
||||
if len(p.settings.Email) == 0 {
|
||||
if p.settings.Email == "" {
|
||||
return fmt.Errorf("no email address provided")
|
||||
}
|
||||
if len(p.settings.Password) == 0 {
|
||||
if p.settings.Password == "" {
|
||||
return fmt.Errorf("no password provided")
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ func (p *Plugin) Validate() error {
|
||||
}
|
||||
|
||||
// Verify the same registry is being used
|
||||
if len(p.settings.Registry) == 0 {
|
||||
if p.settings.Registry == "" {
|
||||
p.settings.Registry = globalRegistry
|
||||
}
|
||||
|
||||
@@ -115,7 +114,7 @@ func (p *Plugin) Execute() error {
|
||||
|
||||
if publish {
|
||||
logrus.Info("Publishing package")
|
||||
if err = runCommand(publishCommand(p.settings), p.settings.Folder); err != nil {
|
||||
if err = runCommand(publishCommand(&p.settings), p.settings.Folder); err != nil {
|
||||
return fmt.Errorf("could not publish package: %w", err)
|
||||
}
|
||||
} else {
|
||||
@@ -127,8 +126,8 @@ func (p *Plugin) Execute() error {
|
||||
|
||||
/// writeNpmrc creates a .npmrc in the folder for authentication
|
||||
func (p *Plugin) writeNpmrc() error {
|
||||
var f func(settings Settings) string
|
||||
if len(p.settings.Token) == 0 {
|
||||
var f func(settings *Settings) string
|
||||
if p.settings.Token == "" {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"username": p.settings.Username,
|
||||
"email": p.settings.Email,
|
||||
@@ -141,15 +140,15 @@ func (p *Plugin) writeNpmrc() error {
|
||||
|
||||
// write npmrc file
|
||||
home := "/root"
|
||||
user, err := user.Current()
|
||||
currentUser, err := user.Current()
|
||||
if err == nil {
|
||||
home = user.HomeDir
|
||||
home = currentUser.HomeDir
|
||||
}
|
||||
npmrcPath := path.Join(home, ".npmrc")
|
||||
|
||||
logrus.WithField("path", npmrcPath).Info("Writing npmrc")
|
||||
|
||||
return ioutil.WriteFile(npmrcPath, []byte(f(p.settings)), 0644)
|
||||
return os.WriteFile(npmrcPath, []byte(f(&p.settings)), 0644) //nolint:gomnd
|
||||
}
|
||||
|
||||
/// shouldPublishPackage determines if the package should be published
|
||||
@@ -183,7 +182,7 @@ func (p *Plugin) shouldPublishPackage() (bool, error) {
|
||||
for _, value := range versions {
|
||||
logrus.WithField("version", value).Debug("Found version of package")
|
||||
|
||||
if strings.Compare(p.settings.npm.Version, value) == 0 {
|
||||
if p.settings.npm.Version == value {
|
||||
logrus.Info("Version found in the registry")
|
||||
if p.settings.FailOnVersionConflict {
|
||||
return false, fmt.Errorf("cannot publish package due to version conflict")
|
||||
@@ -249,7 +248,7 @@ func readPackageFile(folder string) (*npmPackage, error) {
|
||||
}
|
||||
|
||||
// Read the file
|
||||
file, err := ioutil.ReadFile(packagePath)
|
||||
file, err := os.ReadFile(packagePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read package.json at %s: %w", packagePath, err)
|
||||
}
|
||||
@@ -262,15 +261,15 @@ func readPackageFile(folder string) (*npmPackage, error) {
|
||||
}
|
||||
|
||||
// Make sure values are present
|
||||
if len(npm.Name) == 0 {
|
||||
if npm.Name == "" {
|
||||
return nil, fmt.Errorf("no package name present")
|
||||
}
|
||||
if len(npm.Version) == 0 {
|
||||
if npm.Version == "" {
|
||||
return nil, fmt.Errorf("no package version present")
|
||||
}
|
||||
|
||||
// Set the default registry
|
||||
if len(npm.Config.Registry) == 0 {
|
||||
if npm.Config.Registry == "" {
|
||||
npm.Config.Registry = globalRegistry
|
||||
}
|
||||
|
||||
@@ -285,7 +284,7 @@ func readPackageFile(folder string) (*npmPackage, error) {
|
||||
|
||||
// npmrcContentsUsernamePassword creates the contents from a username and
|
||||
// password
|
||||
func npmrcContentsUsernamePassword(config Settings) string {
|
||||
func npmrcContentsUsernamePassword(config *Settings) string {
|
||||
// get the base64 encoded string
|
||||
authString := fmt.Sprintf("%s:%s", config.Username, config.Password)
|
||||
encoded := base64.StdEncoding.EncodeToString([]byte(authString))
|
||||
@@ -295,7 +294,7 @@ func npmrcContentsUsernamePassword(config Settings) string {
|
||||
}
|
||||
|
||||
/// Writes npmrc contents when using a token
|
||||
func npmrcContentsToken(config Settings) string {
|
||||
func npmrcContentsToken(config *Settings) string {
|
||||
registry, _ := url.Parse(config.Registry)
|
||||
registry.Scheme = "" // Reset the scheme to empty. This makes it so we will get a protocol relative URL.
|
||||
host, port, _ := net.SplitHostPort(registry.Host)
|
||||
@@ -305,7 +304,7 @@ func npmrcContentsToken(config Settings) string {
|
||||
registryString := registry.String()
|
||||
|
||||
if !strings.HasSuffix(registryString, "/") {
|
||||
registryString = registryString + "/"
|
||||
registryString += "/"
|
||||
}
|
||||
return fmt.Sprintf("%s:_authToken=%s", registryString, config.Token)
|
||||
}
|
||||
@@ -341,14 +340,14 @@ func packageVersionsCommand(name string) *exec.Cmd {
|
||||
}
|
||||
|
||||
// publishCommand runs the publish command
|
||||
func publishCommand(settings Settings) *exec.Cmd {
|
||||
func publishCommand(settings *Settings) *exec.Cmd {
|
||||
commandArgs := []string{"publish"}
|
||||
|
||||
if len(settings.Tag) != 0 {
|
||||
if settings.Tag != "" {
|
||||
commandArgs = append(commandArgs, "--tag", settings.Tag)
|
||||
}
|
||||
|
||||
if len(settings.Access) != 0 {
|
||||
if settings.Access != "" {
|
||||
commandArgs = append(commandArgs, "--access", settings.Access)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ type Plugin struct {
|
||||
}
|
||||
|
||||
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
||||
//nolint:gocritic
|
||||
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
|
||||
return &Plugin{
|
||||
settings: settings,
|
||||
|
||||
@@ -14,35 +14,35 @@ func TestTokenRCContents(t *testing.T) {
|
||||
Registry: "https://npm.someorg.com/",
|
||||
Token: "token",
|
||||
}
|
||||
actual := npmrcContentsToken(settings)
|
||||
actual := npmrcContentsToken(&settings)
|
||||
expected := "//npm.someorg.com/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = "https://npm.someorg.com/with/path/"
|
||||
actual = npmrcContentsToken(settings)
|
||||
actual = npmrcContentsToken(&settings)
|
||||
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = globalRegistry
|
||||
actual = npmrcContentsToken(settings)
|
||||
actual = npmrcContentsToken(&settings)
|
||||
expected = "//registry.npmjs.org/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = "https://npm.someorg.com"
|
||||
actual = npmrcContentsToken(settings)
|
||||
actual = npmrcContentsToken(&settings)
|
||||
expected = "//npm.someorg.com/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = "https://npm.someorg.com/with/path"
|
||||
actual = npmrcContentsToken(settings)
|
||||
actual = npmrcContentsToken(&settings)
|
||||
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
|
||||
Reference in New Issue
Block a user