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:
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

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:
* `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:

View File

@ -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"]

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
[![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 <<EOF
{
@ -23,7 +24,7 @@ Publish a release:
},
"workspace": {
"root": "/drone/src",
"path": "drone/src/github.com/drone/drone"
"path": "/drone/src/github.com/drone/drone"
},
"vargs": {
"api_key": "your_api_key",
@ -38,10 +39,40 @@ EOF
## Docker
Build the Docker container using the `netgo` build tag to eliminate the CGO
dependency:
Build the Docker container using `make`:
```
GO15VENDOREXPERIMENT=1 CGO_ENABLED=0 go build -a -tags netgo
docker build --rm=true -t plugins/drone-github-release .
make deps build docker
```
### 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"
)
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 {

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