harness-drone/pkg/plugin/publish/pypi.go

39 lines
914 B
Go
Raw Normal View History

2014-02-07 10:10:01 +00:00
package publish
2014-03-28 05:43:58 +00:00
import (
"fmt"
"github.com/drone/drone/pkg/build/buildfile"
)
// set up the .pypirc file
var pypirc = `
cat <<EOF > $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'")
}