2014-02-07 13:10:01 +03:00
|
|
|
package publish
|
2014-03-28 08:43:58 +03: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`
|
|
|
|
|
2014-03-30 01:15:52 +03:00
|
|
|
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
|
|
|
|
`
|
|
|
|
|
2014-03-28 08:43:58 +03:00
|
|
|
type PyPI struct {
|
|
|
|
Username string `yaml:"username,omitempty"`
|
|
|
|
Password string `yaml:"password,omitempty"`
|
2014-03-30 01:15:52 +03:00
|
|
|
Formats []string `yaml:"formats,omitempty"`
|
2014-03-28 08:43:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
|
|
|
if len(p.Username) == 0 || len(p.Password) == 0 {
|
2014-03-30 01:15:52 +03:00
|
|
|
// nothing to do if the config is fundamentally flawed
|
2014-03-28 08:43:58 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
f.WriteCmdSilent("echo 'publishing to PyPI...'")
|
|
|
|
|
|
|
|
// find the setup.py file
|
|
|
|
f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')")
|
|
|
|
|
2014-03-30 01:15:52 +03:00
|
|
|
// build the .pypirc file that pypi expects
|
2014-03-28 08:43:58 +03:00
|
|
|
f.WriteCmdSilent(fmt.Sprintf(pypirc, p.Username, p.Password))
|
2014-03-30 01:15:52 +03:00
|
|
|
formatStr := p.BuildFormatStr()
|
2014-03-28 08:43:58 +03:00
|
|
|
|
|
|
|
// if we found the setup.py file use it to deploy
|
2014-03-30 01:15:52 +03:00
|
|
|
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 ""
|
|
|
|
}
|
2014-03-30 01:17:27 +03:00
|
|
|
fmtStr := "--formats "
|
2014-03-30 01:15:52 +03:00
|
|
|
for i := range p.Formats {
|
|
|
|
fmtStr += p.Formats[i] + ","
|
|
|
|
}
|
|
|
|
return fmtStr[:len(fmtStr) - 1]
|
2014-03-28 08:43:58 +03:00
|
|
|
}
|