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:
parent
51a0407101
commit
09ebb92a42
@ -3,6 +3,7 @@ package publish
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ type NPM struct {
|
|||||||
// Registers the published package with the given tag
|
// Registers the published package with the given tag
|
||||||
Tag string `yaml:"tag,omitempty"`
|
Tag string `yaml:"tag,omitempty"`
|
||||||
|
|
||||||
Branch string `yaml:"branch,omitempty"`
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NPM) Write(f *buildfile.Buildfile) {
|
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))
|
f.WriteCmd(fmt.Sprintf(npmPublishCmd, n.Folder))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *NPM) GetCondition() *condition.Condition {
|
||||||
|
return n.Condition
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package publish
|
package publish
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
"github.com/drone/drone/shared/build/repo"
|
"github.com/drone/drone/shared/build/repo"
|
||||||
)
|
)
|
||||||
@ -17,22 +18,36 @@ type Publish struct {
|
|||||||
|
|
||||||
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
||||||
// S3
|
// 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)
|
p.S3.Write(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swift
|
// 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)
|
p.Swift.Write(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PyPI
|
// 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)
|
p.PyPI.Write(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NPM
|
// 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)
|
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
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ package publish
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +38,8 @@ type PyPI struct {
|
|||||||
Password string `yaml:"password,omitempty"`
|
Password string `yaml:"password,omitempty"`
|
||||||
Formats []string `yaml:"formats,omitempty"`
|
Formats []string `yaml:"formats,omitempty"`
|
||||||
Repository string `yaml:"repository,omitempty"`
|
Repository string `yaml:"repository,omitempty"`
|
||||||
Branch string `yaml:"branch,omitempty"`
|
|
||||||
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
func (p *PyPI) Write(f *buildfile.Buildfile) {
|
||||||
@ -83,3 +85,7 @@ func (p *PyPI) BuildFormatStr() string {
|
|||||||
}
|
}
|
||||||
return fmtStr[:len(fmtStr)-1]
|
return fmtStr[:len(fmtStr)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PyPI) GetCondition() *condition.Condition {
|
||||||
|
return p.Condition
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ type S3 struct {
|
|||||||
// Recursive uploads
|
// Recursive uploads
|
||||||
Recursive bool `yaml:"recursive"`
|
Recursive bool `yaml:"recursive"`
|
||||||
|
|
||||||
Branch string `yaml:"branch,omitempty"`
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *S3) Write(f *buildfile.Buildfile) {
|
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))
|
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
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
"github.com/drone/drone/shared/build/buildfile"
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ type Swift struct {
|
|||||||
// object name if source is a file
|
// object name if source is a file
|
||||||
Target string `yaml:"target,omitempty"`
|
Target string `yaml:"target,omitempty"`
|
||||||
|
|
||||||
Branch string `yaml:"branch,omitempty"`
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Swift) Write(f *buildfile.Buildfile) {
|
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))
|
f.WriteCmd(fmt.Sprintf(`swiftly put -i %s %s%s`, s.Source, s.Container, target))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Swift) GetCondition() *condition.Condition {
|
||||||
|
return s.Condition
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user