From d0628bbe7be8c25af7f06b65b357122dee071620 Mon Sep 17 00:00:00 2001 From: Ke Zhu Date: Sun, 4 May 2014 13:29:51 -0400 Subject: [PATCH 1/3] support publishing to npm --- Makefile | 1 + pkg/plugin/publish/npm.go | 72 ++++++++++++++++++++++++++ pkg/plugin/publish/npm_test.go | 95 ++++++++++++++++++++++++++++++++++ pkg/plugin/publish/publish.go | 6 +++ 4 files changed, 174 insertions(+) create mode 100644 pkg/plugin/publish/npm_test.go diff --git a/Makefile b/Makefile index a1e3476c..93ed269b 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ database/testing \ mail \ model \ plugin/deploy \ +plugin/publish \ queue PKGS := $(addprefix github.com/drone/drone/pkg/,$(PKGS)) .PHONY := test $(PKGS) diff --git a/pkg/plugin/publish/npm.go b/pkg/plugin/publish/npm.go index 30b1a5b2..865e70d8 100644 --- a/pkg/plugin/publish/npm.go +++ b/pkg/plugin/publish/npm.go @@ -1 +1,73 @@ package publish + +import ( + "fmt" + + "github.com/drone/drone/pkg/build/buildfile" +) + +var npmLoginCmd = ` +npm login < 0 && r.Branch == p.PyPI.Branch)) { p.PyPI.Write(f) } + + // NPM + if p.NPM != nil && (len(p.NPM.Branch) == 0 || (len(p.NPM.Branch) > 0 && r.Branch == p.NPM.Branch)) { + p.NPM.Write(f) + } } From d77b3209b024436cc26ce2d04dc579596e7da69a Mon Sep 17 00:00:00 2001 From: Ke Zhu Date: Sun, 4 May 2014 21:48:03 -0400 Subject: [PATCH 2/3] update npm login method --- pkg/plugin/publish/npm.go | 8 ++++---- pkg/plugin/publish/npm_test.go | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/plugin/publish/npm.go b/pkg/plugin/publish/npm.go index 865e70d8..42b26165 100644 --- a/pkg/plugin/publish/npm.go +++ b/pkg/plugin/publish/npm.go @@ -6,11 +6,11 @@ import ( "github.com/drone/drone/pkg/build/buildfile" ) +// use npm trick instead of running npm adduser that requires stdin var npmLoginCmd = ` -npm login < ~/.npmrc +_auth = $(echo "%s:%s" | tr -d "\r\n" | base64) +email = %s EOF ` diff --git a/pkg/plugin/publish/npm_test.go b/pkg/plugin/publish/npm_test.go index d94d7bac..96c52581 100644 --- a/pkg/plugin/publish/npm_test.go +++ b/pkg/plugin/publish/npm_test.go @@ -59,10 +59,6 @@ func TestNPMPublish(t *testing.T) { t.Fatalf("Can't unmarshal publish script: %s", err) } - if !strings.Contains(bscr, "npm login") { - t.Error("Expect script to contain login command") - } - if !strings.Contains(bscr, "npm publish") { t.Error("Expect script to contain install command") } From 0ee9b163b9747a7d911d795f4653476425e293a1 Mon Sep 17 00:00:00 2001 From: Ke Zhu Date: Sun, 4 May 2014 22:05:24 -0400 Subject: [PATCH 3/3] correct npm publish logic --- pkg/plugin/publish/npm.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/plugin/publish/npm.go b/pkg/plugin/publish/npm.go index 42b26165..d31879ed 100644 --- a/pkg/plugin/publish/npm.go +++ b/pkg/plugin/publish/npm.go @@ -51,11 +51,6 @@ func (n *NPM) Write(f *buildfile.Buildfile) { npmPublishCmd := "npm publish %s" - // Setup custom npm registry - if n.Registry != "" { - f.WriteCmdSilent(fmt.Sprintf("npm config set registry %s", n.Registry)) - } - if n.Tag != "" { npmPublishCmd += fmt.Sprintf(" --tag %s", n.Tag) } @@ -69,5 +64,10 @@ func (n *NPM) Write(f *buildfile.Buildfile) { // Login to registry f.WriteCmdSilent(fmt.Sprintf(npmLoginCmd, n.Username, n.Password, n.Email)) + // Setup custom npm registry + if n.Registry != "" { + f.WriteCmdSilent(fmt.Sprintf("npm config set registry %s", n.Registry)) + } + f.WriteCmd(fmt.Sprintf(npmPublishCmd, n.Folder)) } \ No newline at end of file