Add ability to choose different formats
This commit is contained in:
parent
44aaf4fd9c
commit
ec409e51a1
2 changed files with 32 additions and 4 deletions
|
@ -10,7 +10,7 @@ import (
|
||||||
type Publish struct {
|
type Publish struct {
|
||||||
S3 *S3 `yaml:"s3,omitempty"`
|
S3 *S3 `yaml:"s3,omitempty"`
|
||||||
Swift *Swift `yaml:"swift,omitempty"`
|
Swift *Swift `yaml:"swift,omitempty"`
|
||||||
PyPI *PyPI `yaml:"pypi, omitempty"`
|
PyPI *PyPI `yaml:"pypi,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Publish) Write(f *buildfile.Buildfile) {
|
func (p *Publish) Write(f *buildfile.Buildfile) {
|
||||||
|
|
|
@ -15,14 +15,28 @@ username:%s
|
||||||
password:%s
|
password:%s
|
||||||
EOF`
|
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 {
|
type PyPI struct {
|
||||||
Username string `yaml:"username,omitempty"`
|
Username string `yaml:"username,omitempty"`
|
||||||
Password string `yaml:"password,omitempty"`
|
Password string `yaml:"password,omitempty"`
|
||||||
|
Formats []string `yaml:"formats,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
||||||
if len(p.Username) == 0 || len(p.Password) == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
f.WriteCmdSilent("echo 'publishing to PyPI...'")
|
f.WriteCmdSilent("echo 'publishing to PyPI...'")
|
||||||
|
@ -30,9 +44,23 @@ func (p *PyPI) Write(f *buildfile.Buildfile) {
|
||||||
// find the setup.py file
|
// find the setup.py file
|
||||||
f.WriteCmdSilent("_PYPI_SETUP_PY=$(find . -name 'setup.py')")
|
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))
|
f.WriteCmdSilent(fmt.Sprintf(pypirc, p.Username, p.Password))
|
||||||
|
formatStr := p.BuildFormatStr()
|
||||||
|
|
||||||
// if we found the setup.py file use it to deploy
|
// 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.WriteCmdSilent(fmt.Sprintf(deployCmd, formatStr))
|
||||||
f.WriteCmd("[ -z $_PYPI_SETUP_PY ] && echo 'Failed to find setup.py file'")
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue