2014-02-07 10:10:01 +00:00
|
|
|
package publish
|
2014-03-28 05:43:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-04-29 02:28:07 +00:00
|
|
|
|
2014-03-28 05:43:58 +00:00
|
|
|
"github.com/drone/drone/pkg/build/buildfile"
|
|
|
|
)
|
|
|
|
|
|
|
|
// set up the .pypirc file
|
|
|
|
var pypirc = `
|
|
|
|
cat <<EOF > $HOME/.pypirc
|
2014-03-29 22:22:37 +00:00
|
|
|
[distutils]
|
|
|
|
index-servers =
|
2014-04-29 20:07:29 +00:00
|
|
|
%s
|
2014-03-29 22:22:37 +00:00
|
|
|
|
2014-04-29 20:07:29 +00:00
|
|
|
[%s]
|
2014-03-28 05:43:58 +00:00
|
|
|
username:%s
|
|
|
|
password:%s
|
2014-04-29 20:07:29 +00:00
|
|
|
%s
|
2014-03-28 05:43:58 +00:00
|
|
|
EOF`
|
|
|
|
|
2014-03-29 22:15:52 +00:00
|
|
|
var deployCmd = `
|
2014-04-29 20:07:29 +00:00
|
|
|
if [ -n "$_PYPI_SETUP_PY" ]
|
2014-03-29 22:15:52 +00:00
|
|
|
then
|
2014-04-29 20:07:29 +00:00
|
|
|
python $_PYPI_SETUP_PY sdist %s upload -r %s
|
2014-03-29 22:15:52 +00:00
|
|
|
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 05:43:58 +00:00
|
|
|
type PyPI struct {
|
2014-04-29 20:07:29 +00:00
|
|
|
Username string `yaml:"username,omitempty"`
|
|
|
|
Password string `yaml:"password,omitempty"`
|
|
|
|
Formats []string `yaml:"formats,omitempty"`
|
|
|
|
Repository string `yaml:"repository,omitempty"`
|
2014-04-29 02:28:07 +00:00
|
|
|
Branch string `yaml:"branch,omitempty"`
|
2014-03-28 05:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
2014-04-29 20:07:29 +00:00
|
|
|
var indexServer string
|
|
|
|
var repository string
|
|
|
|
|
2014-03-28 05:43:58 +00:00
|
|
|
if len(p.Username) == 0 || len(p.Password) == 0 {
|
2014-03-29 22:15:52 +00:00
|
|
|
// nothing to do if the config is fundamentally flawed
|
2014-03-28 05:43:58 +00:00
|
|
|
return
|
|
|
|
}
|
2014-04-29 20:07:29 +00:00
|
|
|
|
|
|
|
// Handle the setting a custom pypi server/repository
|
|
|
|
if len(p.Repository) == 0 {
|
|
|
|
indexServer = "pypi"
|
|
|
|
repository = ""
|
|
|
|
} else {
|
|
|
|
indexServer = "custom"
|
|
|
|
repository = fmt.Sprintf("repository:%s", p.Repository)
|
|
|
|
}
|
|
|
|
|
2014-03-28 05:43:58 +00:00
|
|
|
f.WriteCmdSilent("echo 'publishing to PyPI...'")
|
|
|
|
|
|
|
|
// find the setup.py file
|
|
|
|
f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')")
|
|
|
|
|
2014-03-29 22:15:52 +00:00
|
|
|
// build the .pypirc file that pypi expects
|
2014-04-29 20:07:29 +00:00
|
|
|
f.WriteCmdSilent(fmt.Sprintf(pypirc, indexServer, indexServer, p.Username, p.Password, repository))
|
2014-03-29 22:15:52 +00:00
|
|
|
formatStr := p.BuildFormatStr()
|
2014-03-28 05:43:58 +00:00
|
|
|
|
|
|
|
// if we found the setup.py file use it to deploy
|
2014-04-29 20:07:29 +00:00
|
|
|
f.WriteCmdSilent(fmt.Sprintf(deployCmd, formatStr, indexServer))
|
2014-03-29 22:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-29 22:17:27 +00:00
|
|
|
fmtStr := "--formats "
|
2014-03-29 22:15:52 +00:00
|
|
|
for i := range p.Formats {
|
|
|
|
fmtStr += p.Formats[i] + ","
|
|
|
|
}
|
2014-03-29 22:18:25 +00:00
|
|
|
return fmtStr[:len(fmtStr)-1]
|
2014-03-28 05:43:58 +00:00
|
|
|
}
|