From a7c989263eb30cc09fa726c9ed9b292d79ca62a1 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Wed, 23 Dec 2015 15:17:14 +0100 Subject: [PATCH 1/2] Added makefile, updated docs --- .drone.yml | 14 ++++---------- DOCS.md | 6 +++--- Dockerfile | 10 +++++++--- Makefile | 25 +++++++++++++++++++++++++ README.md | 45 ++++++++++++++++++++++++++++++++++++++------- 5 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 Makefile diff --git a/.drone.yml b/.drone.yml index b098dca..18d1f2a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,14 +1,9 @@ build: image: golang:1.5 - environment: - - GO15VENDOREXPERIMENT=1 - - GOOS=linux - - GOARCH=amd64 - - CGO_ENABLED=0 commands: - - go get - - go build - - go test + - make deps + - make build + - make test publish: docker: @@ -21,10 +16,9 @@ publish: plugin: name: GitHub Release - desc: Publish files and artifacts to GitHub releases + desc: Publishs files and artifacts to GitHub Releases type: publish image: plugins/drone-github-release labels: - - publish - github - release diff --git a/DOCS.md b/DOCS.md index a88acb9..7ecd3f7 100644 --- a/DOCS.md +++ b/DOCS.md @@ -2,9 +2,9 @@ Use this plugin for publishing files and artifacts to GitHub releases. You can override the default configuration with the following parameters: * `api_key` - GitHub oauth token with public_repo or repo permission -* `files` - Files to upload to GitHub Release; globs are allowed -* `base_url` - GitHub base URL; only required for GHE -* `upload_url` - GitHub upload URL; only required for GHE +* `files` - Files to upload to GitHub Release, globs are allowed +* `base_url` - GitHub base URL, only required for GHE +* `upload_url` - GitHub upload URL, only required for GHE Sample configuration: diff --git a/Dockerfile b/Dockerfile index 4917c29..715651b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ # Docker image for the Drone GitHub Release plugin # # cd $GOPATH/src/github.com/drone-plugins/drone-github-release -# GO15VENDOREXPERIMENT=1 CGO_ENABLED=0 go build -a -tags netgo -# docker build --rm=true -t plugins/drone-github-release . +# make deps build docker FROM alpine:3.2 -RUN apk add -U ca-certificates && rm -rf /var/cache/apk/* + +RUN apk update && \ + apk add \ + ca-certificates && \ + rm -rf /var/cache/apk/* + ADD drone-github-release /bin/ ENTRYPOINT ["/bin/drone-github-release"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f3d2a4f --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +.PHONY: clean deps test build docker + +export GOOS ?= linux +export GOARCH ?= amd64 +export CGO_ENABLED ?= 0 + +CI_BUILD_NUMBER ?= 0 + +LDFLAGS += -X "main.buildDate=$(shell date -u '+%Y-%m-%d %H:%M:%S %Z')" +LDFLAGS += -X "main.build=$(CI_BUILD_NUMBER)" + +clean: + go clean -i ./... + +deps: + go get -t ./... + +test: + go test -cover ./... + +build: + go build -ldflags '-s -w $(LDFLAGS)' + +docker: + docker build --rm=true -t plugins/drone-github-release . diff --git a/README.md b/README.md index db799be..6f9858f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # drone-github-release +[![Build Status](http://beta.drone.io/api/badges/drone-plugins/drone-github-release/status.svg)](http://beta.drone.io/drone-plugins/drone-github-release) +[![](https://badge.imagelayers.io/plugins/drone-github-release:latest.svg)](https://imagelayers.io/?images=plugins/drone-github-release:latest 'Get your own badge on imagelayers.io') + Drone plugin for publishing GitHub releases ## Usage -Publish a release: - ``` ./drone-github-release < Date: Wed, 23 Dec 2015 15:18:22 +0100 Subject: [PATCH 2/2] Moved struct into separate file, fixed bug for nonexistant releases --- main.go | 39 ++++++++++++++++----------------------- types.go | 8 ++++++++ 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 types.go diff --git a/main.go b/main.go index 855cae8..a72683c 100644 --- a/main.go +++ b/main.go @@ -15,23 +15,23 @@ import ( "golang.org/x/oauth2" ) -type Params struct { - BaseUrl string `json:"base_url"` - UploadUrl string `json:"upload_url"` - APIKey string `json:"api_key"` - Files []string `json:"files"` -} +var ( + build string + buildDate string +) func main() { + fmt.Printf("Drone GitHub Release Plugin built at %s\n", buildDate) + workspace := drone.Workspace{} repo := drone.Repo{} build := drone.Build{} vargs := Params{} + plugin.Param("workspace", &workspace) plugin.Param("repo", &repo) plugin.Param("build", &build) plugin.Param("vargs", &vargs) - plugin.Param("workspace", &workspace) plugin.MustParse() if build.Event != "tag" { @@ -41,10 +41,6 @@ func main() { return } - if len(workspace.Path) != 0 { - os.Chdir(workspace.Path) - } - if len(vargs.BaseUrl) == 0 { vargs.BaseUrl = "https://api.github.com/" } else { @@ -68,6 +64,10 @@ func main() { return } + if len(workspace.Path) != 0 { + os.Chdir(workspace.Path) + } + files := make([]string, 0) for _, glob := range vargs.Files { @@ -116,7 +116,7 @@ func main() { client.BaseURL = baseUrl client.UploadURL = uploadUrl - release, releaseErr := retrieveRelease( + release, releaseErr := prepareRelease( client, repo.Owner, repo.Name, @@ -145,31 +145,24 @@ func main() { } func prepareRelease(client *github.Client, owner string, repo string, tag string) (*github.RepositoryRelease, error) { - var release *github.RepositoryRelease - var releaseErr error - - release, releaseErr = retrieveRelease( + release, _ := retrieveRelease( client, owner, repo, tag) - if releaseErr != nil { - return nil, releaseErr - } - if release != nil { return release, nil } - release, releaseErr = createRelease( + release, err := createRelease( client, owner, repo, tag) - if releaseErr != nil { - return nil, releaseErr + if err != nil { + return nil, err } if release != nil { diff --git a/types.go b/types.go new file mode 100644 index 0000000..8f739fa --- /dev/null +++ b/types.go @@ -0,0 +1,8 @@ +package main + +type Params struct { + BaseUrl string `json:"base_url"` + UploadUrl string `json:"upload_url"` + APIKey string `json:"api_key"` + Files []string `json:"files"` +}