Skip to content

Commit

Permalink
Merge pull request #45 from arangodb/releasing
Browse files Browse the repository at this point in the history
Added release code
  • Loading branch information
ewoutp committed Mar 13, 2018
2 parents 6bc3f14 + e50f09b commit bc94a20
Show file tree
Hide file tree
Showing 75 changed files with 4,886 additions and 85 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ update-vendor:
k8s.io/client-go/... \
k8s.io/gengo/args \
k8s.io/apiextensions-apiserver \
github.com/aktau/github-release \
github.com/arangodb-helper/go-certificates \
github.com/arangodb/go-driver \
github.com/cenkalti/backoff \
github.com/coreos/go-semver/semver \
github.com/dchest/uniuri \
github.com/dgrijalva/jwt-go \
github.com/julienschmidt/httprouter \
Expand Down
26 changes: 26 additions & 0 deletions deps/github.com/aktau/github-release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
github-release
go-app
bin/

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
20 changes: 20 additions & 0 deletions deps/github.com/aktau/github-release/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 Nicolas Hillegeer

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
83 changes: 83 additions & 0 deletions deps/github.com/aktau/github-release/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
LAST_TAG := $(shell git describe --abbrev=0 --tags)

USER := aktau
EXECUTABLE := github-release

# only include the amd64 binaries, otherwise the github release will become
# too big
UNIX_EXECUTABLES := \
darwin/amd64/$(EXECUTABLE) \
freebsd/amd64/$(EXECUTABLE) \
linux/amd64/$(EXECUTABLE)
WIN_EXECUTABLES := \
windows/amd64/$(EXECUTABLE).exe

COMPRESSED_EXECUTABLES=$(UNIX_EXECUTABLES:%=%.bz2) $(WIN_EXECUTABLES:%.exe=%.zip)
COMPRESSED_EXECUTABLE_TARGETS=$(COMPRESSED_EXECUTABLES:%=bin/%)

UPLOAD_CMD = bin/tmp/$(EXECUTABLE) upload -u $(USER) -r $(EXECUTABLE) -t $(LAST_TAG) -n $(subst /,-,$(FILE)) -f bin/$(FILE)

all: $(EXECUTABLE)

# the executable used to perform the upload, dogfooding and all...
bin/tmp/$(EXECUTABLE):
go build -o "$@"

# arm
bin/linux/arm/5/$(EXECUTABLE):
GOARM=5 GOARCH=arm GOOS=linux go build -o "$@"
bin/linux/arm/7/$(EXECUTABLE):
GOARM=7 GOARCH=arm GOOS=linux go build -o "$@"

# 386
bin/darwin/386/$(EXECUTABLE):
GOARCH=386 GOOS=darwin go build -o "$@"
bin/linux/386/$(EXECUTABLE):
GOARCH=386 GOOS=linux go build -o "$@"
bin/windows/386/$(EXECUTABLE):
GOARCH=386 GOOS=windows go build -o "$@"

# amd64
bin/freebsd/amd64/$(EXECUTABLE):
GOARCH=amd64 GOOS=freebsd go build -o "$@"
bin/darwin/amd64/$(EXECUTABLE):
GOARCH=amd64 GOOS=darwin go build -o "$@"
bin/linux/amd64/$(EXECUTABLE):
GOARCH=amd64 GOOS=linux go build -o "$@"
bin/windows/amd64/$(EXECUTABLE).exe:
GOARCH=amd64 GOOS=windows go build -o "$@"

# compressed artifacts, makes a huge difference (Go executable is ~9MB,
# after compressing ~2MB)
%.bz2: %
bzip2 -c < "$<" > "$@"
%.zip: %.exe
zip "$@" "$<"

# git tag -a v$(RELEASE) -m 'release $(RELEASE)'
release: clean
$(MAKE) bin/tmp/$(EXECUTABLE) $(COMPRESSED_EXECUTABLE_TARGETS)
git push && git push --tags
git log --format=%B $(LAST_TAG) -1 | \
bin/tmp/$(EXECUTABLE) release -u $(USER) -r $(EXECUTABLE) \
-t $(LAST_TAG) -n $(LAST_TAG) -d - || true
$(foreach FILE,$(COMPRESSED_EXECUTABLES),$(UPLOAD_CMD);)

# install and/or update all dependencies, run this from the project directory
# go get -u ./...
# go test -i ./
dep:
go list -f '{{join .Deps "\n"}}' | xargs go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | xargs go get -u

$(EXECUTABLE): dep
go build -o "$@"

install:
go install

clean:
rm go-app || true
rm $(EXECUTABLE) || true
rm -rf bin/

.PHONY: clean release dep install
132 changes: 132 additions & 0 deletions deps/github.com/aktau/github-release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
github-release
==============

A small commandline app written in Go that allows you to easily create
and delete releases of your projects on Github. In addition it allows
you to attach files to those releases.

It interacts with the [github releases API](http://developer.github.com/v3/repos/releases).
Though it's entirely possibly to [do all these things with
cURL](https://github.com/blog/1645-releases-api-preview), It's not
really that user-friendly. For example, you need to first query the API
to find the id of the release you want, before you can upload an
artifact. `github-release` takes care of those little details.

It might still be a bit rough around the edges, pull requests are
welcome!

**NOTE**: I've been made aware of the existence of the
[gothub](https://github.com/itchio/gothub) fork. Since I have very little
time to work on the project and have been a really bad maintainer, I suggest
checking it out to see if your issues have been solved there.

How to install
==============

If you don't have the Go toolset installed, and you don't want to, but
still want to use the app, you can download binaries for your platform
on the [releases
page](https://github.com/aktau/github-release/releases/latest). Yes, that's
dogfooding, check the makefile!

If you have Go installed, you can just do:

```sh
go get github.com/aktau/github-release
```

This will automatically download, compile and install the app.

After that you should have a `github-release` executable in your
`$GOPATH/bin`.

How to use
==========

**NOTE**: for these examples I've [created a github
token](https://help.github.com/articles/creating-an-access-token-for-command-line-use)
and set it as the env variable `GITHUB_TOKEN`. `github-release` will
automatically pick it up from the environment so that you don't have to
pass it as an argument.

```sh
# set your token
export GITHUB_TOKEN=...

# check the help
$ github-release --help

# make your tag and upload
$ git tag ... && git push --tags

# check the current tags and existing releases of the repo
$ github-release info -u aktau -r gofinance
git tags:
- v0.1.0 (commit: https://api.github.com/repos/aktau/gofinance/commits/f562727ce83ce8971a8569a1879219e41d56a756)
releases:
- 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: ✗
- artifact: github.go, downloads: 0, state: uploaded, type: application/octet-stream, size: 1.9KB, id: 68616

# create a formal release
$ github-release release \
--user aktau \
--repo gofinance \
--tag v0.1.0 \
--name "the wolf of source street" \
--description "Not a movie, contrary to popular opinion. Still, my first release!" \
--pre-release

# you've made a mistake, but you can edit the release without
# having to delete it first (this also means you can edit without having
# to upload your files again)
$ github-release edit \
--user aktau \
--repo gofinance \
--tag v0.1.0 \
--name "Highlander II: The Quickening" \
--description "This is the actual description!"

# upload a file, for example the OSX/AMD64 binary of my gofinance app
$ github-release upload \
--user aktau \
--repo gofinance \
--tag v0.1.0 \
--name "gofinance-osx-amd64" \
--file bin/darwin/amd64/gofinance

# upload other files...
$ github-release upload ...

# you're not happy with it, so delete it
$ github-release delete \
--user aktau \
--repo gofinance \
--tag v0.1.0
```

GitHub Enterprise Support
=========================
You can point to a different GitHub API endpoint via the environment variable ```GITHUB_API```:

```
export GITHUB_API=http://github.saobby.my.eu.orgpany.com/api/v3
```

Used libraries
==============

| Package | Description | License |
| ------------------------------------------------------------------------ | ------------------- | ------- |
| [github.com/dustin/go-humanize](https://github.com/dustin/go-humanize) | humanize file sizes | MIT |
| [github.com/tomnomnom/linkheader](https://github.com/tomnomnom/linkheader) | GH API pagination | MIT |
| [github.com/voxelbrain/goptions](https://github.com/voxelbrain/goptions) | option parsing | BSD |

Todo
====

- Check if an artifact is already uploaded before starting a new upload

Copyright
=========

Copyright (c) 2014, Nicolas Hillegeer. All rights reserved.
58 changes: 58 additions & 0 deletions deps/github.com/aktau/github-release/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"fmt"
"net/http"
"time"

"github.com/aktau/github-release/github"
)

const (
// GET /repos/:owner/:repo/releases/assets/:id
// DELETE /repos/:owner/:repo/releases/assets/:id
ASSET_URI = "/repos/%s/%s/releases/assets/%d"

// API: https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
// GET /repos/:owner/:repo/releases/:id/assets
ASSET_RELEASE_LIST_URI = "/repos/%s/%s/releases/%d/assets"
)

type Asset struct {
Url string `json:"url"`
Id int `json:"id"`
Name string `json:"name"`
ContentType string `json:"content_type"`
State string `json:"state"`
Size uint64 `json:"size"`
Downloads uint64 `json:"download_count"`
Created time.Time `json:"created_at"`
Published time.Time `json:"published_at"`
}

// findAsset returns the asset if an asset with name can be found in assets,
// otherwise returns nil.
func findAsset(assets []Asset, name string) *Asset {
for _, asset := range assets {
if asset.Name == name {
return &asset
}
}
return nil
}

// Delete sends a HTTP DELETE request for the given asset to Github. Returns
// nil if the asset was deleted OR there was nothing to delete.
func (a *Asset) Delete(user, repo, token string) error {
URL := nvls(EnvApiEndpoint, github.DefaultBaseURL) +
fmt.Sprintf(ASSET_URI, user, repo, a.Id)
resp, err := github.DoAuthRequest("DELETE", URL, "application/json", token, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete asset %s (ID: %d), HTTP error: %b", a.Name, a.Id, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("failed to delete asset %s (ID: %d), status: %s", a.Name, a.Id, resp.Status)
}
return nil
}
Loading

0 comments on commit bc94a20

Please sign in to comment.