Merge pull request #3 from drone-plugins/feature/fixes

Bugfix and added makefile
This commit is contained in:
Brad Rydzewski 2015-12-23 11:29:26 -05:00
commit b586b84117
7 changed files with 101 additions and 46 deletions

View File

@ -1,14 +1,9 @@
build: build:
image: golang:1.5 image: golang:1.5
environment:
- GO15VENDOREXPERIMENT=1
- GOOS=linux
- GOARCH=amd64
- CGO_ENABLED=0
commands: commands:
- go get - make deps
- go build - make build
- go test - make test
publish: publish:
docker: docker:
@ -21,10 +16,9 @@ publish:
plugin: plugin:
name: GitHub Release name: GitHub Release
desc: Publish files and artifacts to GitHub releases desc: Publishs files and artifacts to GitHub Releases
type: publish type: publish
image: plugins/drone-github-release image: plugins/drone-github-release
labels: labels:
- publish
- github - github
- release - release

View File

@ -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: can override the default configuration with the following parameters:
* `api_key` - GitHub oauth token with public_repo or repo permission * `api_key` - GitHub oauth token with public_repo or repo permission
* `files` - Files to upload to GitHub Release; globs are allowed * `files` - Files to upload to GitHub Release, globs are allowed
* `base_url` - GitHub base URL; only required for GHE * `base_url` - GitHub base URL, only required for GHE
* `upload_url` - GitHub upload URL; only required for GHE * `upload_url` - GitHub upload URL, only required for GHE
Sample configuration: Sample configuration:

View File

@ -1,10 +1,14 @@
# Docker image for the Drone GitHub Release plugin # Docker image for the Drone GitHub Release plugin
# #
# cd $GOPATH/src/github.com/drone-plugins/drone-github-release # cd $GOPATH/src/github.com/drone-plugins/drone-github-release
# GO15VENDOREXPERIMENT=1 CGO_ENABLED=0 go build -a -tags netgo # make deps build docker
# docker build --rm=true -t plugins/drone-github-release .
FROM alpine:3.2 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/ ADD drone-github-release /bin/
ENTRYPOINT ["/bin/drone-github-release"] ENTRYPOINT ["/bin/drone-github-release"]

25
Makefile Normal file
View File

@ -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 .

View File

@ -1,11 +1,12 @@
# drone-github-release # 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 Drone plugin for publishing GitHub releases
## Usage ## Usage
Publish a release:
``` ```
./drone-github-release <<EOF ./drone-github-release <<EOF
{ {
@ -23,7 +24,7 @@ Publish a release:
}, },
"workspace": { "workspace": {
"root": "/drone/src", "root": "/drone/src",
"path": "drone/src/github.com/drone/drone" "path": "/drone/src/github.com/drone/drone"
}, },
"vargs": { "vargs": {
"api_key": "your_api_key", "api_key": "your_api_key",
@ -38,10 +39,40 @@ EOF
## Docker ## Docker
Build the Docker container using the `netgo` build tag to eliminate the CGO Build the Docker container using `make`:
dependency:
``` ```
GO15VENDOREXPERIMENT=1 CGO_ENABLED=0 go build -a -tags netgo make deps build docker
docker build --rm=true -t plugins/drone-github-release . ```
### Example
```sh
docker run -i plugins/drone-github-release <<EOF
{
"repo": {
"clone_url": "git://github.com/drone/drone",
"full_name": "drone/drone",
"owner": "drone",
"name": "drone"
},
"build": {
"event": "tag",
"branch": "refs/heads/v0.0.1",
"commit": "8f5d3b2ce38562bedb48b798328f5bb2e4077a2f",
"ref": "refs/heads/v0.0.1"
},
"workspace": {
"root": "/drone/src",
"path": "/drone/src/github.com/drone/drone"
},
"vargs": {
"api_key": "your_api_key",
"files": [
"dist/*.txt",
"dist/other-file"
]
}
}
EOF
``` ```

39
main.go
View File

@ -15,23 +15,23 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
type Params struct { var (
BaseUrl string `json:"base_url"` build string
UploadUrl string `json:"upload_url"` buildDate string
APIKey string `json:"api_key"` )
Files []string `json:"files"`
}
func main() { func main() {
fmt.Printf("Drone GitHub Release Plugin built at %s\n", buildDate)
workspace := drone.Workspace{} workspace := drone.Workspace{}
repo := drone.Repo{} repo := drone.Repo{}
build := drone.Build{} build := drone.Build{}
vargs := Params{} vargs := Params{}
plugin.Param("workspace", &workspace)
plugin.Param("repo", &repo) plugin.Param("repo", &repo)
plugin.Param("build", &build) plugin.Param("build", &build)
plugin.Param("vargs", &vargs) plugin.Param("vargs", &vargs)
plugin.Param("workspace", &workspace)
plugin.MustParse() plugin.MustParse()
if build.Event != "tag" { if build.Event != "tag" {
@ -41,10 +41,6 @@ func main() {
return return
} }
if len(workspace.Path) != 0 {
os.Chdir(workspace.Path)
}
if len(vargs.BaseUrl) == 0 { if len(vargs.BaseUrl) == 0 {
vargs.BaseUrl = "https://api.github.com/" vargs.BaseUrl = "https://api.github.com/"
} else { } else {
@ -68,6 +64,10 @@ func main() {
return return
} }
if len(workspace.Path) != 0 {
os.Chdir(workspace.Path)
}
files := make([]string, 0) files := make([]string, 0)
for _, glob := range vargs.Files { for _, glob := range vargs.Files {
@ -116,7 +116,7 @@ func main() {
client.BaseURL = baseUrl client.BaseURL = baseUrl
client.UploadURL = uploadUrl client.UploadURL = uploadUrl
release, releaseErr := retrieveRelease( release, releaseErr := prepareRelease(
client, client,
repo.Owner, repo.Owner,
repo.Name, repo.Name,
@ -145,31 +145,24 @@ func main() {
} }
func prepareRelease(client *github.Client, owner string, repo string, tag string) (*github.RepositoryRelease, error) { func prepareRelease(client *github.Client, owner string, repo string, tag string) (*github.RepositoryRelease, error) {
var release *github.RepositoryRelease release, _ := retrieveRelease(
var releaseErr error
release, releaseErr = retrieveRelease(
client, client,
owner, owner,
repo, repo,
tag) tag)
if releaseErr != nil {
return nil, releaseErr
}
if release != nil { if release != nil {
return release, nil return release, nil
} }
release, releaseErr = createRelease( release, err := createRelease(
client, client,
owner, owner,
repo, repo,
tag) tag)
if releaseErr != nil { if err != nil {
return nil, releaseErr return nil, err
} }
if release != nil { if release != nil {

8
types.go Normal file
View File

@ -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"`
}