From 44aaf4fd9ca7ca09ab15009b45f4b64870876b12 Mon Sep 17 00:00:00 2001 From: swgillespie Date: Thu, 27 Mar 2014 22:43:58 -0700 Subject: [PATCH 1/5] Initial commit, haven't tested yet --- pkg/plugin/publish/publish.go | 4 ++++ pkg/plugin/publish/pypi.go | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/pkg/plugin/publish/publish.go b/pkg/plugin/publish/publish.go index 33a4dc43c..bef429e36 100644 --- a/pkg/plugin/publish/publish.go +++ b/pkg/plugin/publish/publish.go @@ -10,6 +10,7 @@ import ( type Publish struct { S3 *S3 `yaml:"s3,omitempty"` Swift *Swift `yaml:"swift,omitempty"` + PyPI *PyPI `yaml:"pypi, omitempty"` } func (p *Publish) Write(f *buildfile.Buildfile) { @@ -19,4 +20,7 @@ func (p *Publish) Write(f *buildfile.Buildfile) { if p.Swift != nil { p.Swift.Write(f) } + if p.PyPI != nil { + p.PyPI.Write(f) + } } diff --git a/pkg/plugin/publish/pypi.go b/pkg/plugin/publish/pypi.go index 30b1a5b2a..710af6d28 100644 --- a/pkg/plugin/publish/pypi.go +++ b/pkg/plugin/publish/pypi.go @@ -1 +1,38 @@ package publish + +import ( + "fmt" + "github.com/drone/drone/pkg/build/buildfile" +) + +// set up the .pypirc file +var pypirc = ` +cat < $HOME/.pypirc +[pypirc] +servers = pypi +[server-login] +username:%s +password:%s +EOF` + +type PyPI struct { + Username string `yaml:"username,omitempty"` + Password string `yaml:"password,omitempty"` +} + +func (p *PyPI) Write(f *buildfile.Buildfile) { + if len(p.Username) == 0 || len(p.Password) == 0 { + // nothing to do if the config is bad + return + } + f.WriteCmdSilent("echo 'publishing to PyPI...'") + + // find the setup.py file + f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')") + + f.WriteCmdSilent(fmt.Sprintf(pypirc, p.Username, p.Password)) + + // if we found the setup.py file use it to deploy + f.WriteCmd("[ -z $_PYPI_SETUP_PY ] || python $_PYPI_SETUP_PY sdist --formats gztar,zip upload") + f.WriteCmd("[ -z $_PYPI_SETUP_PY ] && echo 'Failed to find setup.py file'") +} From ec409e51a1e11a63f4172a3c49ccf9b239cce9a3 Mon Sep 17 00:00:00 2001 From: swgillespie Date: Sat, 29 Mar 2014 15:15:52 -0700 Subject: [PATCH 2/5] Add ability to choose different formats --- pkg/plugin/publish/publish.go | 2 +- pkg/plugin/publish/pypi.go | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pkg/plugin/publish/publish.go b/pkg/plugin/publish/publish.go index bef429e36..83f891f73 100644 --- a/pkg/plugin/publish/publish.go +++ b/pkg/plugin/publish/publish.go @@ -10,7 +10,7 @@ import ( type Publish struct { S3 *S3 `yaml:"s3,omitempty"` Swift *Swift `yaml:"swift,omitempty"` - PyPI *PyPI `yaml:"pypi, omitempty"` + PyPI *PyPI `yaml:"pypi,omitempty"` } func (p *Publish) Write(f *buildfile.Buildfile) { diff --git a/pkg/plugin/publish/pypi.go b/pkg/plugin/publish/pypi.go index 710af6d28..7d08c2304 100644 --- a/pkg/plugin/publish/pypi.go +++ b/pkg/plugin/publish/pypi.go @@ -15,14 +15,28 @@ username:%s password:%s EOF` +var deployCmd = ` +if [ -z $_PYPI_SETUP_PY ] +then + python $_PYPI_SETUP_PY sdist %s upload + if [ $? -ne 0 ] + then + echo "Deploy to PyPI failed - perhaps due to the version number not being incremented. Continuing..." + fi +else + echo "Failed to find setup.py file" +fi +` + type PyPI struct { Username string `yaml:"username,omitempty"` Password string `yaml:"password,omitempty"` + Formats []string `yaml:"formats,omitempty"` } func (p *PyPI) Write(f *buildfile.Buildfile) { if len(p.Username) == 0 || len(p.Password) == 0 { - // nothing to do if the config is bad + // nothing to do if the config is fundamentally flawed return } f.WriteCmdSilent("echo 'publishing to PyPI...'") @@ -30,9 +44,23 @@ func (p *PyPI) Write(f *buildfile.Buildfile) { // find the setup.py file f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')") + // build the .pypirc file that pypi expects f.WriteCmdSilent(fmt.Sprintf(pypirc, p.Username, p.Password)) + formatStr := p.BuildFormatStr() // if we found the setup.py file use it to deploy - f.WriteCmd("[ -z $_PYPI_SETUP_PY ] || python $_PYPI_SETUP_PY sdist --formats gztar,zip upload") - f.WriteCmd("[ -z $_PYPI_SETUP_PY ] && echo 'Failed to find setup.py file'") + f.WriteCmdSilent(fmt.Sprintf(deployCmd, formatStr)) +} + +func (p *PyPI) BuildFormatStr() string { + if len(p.Formats) == 0 { + // the format parameter is optional - if it's not here, + // omit the format string completely. + return "" + } + fmtStr := "--format " + for i := range p.Formats { + fmtStr += p.Formats[i] + "," + } + return fmtStr[:len(fmtStr) - 1] } From 2d07120891dab23ab9d45c86a3c1a5b35f2b8ef9 Mon Sep 17 00:00:00 2001 From: swgillespie Date: Sat, 29 Mar 2014 15:17:27 -0700 Subject: [PATCH 3/5] Flag is 'formats', not 'format --- pkg/plugin/publish/pypi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/plugin/publish/pypi.go b/pkg/plugin/publish/pypi.go index 7d08c2304..bf55c1ae0 100644 --- a/pkg/plugin/publish/pypi.go +++ b/pkg/plugin/publish/pypi.go @@ -58,7 +58,7 @@ func (p *PyPI) BuildFormatStr() string { // omit the format string completely. return "" } - fmtStr := "--format " + fmtStr := "--formats " for i := range p.Formats { fmtStr += p.Formats[i] + "," } From ed18293ab3ffd803ff5af9dbe59eb0e602f8386f Mon Sep 17 00:00:00 2001 From: swgillespie Date: Sat, 29 Mar 2014 15:18:25 -0700 Subject: [PATCH 4/5] Forgot to gofmt --- pkg/plugin/publish/publish.go | 4 ++-- pkg/plugin/publish/pypi.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/plugin/publish/publish.go b/pkg/plugin/publish/publish.go index 83f891f73..2cfbf6deb 100644 --- a/pkg/plugin/publish/publish.go +++ b/pkg/plugin/publish/publish.go @@ -8,9 +8,9 @@ import ( // for publishing build artifacts when // a Build has succeeded type Publish struct { - S3 *S3 `yaml:"s3,omitempty"` + S3 *S3 `yaml:"s3,omitempty"` Swift *Swift `yaml:"swift,omitempty"` - PyPI *PyPI `yaml:"pypi,omitempty"` + PyPI *PyPI `yaml:"pypi,omitempty"` } func (p *Publish) Write(f *buildfile.Buildfile) { diff --git a/pkg/plugin/publish/pypi.go b/pkg/plugin/publish/pypi.go index bf55c1ae0..67c6f33d2 100644 --- a/pkg/plugin/publish/pypi.go +++ b/pkg/plugin/publish/pypi.go @@ -29,9 +29,9 @@ fi ` type PyPI struct { - Username string `yaml:"username,omitempty"` - Password string `yaml:"password,omitempty"` - Formats []string `yaml:"formats,omitempty"` + Username string `yaml:"username,omitempty"` + Password string `yaml:"password,omitempty"` + Formats []string `yaml:"formats,omitempty"` } func (p *PyPI) Write(f *buildfile.Buildfile) { @@ -62,5 +62,5 @@ func (p *PyPI) BuildFormatStr() string { for i := range p.Formats { fmtStr += p.Formats[i] + "," } - return fmtStr[:len(fmtStr) - 1] + return fmtStr[:len(fmtStr)-1] } From fc3236b95ac119d59d4d78cc88468570f3249b7c Mon Sep 17 00:00:00 2001 From: swgillespie Date: Sat, 29 Mar 2014 15:22:37 -0700 Subject: [PATCH 5/5] Change format of .pypirc file in line with what distutils expects --- pkg/plugin/publish/pypi.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/plugin/publish/pypi.go b/pkg/plugin/publish/pypi.go index 67c6f33d2..faf28c6f6 100644 --- a/pkg/plugin/publish/pypi.go +++ b/pkg/plugin/publish/pypi.go @@ -8,9 +8,11 @@ import ( // set up the .pypirc file var pypirc = ` cat < $HOME/.pypirc -[pypirc] -servers = pypi -[server-login] +[distutils] +index-servers = + pypi + +[pypi] username:%s password:%s EOF`