Skip to content

Commit bc94a20

Browse files
authored
Merge pull request #45 from arangodb/releasing
Added release code
2 parents 6bc3f14 + e50f09b commit bc94a20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4886
-85
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ update-vendor:
125125
k8s.io/client-go/... \
126126
k8s.io/gengo/args \
127127
k8s.io/apiextensions-apiserver \
128+
github.com/aktau/github-release \
128129
github.com/arangodb-helper/go-certificates \
129130
github.com/arangodb/go-driver \
130131
github.com/cenkalti/backoff \
132+
github.com/coreos/go-semver/semver \
131133
github.com/dchest/uniuri \
132134
github.com/dgrijalva/jwt-go \
133135
github.com/julienschmidt/httprouter \
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
github-release
2+
go-app
3+
bin/
4+
5+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
6+
*.o
7+
*.a
8+
*.so
9+
10+
# Folders
11+
_obj
12+
_test
13+
14+
# Architecture specific extensions/prefixes
15+
*.[568vq]
16+
[568vq].out
17+
18+
*.cgo1.go
19+
*.cgo2.c
20+
_cgo_defun.c
21+
_cgo_gotypes.go
22+
_cgo_export.*
23+
24+
_testmain.go
25+
26+
*.exe
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Nicolas Hillegeer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
LAST_TAG := $(shell git describe --abbrev=0 --tags)
2+
3+
USER := aktau
4+
EXECUTABLE := github-release
5+
6+
# only include the amd64 binaries, otherwise the github release will become
7+
# too big
8+
UNIX_EXECUTABLES := \
9+
darwin/amd64/$(EXECUTABLE) \
10+
freebsd/amd64/$(EXECUTABLE) \
11+
linux/amd64/$(EXECUTABLE)
12+
WIN_EXECUTABLES := \
13+
windows/amd64/$(EXECUTABLE).exe
14+
15+
COMPRESSED_EXECUTABLES=$(UNIX_EXECUTABLES:%=%.bz2) $(WIN_EXECUTABLES:%.exe=%.zip)
16+
COMPRESSED_EXECUTABLE_TARGETS=$(COMPRESSED_EXECUTABLES:%=bin/%)
17+
18+
UPLOAD_CMD = bin/tmp/$(EXECUTABLE) upload -u $(USER) -r $(EXECUTABLE) -t $(LAST_TAG) -n $(subst /,-,$(FILE)) -f bin/$(FILE)
19+
20+
all: $(EXECUTABLE)
21+
22+
# the executable used to perform the upload, dogfooding and all...
23+
bin/tmp/$(EXECUTABLE):
24+
go build -o "$@"
25+
26+
# arm
27+
bin/linux/arm/5/$(EXECUTABLE):
28+
GOARM=5 GOARCH=arm GOOS=linux go build -o "$@"
29+
bin/linux/arm/7/$(EXECUTABLE):
30+
GOARM=7 GOARCH=arm GOOS=linux go build -o "$@"
31+
32+
# 386
33+
bin/darwin/386/$(EXECUTABLE):
34+
GOARCH=386 GOOS=darwin go build -o "$@"
35+
bin/linux/386/$(EXECUTABLE):
36+
GOARCH=386 GOOS=linux go build -o "$@"
37+
bin/windows/386/$(EXECUTABLE):
38+
GOARCH=386 GOOS=windows go build -o "$@"
39+
40+
# amd64
41+
bin/freebsd/amd64/$(EXECUTABLE):
42+
GOARCH=amd64 GOOS=freebsd go build -o "$@"
43+
bin/darwin/amd64/$(EXECUTABLE):
44+
GOARCH=amd64 GOOS=darwin go build -o "$@"
45+
bin/linux/amd64/$(EXECUTABLE):
46+
GOARCH=amd64 GOOS=linux go build -o "$@"
47+
bin/windows/amd64/$(EXECUTABLE).exe:
48+
GOARCH=amd64 GOOS=windows go build -o "$@"
49+
50+
# compressed artifacts, makes a huge difference (Go executable is ~9MB,
51+
# after compressing ~2MB)
52+
%.bz2: %
53+
bzip2 -c < "$<" > "$@"
54+
%.zip: %.exe
55+
zip "$@" "$<"
56+
57+
# git tag -a v$(RELEASE) -m 'release $(RELEASE)'
58+
release: clean
59+
$(MAKE) bin/tmp/$(EXECUTABLE) $(COMPRESSED_EXECUTABLE_TARGETS)
60+
git push && git push --tags
61+
git log --format=%B $(LAST_TAG) -1 | \
62+
bin/tmp/$(EXECUTABLE) release -u $(USER) -r $(EXECUTABLE) \
63+
-t $(LAST_TAG) -n $(LAST_TAG) -d - || true
64+
$(foreach FILE,$(COMPRESSED_EXECUTABLES),$(UPLOAD_CMD);)
65+
66+
# install and/or update all dependencies, run this from the project directory
67+
# go get -u ./...
68+
# go test -i ./
69+
dep:
70+
go list -f '{{join .Deps "\n"}}' | xargs go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | xargs go get -u
71+
72+
$(EXECUTABLE): dep
73+
go build -o "$@"
74+
75+
install:
76+
go install
77+
78+
clean:
79+
rm go-app || true
80+
rm $(EXECUTABLE) || true
81+
rm -rf bin/
82+
83+
.PHONY: clean release dep install
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
github-release
2+
==============
3+
4+
A small commandline app written in Go that allows you to easily create
5+
and delete releases of your projects on Github. In addition it allows
6+
you to attach files to those releases.
7+
8+
It interacts with the [github releases API](http://developer.github.com/v3/repos/releases).
9+
Though it's entirely possibly to [do all these things with
10+
cURL](https://github.com/blog/1645-releases-api-preview), It's not
11+
really that user-friendly. For example, you need to first query the API
12+
to find the id of the release you want, before you can upload an
13+
artifact. `github-release` takes care of those little details.
14+
15+
It might still be a bit rough around the edges, pull requests are
16+
welcome!
17+
18+
**NOTE**: I've been made aware of the existence of the
19+
[gothub](https://github.com/itchio/gothub) fork. Since I have very little
20+
time to work on the project and have been a really bad maintainer, I suggest
21+
checking it out to see if your issues have been solved there.
22+
23+
How to install
24+
==============
25+
26+
If you don't have the Go toolset installed, and you don't want to, but
27+
still want to use the app, you can download binaries for your platform
28+
on the [releases
29+
page](https://github.com/aktau/github-release/releases/latest). Yes, that's
30+
dogfooding, check the makefile!
31+
32+
If you have Go installed, you can just do:
33+
34+
```sh
35+
go get github.com/aktau/github-release
36+
```
37+
38+
This will automatically download, compile and install the app.
39+
40+
After that you should have a `github-release` executable in your
41+
`$GOPATH/bin`.
42+
43+
How to use
44+
==========
45+
46+
**NOTE**: for these examples I've [created a github
47+
token](https://help.github.com/articles/creating-an-access-token-for-command-line-use)
48+
and set it as the env variable `GITHUB_TOKEN`. `github-release` will
49+
automatically pick it up from the environment so that you don't have to
50+
pass it as an argument.
51+
52+
```sh
53+
# set your token
54+
export GITHUB_TOKEN=...
55+
56+
# check the help
57+
$ github-release --help
58+
59+
# make your tag and upload
60+
$ git tag ... && git push --tags
61+
62+
# check the current tags and existing releases of the repo
63+
$ github-release info -u aktau -r gofinance
64+
git tags:
65+
- v0.1.0 (commit: https://api.github.com/repos/aktau/gofinance/commits/f562727ce83ce8971a8569a1879219e41d56a756)
66+
releases:
67+
- v0.1.0, name: 'hoary ungar', description: 'something something dark side 2', id: 166740, tagged: 29/01/2014 at 14:27, published: 30/01/2014 at 16:20, draft: ✔, prerelease: ✗
68+
- artifact: github.go, downloads: 0, state: uploaded, type: application/octet-stream, size: 1.9KB, id: 68616
69+
70+
# create a formal release
71+
$ github-release release \
72+
--user aktau \
73+
--repo gofinance \
74+
--tag v0.1.0 \
75+
--name "the wolf of source street" \
76+
--description "Not a movie, contrary to popular opinion. Still, my first release!" \
77+
--pre-release
78+
79+
# you've made a mistake, but you can edit the release without
80+
# having to delete it first (this also means you can edit without having
81+
# to upload your files again)
82+
$ github-release edit \
83+
--user aktau \
84+
--repo gofinance \
85+
--tag v0.1.0 \
86+
--name "Highlander II: The Quickening" \
87+
--description "This is the actual description!"
88+
89+
# upload a file, for example the OSX/AMD64 binary of my gofinance app
90+
$ github-release upload \
91+
--user aktau \
92+
--repo gofinance \
93+
--tag v0.1.0 \
94+
--name "gofinance-osx-amd64" \
95+
--file bin/darwin/amd64/gofinance
96+
97+
# upload other files...
98+
$ github-release upload ...
99+
100+
# you're not happy with it, so delete it
101+
$ github-release delete \
102+
--user aktau \
103+
--repo gofinance \
104+
--tag v0.1.0
105+
```
106+
107+
GitHub Enterprise Support
108+
=========================
109+
You can point to a different GitHub API endpoint via the environment variable ```GITHUB_API```:
110+
111+
```
112+
export GITHUB_API=http://github.saobby.my.eu.orgpany.com/api/v3
113+
```
114+
115+
Used libraries
116+
==============
117+
118+
| Package | Description | License |
119+
| ------------------------------------------------------------------------ | ------------------- | ------- |
120+
| [github.com/dustin/go-humanize](https://github.com/dustin/go-humanize) | humanize file sizes | MIT |
121+
| [github.com/tomnomnom/linkheader](https://github.com/tomnomnom/linkheader) | GH API pagination | MIT |
122+
| [github.com/voxelbrain/goptions](https://github.com/voxelbrain/goptions) | option parsing | BSD |
123+
124+
Todo
125+
====
126+
127+
- Check if an artifact is already uploaded before starting a new upload
128+
129+
Copyright
130+
=========
131+
132+
Copyright (c) 2014, Nicolas Hillegeer. All rights reserved.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"time"
7+
8+
"github.com/aktau/github-release/github"
9+
)
10+
11+
const (
12+
// GET /repos/:owner/:repo/releases/assets/:id
13+
// DELETE /repos/:owner/:repo/releases/assets/:id
14+
ASSET_URI = "/repos/%s/%s/releases/assets/%d"
15+
16+
// API: https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
17+
// GET /repos/:owner/:repo/releases/:id/assets
18+
ASSET_RELEASE_LIST_URI = "/repos/%s/%s/releases/%d/assets"
19+
)
20+
21+
type Asset struct {
22+
Url string `json:"url"`
23+
Id int `json:"id"`
24+
Name string `json:"name"`
25+
ContentType string `json:"content_type"`
26+
State string `json:"state"`
27+
Size uint64 `json:"size"`
28+
Downloads uint64 `json:"download_count"`
29+
Created time.Time `json:"created_at"`
30+
Published time.Time `json:"published_at"`
31+
}
32+
33+
// findAsset returns the asset if an asset with name can be found in assets,
34+
// otherwise returns nil.
35+
func findAsset(assets []Asset, name string) *Asset {
36+
for _, asset := range assets {
37+
if asset.Name == name {
38+
return &asset
39+
}
40+
}
41+
return nil
42+
}
43+
44+
// Delete sends a HTTP DELETE request for the given asset to Github. Returns
45+
// nil if the asset was deleted OR there was nothing to delete.
46+
func (a *Asset) Delete(user, repo, token string) error {
47+
URL := nvls(EnvApiEndpoint, github.DefaultBaseURL) +
48+
fmt.Sprintf(ASSET_URI, user, repo, a.Id)
49+
resp, err := github.DoAuthRequest("DELETE", URL, "application/json", token, nil, nil)
50+
if err != nil {
51+
return fmt.Errorf("failed to delete asset %s (ID: %d), HTTP error: %b", a.Name, a.Id, err)
52+
}
53+
defer resp.Body.Close()
54+
if resp.StatusCode != http.StatusNoContent {
55+
return fmt.Errorf("failed to delete asset %s (ID: %d), status: %s", a.Name, a.Id, resp.Status)
56+
}
57+
return nil
58+
}

0 commit comments

Comments
 (0)