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'") +}