Skip to content

Commit

Permalink
Add versioning, pushing releases to github (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
maplebed committed May 18, 2019
1 parent d1ef6d3 commit 381b241
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
30 changes: 21 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,46 @@ jobs:
executor: linuxgo
steps:
- checkout
- go test -v ./...
- run: go test -v ./...
build:
executor: linuxgo
steps:
- checkout
- run: go install ./...
- run: mkdir workspace; cp $GOPATH/bin/buildevents workspace/
- run: go install -ldflags "-X main.Version=${CIRCLE_TAG}+${CIRCLE_SHA1}" ./...
- run: mkdir -v artifacts; cp -v $GOPATH/bin/buildevents artifacts/
- persist_to_workspace:
root: workspace
root: artifacts
paths:
- buildevents
publish:
executor: linuxgo
docker:
- image: cibuilds/github:0.12.1
steps:
- attach_workspace:
at: workspace
- # stub for pushing github release
at: artifacts
- run:
name: "Publish Release on GitHub"
command: |
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} ./artifacts/buildevents
workflows:
build:
jobs:
- test
- test:
filters:
tags:
only: /.*/
- build:
requires:
- test
filters:
tags:
only: /.*/
- publish:
requires:
- build
filters:
tags:
only: /^v.*/
branches:
only: master
ignore: /.*/
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/honeycombio/libhoney-go/transmission"
)

// Version will be set by CircleCI based on a git tag and the commit hash
var Version string

// buildevents expects to get some unchanging values from the environment and
// the rest as positional arguments on the command line.
//
Expand Down Expand Up @@ -221,6 +224,17 @@ func main() {
})
}

if Version == "" {
Version = "dev"
}
libhoney.AddField("meta.version", Version)

// respond to ./buildevents --version in order to enable circleci to tag releases
if os.Args[1] == "--version" {
fmt.Println(Version)
os.Exit(0)
}

if len(os.Args) < 4 {
usage()
os.Exit(1)
Expand Down

0 comments on commit 381b241

Please sign in to comment.