Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ jobs:
- run:
name: Code Quality
command: make lint
- run:
name: Release
command: |
export GOVERSION=$(go version | awk '{sub("^go","",$3);print $3;}')
scripts/goreleaser --rm-dist --skip-publish ${CIRCLE_TAG:-"--snapshot"}
rm -rf $(find ./dist/* -type d) || true
- store_test_results:
path: test-results/
- store_artifacts:
path: test-results/
- store_artifacts:
path: /go/bin/vault-plugin-splunk
path: dist/

- save_cache:
name: Saving Cache for vendor
Expand All @@ -63,10 +69,8 @@ jobs:
- /tmp/go/cache

- persist_to_workspace:
root: /go/bin
# Must be relative path from root
paths:
- vault-plugin-splunk
root: dist/
paths: .

publish-github-release:
docker:
Expand All @@ -78,9 +82,8 @@ jobs:
name: "Publish Release on GitHub"
command: |
go get github.com/tcnksm/ghr
VERSION=$(artifacts/vault-plugin-splunk -version | awk '{print $1}')
zip -jr vault-plugin-splunk artifacts/
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -recreate ${VERSION} ./vault-plugin-splunk.zip
VERSION=$(echo artifacts/vault-plugin-splunk_*_*.zip | awk -F_ '{print $2;exit;}')
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -recreate ${VERSION} ./artifacts/

workflows:
version: 2
Expand Down
33 changes: 33 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
before:
# hooks:
# # you may remove this if you don't use vgo
# - go mod download
builds:
- main: cmd/vault-plugin-splunk/main.go
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.goVersion={{.Env.GOVERSION}}
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
archives:
- replacements:
386: i386
format: zip
format_overrides:
- goos: linux
format: tar.bz2
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}_{{.Arch}}"
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{.Version}}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
VERSION := $(shell git describe --tags --always 2>/dev/null)
SHORT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
GO_VERSION := $(shell go version | awk '{ print $$3}' | sed 's/^go//')

TESTREPORT := test-results.xml

# XXX BUG(mweber) "go env GOBIN" is empty?
GOBIN := $(shell go env GOPATH)/bin

LD_FLAGS_PKG ?= main
LD_FLAGS :=
LD_FLAGS += -X "$(LD_FLAGS_PKG).version=$(VERSION)"
LD_FLAGS += -X "$(LD_FLAGS_PKG).commit=$(SHORT_COMMIT)"
LD_FLAGS += -X "$(LD_FLAGS_PKG).goVersion=$(GO_VERSION)"

.PHONY: all
all: build lint test

Expand All @@ -22,7 +12,7 @@ dep: prereq

.PHONY: build
build: dep vault.hcl
go install -ldflags '$(LD_FLAGS)' ./...
go install ./...

vault.hcl: vault.hcl.in
sed -e 's;@@GOBIN@@;$(GOBIN);g' < $< > $@
Expand Down Expand Up @@ -60,4 +50,4 @@ prereq:
.PHONY: clean
clean:
# XXX clean
rm -rf vault.hcl $(TESTREPORT) vendor/
rm -rf vault.hcl $(TESTREPORT) vendor/ dist/
17 changes: 14 additions & 3 deletions cmd/vault-plugin-splunk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import (
splunk "github.com/splunk/vault-plugin-splunk"
)

// nolint: gochecknoglobals
var (
version string
goVersion string
version = "dev"
commit = ""
date = ""
goVersion = ""
)

func main() {
Expand All @@ -25,9 +28,17 @@ func main() {
// #nosec G104
flags.Parse(os.Args[1:])

printField := func(field, value string) {
if field != "" && value != "" {
fmt.Printf("%s: %s\n", field, value)
}
}
switch {
case *printVersion:
fmt.Printf("%s (golang %s)\n", version, goVersion)
printField("version", version)
printField("commit", commit)
printField("date", date)
printField("go", goVersion)
os.Exit(0)
}

Expand Down
28 changes: 28 additions & 0 deletions scripts/goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
set -e

TAR_FILE="/tmp/goreleaser.tar.gz"
RELEASES_URL="https://github.com/goreleaser/goreleaser/releases"
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"

last_version() {
curl -sL -o /dev/null -w %{url_effective} "$RELEASES_URL/latest" |
rev |
cut -f1 -d'/'|
rev
}

download() {
test -z "$VERSION" && VERSION="$(last_version)"
test -z "$VERSION" && {
echo "Unable to get goreleaser version." >&2
exit 1
}
rm -f "$TAR_FILE"
curl -s -L -o "$TAR_FILE" \
"$RELEASES_URL/download/$VERSION/goreleaser_$(uname -s)_$(uname -m).tar.gz"
}

download
tar -xf "$TAR_FILE" -C "$TMPDIR"
"${TMPDIR}/goreleaser" "$@"