mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 18:31:00 +00:00
Bintray plugin
This commit is contained in:
parent
6ed8542f7d
commit
ce5d4edca5
4 changed files with 180 additions and 8 deletions
|
@ -1 +0,0 @@
|
||||||
package publish
|
|
50
plugin/publish/bintray/bintray.go
Normal file
50
plugin/publish/bintray/bintray.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package bintray
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/drone/drone/plugin/condition"
|
||||||
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Bintray struct {
|
||||||
|
Username string `yaml:"username"`
|
||||||
|
ApiKey string `yaml:"api_key"`
|
||||||
|
Packages []Package `yaml:"packages"`
|
||||||
|
|
||||||
|
Condition *condition.Condition `yaml:"when,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bintray) Write(f *buildfile.Buildfile) {
|
||||||
|
var cmd string
|
||||||
|
|
||||||
|
// Validate Username, ApiKey, Packages
|
||||||
|
if len(b.Username) == 0 || len(b.ApiKey) == 0 || len(b.Packages) == 0 {
|
||||||
|
f.WriteCmdSilent(`echo -e "Bintray Plugin: Missing argument(s)\n\n"`)
|
||||||
|
|
||||||
|
if len(b.Username) == 0 {
|
||||||
|
f.WriteCmdSilent(`echo -e "\tusername not defined in yaml config"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.ApiKey) == 0 {
|
||||||
|
f.WriteCmdSilent(`echo -e "\tapi_key not defined in yaml config"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.Packages) == 0 {
|
||||||
|
f.WriteCmdSilent(`echo -e "\tpackages not defined in yaml config"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmdSilent("exit 1")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pkg := range b.Packages {
|
||||||
|
pkg.Write(b.Username, b.ApiKey, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmd(cmd)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bintray) GetCondition() *condition.Condition {
|
||||||
|
return b.Condition
|
||||||
|
}
|
116
plugin/publish/bintray/package.go
Normal file
116
plugin/publish/bintray/package.go
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
package bintray
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/drone/drone/shared/build/buildfile"
|
||||||
|
)
|
||||||
|
|
||||||
|
const bintray_endpoint = "https://api.bintray.com/content/%s/%s/%s/%s/%s"
|
||||||
|
|
||||||
|
type Package struct {
|
||||||
|
File string `yaml:"file"`
|
||||||
|
Type string `yaml:"type"`
|
||||||
|
Owner string `yaml:"owner"`
|
||||||
|
Repository string `yaml:"repository"`
|
||||||
|
Package string `yaml:"package"`
|
||||||
|
Version string `yaml:"version"`
|
||||||
|
Target string `yaml:"target"`
|
||||||
|
Distr string `yaml:"distr,omitempty"`
|
||||||
|
Component string `yaml:"component,omitempty"`
|
||||||
|
Arch []string `yaml:"arch,omitempty"`
|
||||||
|
Publish bool `yaml:"publish,omitempty"`
|
||||||
|
Override bool `yaml:"override,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Package) Write(username, api_key string, f *buildfile.Buildfile) {
|
||||||
|
if len(p.File) == 0 || len(p.Owner) == 0 || len(p.Repository) == 0 || len(p.Package) == 0 || len(p.Version) == 0 || len(p.Target) == 0 {
|
||||||
|
f.WriteCmdSilent(`echo -e "Bintray Plugin: Missing argument(s)\n\n"`)
|
||||||
|
|
||||||
|
if len(p.Package) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage not defined in yaml config"`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.File) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: file not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Owner) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: owner not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Repository) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: repository not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Version) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: version not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Target) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: target not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmdSilent("exit 1")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch p.Type {
|
||||||
|
case "deb":
|
||||||
|
p.debUpload(username, api_key, f)
|
||||||
|
case "rpm":
|
||||||
|
p.upload(username, api_key, f)
|
||||||
|
case "maven":
|
||||||
|
p.upload(username, api_key, f)
|
||||||
|
default:
|
||||||
|
p.upload(username, api_key, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Package) debUpload(username, api_key string, f *buildfile.Buildfile) {
|
||||||
|
if len(p.Distr) == 0 || len(p.Component) == 0 || len(p.Arch) == 0 {
|
||||||
|
f.WriteCmdSilent(`echo -e "Bintray Plugin: Missing argument(s)\n\n"`)
|
||||||
|
|
||||||
|
if len(p.Distr) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: distr not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Component) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: component not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Arch) == 0 {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\tpackage %s: arch not defined in yaml config"`, p.Package))
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmdSilent("exit 1")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\nUpload %s to %s/%s/%s"`, p.File, p.Owner, p.Repository, p.Package))
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf("curl -s -T %s -u%s:%s %s\\;deb_distribution\\=%s\\;deb_component\\=%s\\;deb_architecture=\\%s\\;publish\\=%d\\;override\\=%d",
|
||||||
|
p.File, username, api_key, p.getEndpoint(), p.Distr, p.Component, strings.Join(p.Arch, ","), boolToInt(p.Publish), boolToInt(p.Override)))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Package) upload(username, api_key string, f *buildfile.Buildfile) {
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf(`echo -e "\nUpload %s to %s/%s/%s"`, p.File, p.Owner, p.Repository, p.Package))
|
||||||
|
f.WriteCmdSilent(fmt.Sprintf("curl -s -T %s -u%s:%s %s\\;publish\\=%d\\;override\\=%d",
|
||||||
|
p.File, username, api_key, p.getEndpoint(), boolToInt(p.Publish), boolToInt(p.Override)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Package) getEndpoint() string {
|
||||||
|
return fmt.Sprintf(bintray_endpoint, p.Owner, p.Repository, p.Package, p.Version, p.Target)
|
||||||
|
}
|
||||||
|
|
||||||
|
func boolToInt(val bool) int {
|
||||||
|
if val {
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package publish
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/drone/drone/plugin/condition"
|
"github.com/drone/drone/plugin/condition"
|
||||||
|
"github.com/drone/drone/plugin/publish/bintray"
|
||||||
"github.com/drone/drone/plugin/publish/npm"
|
"github.com/drone/drone/plugin/publish/npm"
|
||||||
"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"
|
||||||
|
@ -18,6 +19,7 @@ type Publish struct {
|
||||||
Docker *Docker `yaml:"docker,omitempty"`
|
Docker *Docker `yaml:"docker,omitempty"`
|
||||||
Github *Github `yaml:"github,omitempty"`
|
Github *Github `yaml:"github,omitempty"`
|
||||||
Dropbox *Dropbox `yaml:"dropbox,omitempty"`
|
Dropbox *Dropbox `yaml:"dropbox,omitempty"`
|
||||||
|
Bintray *bintray.Bintray `yaml:"bintray,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
||||||
|
@ -55,6 +57,11 @@ func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
|
||||||
if p.Dropbox != nil && match(p.Dropbox.GetCondition(), r) {
|
if p.Dropbox != nil && match(p.Dropbox.GetCondition(), r) {
|
||||||
p.Dropbox.Write(f)
|
p.Dropbox.Write(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bintray
|
||||||
|
if p.Bintray != nil && match(p.Bintray.GetCondition(), r) {
|
||||||
|
p.Bintray.Write(f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func match(c *condition.Condition, r *repo.Repo) bool {
|
func match(c *condition.Condition, r *repo.Repo) bool {
|
||||||
|
|
Loading…
Reference in a new issue