2014-02-07 10:10:01 +00:00
|
|
|
package publish
|
|
|
|
|
|
|
|
import (
|
2014-09-08 06:37:53 +00:00
|
|
|
"github.com/drone/drone/plugin/condition"
|
2014-10-08 02:15:33 +00:00
|
|
|
"github.com/drone/drone/plugin/publish/npm"
|
2014-06-04 21:25:38 +00:00
|
|
|
"github.com/drone/drone/shared/build/buildfile"
|
|
|
|
"github.com/drone/drone/shared/build/repo"
|
2014-02-07 10:10:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Publish stores the configuration details
|
|
|
|
// for publishing build artifacts when
|
|
|
|
// a Build has succeeded
|
|
|
|
type Publish struct {
|
2014-10-08 06:07:48 +00:00
|
|
|
S3 *S3 `yaml:"s3,omitempty"`
|
|
|
|
Swift *Swift `yaml:"swift,omitempty"`
|
|
|
|
PyPI *PyPI `yaml:"pypi,omitempty"`
|
|
|
|
NPM *npm.NPM `yaml:"npm,omitempty"`
|
|
|
|
Docker *Docker `yaml:"docker,omitempty"`
|
2014-10-11 23:14:49 +00:00
|
|
|
Github *Github `yaml:"github,omitempty"`
|
2014-02-07 10:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 02:28:07 +00:00
|
|
|
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
|
|
|
// S3
|
2014-09-08 06:37:53 +00:00
|
|
|
if p.S3 != nil && match(p.S3.GetCondition(), r) {
|
2014-02-07 10:10:01 +00:00
|
|
|
p.S3.Write(f)
|
|
|
|
}
|
2014-04-29 02:28:07 +00:00
|
|
|
|
|
|
|
// Swift
|
2014-09-08 06:37:53 +00:00
|
|
|
if p.Swift != nil && match(p.Swift.GetCondition(), r) {
|
2014-03-26 13:07:16 +00:00
|
|
|
p.Swift.Write(f)
|
|
|
|
}
|
2014-04-29 02:28:07 +00:00
|
|
|
|
|
|
|
// PyPI
|
2014-09-08 06:37:53 +00:00
|
|
|
if p.PyPI != nil && match(p.PyPI.GetCondition(), r) {
|
2014-03-28 05:43:58 +00:00
|
|
|
p.PyPI.Write(f)
|
|
|
|
}
|
2014-05-04 17:29:51 +00:00
|
|
|
|
|
|
|
// NPM
|
2014-09-08 06:37:53 +00:00
|
|
|
if p.NPM != nil && match(p.NPM.GetCondition(), r) {
|
2014-05-04 17:29:51 +00:00
|
|
|
p.NPM.Write(f)
|
|
|
|
}
|
2014-10-08 06:07:48 +00:00
|
|
|
|
2014-10-11 23:14:49 +00:00
|
|
|
// Github
|
|
|
|
if p.Github != nil && match(p.Github.GetCondition(), r) {
|
|
|
|
p.Github.Write(f)
|
|
|
|
}
|
|
|
|
|
2014-10-08 06:07:48 +00:00
|
|
|
// Docker
|
2014-10-11 21:35:06 +00:00
|
|
|
if p.Docker != nil && match(p.Docker.GetCondition(), r) {
|
|
|
|
p.Docker.Write(f)
|
2014-10-08 06:07:48 +00:00
|
|
|
}
|
2014-02-07 10:10:01 +00:00
|
|
|
}
|
2014-09-08 06:37:53 +00:00
|
|
|
|
|
|
|
func match(c *condition.Condition, r *repo.Repo) bool {
|
|
|
|
switch {
|
|
|
|
case c == nil:
|
|
|
|
return true
|
|
|
|
case !c.MatchBranch(r.Branch):
|
|
|
|
return false
|
|
|
|
case !c.MatchOwner(r.Name):
|
|
|
|
return false
|
|
|
|
case !c.MatchPullRequest(r.PR):
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|