1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02:00

added when condition to publish plugins

This commit is contained in:
Brad Rydzewski 2014-09-07 23:37:53 -07:00
parent 51a0407101
commit 09ebb92a42
5 changed files with 44 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package publish
import (
"fmt"
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
@ -40,7 +41,7 @@ type NPM struct {
// Registers the published package with the given tag
Tag string `yaml:"tag,omitempty"`
Branch string `yaml:"branch,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (n *NPM) Write(f *buildfile.Buildfile) {
@ -71,3 +72,7 @@ func (n *NPM) Write(f *buildfile.Buildfile) {
f.WriteCmd(fmt.Sprintf(npmPublishCmd, n.Folder))
}
func (n *NPM) GetCondition() *condition.Condition {
return n.Condition
}

View File

@ -1,6 +1,7 @@
package publish
import (
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
"github.com/drone/drone/shared/build/repo"
)
@ -17,22 +18,36 @@ type Publish struct {
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
// S3
if p.S3 != nil && (len(p.S3.Branch) == 0 || (len(p.S3.Branch) > 0 && r.Branch == p.S3.Branch)) {
if p.S3 != nil && match(p.S3.GetCondition(), r) {
p.S3.Write(f)
}
// Swift
if p.Swift != nil && (len(p.Swift.Branch) == 0 || (len(p.Swift.Branch) > 0 && r.Branch == p.Swift.Branch)) {
if p.Swift != nil && match(p.Swift.GetCondition(), r) {
p.Swift.Write(f)
}
// PyPI
if p.PyPI != nil && (len(p.PyPI.Branch) == 0 || (len(p.PyPI.Branch) > 0 && r.Branch == p.PyPI.Branch)) {
if p.PyPI != nil && match(p.PyPI.GetCondition(), r) {
p.PyPI.Write(f)
}
// NPM
if p.NPM != nil && (len(p.NPM.Branch) == 0 || (len(p.NPM.Branch) > 0 && r.Branch == p.NPM.Branch)) {
if p.NPM != nil && match(p.NPM.GetCondition(), r) {
p.NPM.Write(f)
}
}
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
}

View File

@ -3,6 +3,7 @@ package publish
import (
"fmt"
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
@ -37,7 +38,8 @@ type PyPI struct {
Password string `yaml:"password,omitempty"`
Formats []string `yaml:"formats,omitempty"`
Repository string `yaml:"repository,omitempty"`
Branch string `yaml:"branch,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (p *PyPI) Write(f *buildfile.Buildfile) {
@ -83,3 +85,7 @@ func (p *PyPI) BuildFormatStr() string {
}
return fmtStr[:len(fmtStr)-1]
}
func (p *PyPI) GetCondition() *condition.Condition {
return p.Condition
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
@ -47,7 +48,7 @@ type S3 struct {
// Recursive uploads
Recursive bool `yaml:"recursive"`
Branch string `yaml:"branch,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (s *S3) Write(f *buildfile.Buildfile) {
@ -94,3 +95,7 @@ func (s *S3) Write(f *buildfile.Buildfile) {
f.WriteCmd(fmt.Sprintf(`aws s3 cp %s s3://%s/%s --acl %s --region %s`, s.Source, s.Bucket, s.Target, s.Access, s.Region))
}
}
func (s *S3) GetCondition() *condition.Condition {
return s.Condition
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/drone/drone/plugin/condition"
"github.com/drone/drone/shared/build/buildfile"
)
@ -34,7 +35,7 @@ type Swift struct {
// object name if source is a file
Target string `yaml:"target,omitempty"`
Branch string `yaml:"branch,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"`
}
func (s *Swift) Write(f *buildfile.Buildfile) {
@ -65,3 +66,7 @@ func (s *Swift) Write(f *buildfile.Buildfile) {
f.WriteCmd(fmt.Sprintf(`swiftly put -i %s %s%s`, s.Source, s.Container, target))
}
func (s *Swift) GetCondition() *condition.Condition {
return s.Condition
}