From ce5d4edca55d9885a83170b35a1241a6dfa98203 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Mon, 12 Jan 2015 16:50:59 +0300 Subject: [PATCH 1/2] Bintray plugin --- plugin/publish/bintray.go | 1 - plugin/publish/bintray/bintray.go | 50 +++++++++++++ plugin/publish/bintray/package.go | 116 ++++++++++++++++++++++++++++++ plugin/publish/publish.go | 21 ++++-- 4 files changed, 180 insertions(+), 8 deletions(-) delete mode 100644 plugin/publish/bintray.go create mode 100644 plugin/publish/bintray/bintray.go create mode 100644 plugin/publish/bintray/package.go diff --git a/plugin/publish/bintray.go b/plugin/publish/bintray.go deleted file mode 100644 index 30b1a5b2..00000000 --- a/plugin/publish/bintray.go +++ /dev/null @@ -1 +0,0 @@ -package publish diff --git a/plugin/publish/bintray/bintray.go b/plugin/publish/bintray/bintray.go new file mode 100644 index 00000000..9a0383e2 --- /dev/null +++ b/plugin/publish/bintray/bintray.go @@ -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 +} diff --git a/plugin/publish/bintray/package.go b/plugin/publish/bintray/package.go new file mode 100644 index 00000000..31f35e1d --- /dev/null +++ b/plugin/publish/bintray/package.go @@ -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 + } +} diff --git a/plugin/publish/publish.go b/plugin/publish/publish.go index 4ce6d4b1..8286097d 100644 --- a/plugin/publish/publish.go +++ b/plugin/publish/publish.go @@ -2,6 +2,7 @@ package publish import ( "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/plugin/publish/bintray" "github.com/drone/drone/plugin/publish/npm" "github.com/drone/drone/shared/build/buildfile" "github.com/drone/drone/shared/build/repo" @@ -11,13 +12,14 @@ import ( // for publishing build artifacts when // a Build has succeeded type Publish struct { - 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"` - Github *Github `yaml:"github,omitempty"` - Dropbox *Dropbox `yaml:"dropbox,omitempty"` + 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"` + Github *Github `yaml:"github,omitempty"` + Dropbox *Dropbox `yaml:"dropbox,omitempty"` + Bintray *bintray.Bintray `yaml:"bintray,omitempty"` } 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) { 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 { From ef3fba75a908e5f7866e2f09c58fabbdc1062ca5 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Mon, 12 Jan 2015 16:51:54 +0300 Subject: [PATCH 2/2] Version from file --- Makefile | 12 ++++++++---- VERSION | 1 + cli/main.go | 2 +- server/main.go | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 VERSION diff --git a/Makefile b/Makefile index e6efdd2a..2e9e12e0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ SHA := $(shell git rev-parse --short HEAD) +VERSION := $(shell cat VERSION) +ITTERATION := $(shell date +%s) all: build @@ -23,8 +25,8 @@ test_postgres: build: mkdir -p packaging/output mkdir -p packaging/root/usr/local/bin - go build -o packaging/root/usr/local/bin/drone -ldflags "-X main.revision $(SHA)" github.com/drone/drone/cli - go build -o packaging/root/usr/local/bin/droned -ldflags "-X main.revision $(SHA)" github.com/drone/drone/server + go build -o packaging/root/usr/local/bin/drone -ldflags "-X main.revision $(SHA) -X main.version $(VERSION)" github.com/drone/drone/cli + go build -o packaging/root/usr/local/bin/droned -ldflags "-X main.revision $(SHA) -X main.version $(VERSION)" github.com/drone/drone/server install: install -t /usr/local/bin packaging/root/usr/local/bin/drone @@ -52,9 +54,10 @@ embed: # creates a debian package for drone to install # `sudo dpkg -i drone.deb` deb: - fpm -s dir -t deb -n drone -v 0.3 -p packaging/output/drone.deb \ + fpm -s dir -t deb -n drone -v $(VERSION) -p packaging/output/drone.deb \ --deb-priority optional --category admin \ --force \ + --iteration $(ITTERATION) \ --deb-compression bzip2 \ --after-install packaging/scripts/postinst.deb \ --before-remove packaging/scripts/prerm.deb \ @@ -68,9 +71,10 @@ deb: packaging/root/=/ rpm: - fpm -s dir -t rpm -n drone -v 0.3 -p packaging/output/drone.rpm \ + fpm -s dir -t rpm -n drone -v $(VERSION) -p packaging/output/drone.rpm \ --rpm-compression bzip2 --rpm-os linux \ --force \ + --iteration $(ITTERATION) \ --after-install packaging/scripts/postinst.rpm \ --before-remove packaging/scripts/prerm.rpm \ --after-remove packaging/scripts/postrm.rpm \ diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..0852d432 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.3.0-alpha \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index d051834c..0a2e3b90 100644 --- a/cli/main.go +++ b/cli/main.go @@ -7,7 +7,7 @@ import ( var ( // commit sha for the current build. - version string = "0.3-dev" + version string revision string ) diff --git a/server/main.go b/server/main.go index 9fd47cd2..ae41dc7b 100644 --- a/server/main.go +++ b/server/main.go @@ -41,7 +41,7 @@ const ( var ( // commit sha for the current build, set by // the compile process. - version string = "0.3-dev" + version string revision string )