Skip to content

Commit 27bf860

Browse files
author
Jonathan Thurman
authored
Merge pull request #98 from newrelic/jthurman/goreleaser
Automated Releases via goreleaser
2 parents 2bdac4b + f1ee6a6 commit 27bf860

File tree

18 files changed

+392
-93
lines changed

18 files changed

+392
-93
lines changed

.circleci/config.yml

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ workflows:
1616
- security-scan:
1717
requires:
1818
- checkout_code
19-
- build:
19+
- compile:
2020
requires:
2121
- lint
2222
- test
2323
- security-scan
24-
- hold-for-deploy:
24+
- hold-for-release:
2525
type: approval
2626
filters:
2727
branches:
2828
ignore: /.*/
2929
tags:
30-
only: /^\d+\.\d+\.\d+$/
30+
only: /^v\d+\.\d+\.\d+$/
3131
require:
32-
- build
33-
- docker-push:
32+
- compile
33+
- release:
3434
filters:
3535
branches:
3636
ignore: /.*/
3737
tags:
38-
only: /^\d+\.\d+\.\d+$/
38+
only: /^v\d+\.\d+\.\d+$/
3939
requires:
40-
- build
41-
- hold-for-deploy
40+
- compile
41+
- hold-for-release
4242

4343
jobs:
4444
checkout_code:
@@ -54,7 +54,7 @@ jobs:
5454

5555
lint:
5656
docker:
57-
- image: circleci/golang:1.13
57+
- image: circleci/golang:1.14
5858
working_directory: /go/src/github.com/newrelic/newrelic-cli
5959
steps:
6060
- restore_cache:
@@ -65,7 +65,7 @@ jobs:
6565

6666
test:
6767
docker:
68-
- image: circleci/golang:1.13
68+
- image: circleci/golang:1.14
6969
working_directory: /go/src/github.com/newrelic/newrelic-cli
7070
steps:
7171
- restore_cache:
@@ -77,35 +77,32 @@ jobs:
7777
name: Integration Tests
7878
command: make test-integration
7979

80-
build:
80+
security-scan:
8181
docker:
82-
- image: circleci/golang:1.13
82+
- image: circleci/golang:1.14
8383
working_directory: /go/src/github.com/newrelic/newrelic-cli
8484
steps:
8585
- restore_cache:
8686
key: repo-{{ .Environment.CIRCLE_SHA1 }}
87-
- run: make build-ci
88-
87+
- snyk/scan:
88+
severity-threshold: high
89+
fail-on-issues: false
90+
monitor-on-build: true
8991

90-
security-scan:
92+
compile:
9193
docker:
92-
- image: circleci/golang:1.13
94+
- image: circleci/golang:1.14
9395
working_directory: /go/src/github.com/newrelic/newrelic-cli
9496
steps:
9597
- restore_cache:
9698
key: repo-{{ .Environment.CIRCLE_SHA1 }}
97-
- snyk/scan:
98-
severity-threshold: high
99-
fail-on-issues: false
100-
monitor-on-build: true
99+
- run: make compile-only
101100

102-
docker-push:
101+
release:
103102
docker:
104-
- image: circleci/golang:1.13
103+
- image: circleci/golang:1.14
105104
working_directory: /go/src/github.com/newrelic/newrelic-cli
106105
steps:
107106
- checkout
108-
- run:
109-
name: Push Docker Container
110-
command: make docker-push
107+
- run: make release-publish
111108

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
tmp/*
21
bin/*
32
coverage/*
3+
dist/*
4+
tmp/*
45
vendor/*
56

67
.vscode/

.goreleaser.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
project_name: newrelic-cli
2+
3+
env:
4+
- GO111MODULE=on
5+
6+
before:
7+
hooks:
8+
- make clean
9+
- go mod download
10+
11+
builds:
12+
-
13+
id: newrelic
14+
dir: cmd/newrelic
15+
binary: newrelic
16+
env:
17+
- CGO_ENABLED=0
18+
goos:
19+
- linux
20+
- darwin
21+
- windows
22+
goarch:
23+
- amd64
24+
ldflags:
25+
- -s -w -X main.version={{.Version}} -X main.AppName={{.Binary}}
26+
-X github.com/newrelic/newrelic-cli/internal/client.version={{.Version}}
27+
28+
release:
29+
# Mark as a pre-release for now
30+
prerelease: true
31+
name_template: "{{.ProjectName}} v{{.Version}}"
32+
33+
archives:
34+
-
35+
id: "default"
36+
builds:
37+
- newrelic
38+
replacements:
39+
darwin: Darwin
40+
linux: Linux
41+
windows: Windows
42+
386: i386
43+
amd64: x86_64
44+
format_overrides:
45+
- goos: windows
46+
format: zip
47+
files:
48+
- CHANGELOG.md
49+
- LICENSE
50+
- README.md
51+
52+
dockers:
53+
-
54+
image_templates:
55+
- 'newrelic/cli:{{ .Tag }}'
56+
- 'newrelic/cli:v{{ .Major }}.{{ .Minor }}'
57+
- 'newrelic/cli:latest'
58+
dockerfile: Dockerfile
59+
binaries:
60+
- newrelic
61+
build_flag_templates:
62+
- "--pull"
63+
- "--label=repository=http://github.com/newrelic/newrelic-cli"
64+
- "--label=homepage=https://developer.newrelic.com/"
65+
- "--label=maintainer=Developer Toolkit <opensource@newrelic.com>"
66+
67+
# Already using git-chglog
68+
changelog:
69+
skip: true

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine:3.11
22

33
# Add the binary
4-
COPY ./bin/linux/newrelic /bin
4+
COPY newrelic /bin/newrelic
55

66
ENTRYPOINT ["/bin/newrelic"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ build: check-version clean lint test cover-report compile
2121
build-ci: check-version clean lint test compile-only
2222

2323
# All clean commands
24-
clean: clean-cover clean-compile
24+
clean: cover-clean compile-clean release-clean
2525

2626
# Import fragments
2727
include build/compile.mk

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ $ docker pull newrelic/cli
5959
# Run the container interactively, remove it once the command exists
6060
# Also must pass $NEW_RELIC_API_KEY to the container
6161
$ docker run -it --rm \
62-
-e NEW_RELIC_API_KEY="$NEW_RELIC_API_KEY" \
62+
-e NEW_RELIC_API_KEY \
6363
newrelic/cli \
6464
apm application get --name WebPortal --accountId 2508259
6565

build/compile.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
GO ?= go
66
BUILD_DIR ?= ./bin/
7-
LDFLAGS ?= "-s -w -X main.Version=$(PROJECT_VER) -X main.AppName=$$b" # $b replaced by the binary name in the compile loop, -s/w remove debug symbols
7+
# $b replaced by the binary name in the compile loop, -s/w remove debug symbols
8+
LDFLAGS ?= "-s -w -X main.version=$(PROJECT_VER) -X main.appName=$$b -X github.com/newrelic/newrelic-cli/internal/client.version=$(PROJECT_VER)"
89
SRCDIR ?= .
910
COMPILE_OS ?= darwin linux windows
1011

@@ -15,8 +16,8 @@ COMMANDS ?= $(wildcard ${SRCDIR}/cmd/*)
1516
BINS := $(foreach cmd,${COMMANDS},$(notdir ${cmd}))
1617

1718

18-
clean-compile:
19-
@echo "=== $(PROJECT_NAME) === [ clean-compile ]: removing binaries..."
19+
compile-clean:
20+
@echo "=== $(PROJECT_NAME) === [ compile-clean ]: removing binaries..."
2021
@rm -rfv $(BUILD_DIR)/*
2122

2223
compile: deps compile-only

build/release.mk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
RELEASE_SCRIPT ?= ./tools/release.sh
22

3+
GOTOOLS += github.com/goreleaser/goreleaser
4+
5+
REL_CMD ?= goreleaser
6+
DIST_DIR ?= ./dist
7+
38
# Example usage: make release version=0.11.0
49
release:
510
@echo "=== $(PROJECT_NAME) === [ release ]: Generating release."
611
$(RELEASE_SCRIPT) $(version)
12+
13+
release-clean:
14+
@echo "=== $(PROJECT_NAME) === [ release-clean ]: distribution files..."
15+
@rm -rfv $(DIST_DIR)/*
16+
17+
release-publish: clean tools docker-login
18+
@echo "=== $(PROJECT_NAME) === [ release-publish ]: Publishing release via $(REL_CMD)"
19+
$(REL_CMD)
20+
21+
.PHONY: release release-clean release-publish

build/test.mk

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@ SRCDIR ?= .
1313
GO_PKGS ?= $(shell ${GO} list ./... | grep -v -e "/vendor/" -e "/example")
1414
FILES ?= $(shell find ${SRCDIR} -type f | grep -v -e '.git/' -e '/vendor/')
1515

16-
LDFLAGS_UNIT ?= '-X github.com/newrelic/newrelic-cli/internal/version.GitTag=$(PROJECT_VER_TAGGED)'
17-
1816
GOTOOLS += github.com/stretchr/testify/assert
1917

20-
clean-cover:
21-
@echo "=== $(PROJECT_NAME) === [ clean-cover ]: removing coverage files..."
22-
@rm -rfv $(COVERAGE_DIR)/*
23-
2418
test: test-only
2519
test-only: test-unit test-integration
2620

2721
test-unit:
2822
@echo "=== $(PROJECT_NAME) === [ test-unit ]: running unit tests..."
2923
@mkdir -p $(COVERAGE_DIR)
30-
@$(GO) test -v -ldflags=$(LDFLAGS_UNIT) -parallel 4 -tags unit -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/unit.tmp $(GO_PKGS)
24+
@$(GO) test -v -ldflags=$(LDFLAGS) -parallel 4 -tags unit -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/unit.tmp $(GO_PKGS)
3125

3226
test-integration:
3327
@echo "=== $(PROJECT_NAME) === [ test-integration ]: running integration tests..."
3428
@mkdir -p $(COVERAGE_DIR)
3529
@$(GO) test -v -parallel 4 -tags integration -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/integration.tmp $(GO_PKGS)
3630

31+
32+
#
33+
# Coverage
34+
#
35+
cover-clean:
36+
@echo "=== $(PROJECT_NAME) === [ cover-clean ]: removing coverage files..."
37+
@rm -rfv $(COVERAGE_DIR)/*
38+
3739
cover-report:
3840
@echo "=== $(PROJECT_NAME) === [ cover-report ]: generating coverage results..."
3941
@mkdir -p $(COVERAGE_DIR)

cmd/newrelic/command.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/newrelic/newrelic-cli/internal/version"
87
log "github.com/sirupsen/logrus"
98
"github.com/spf13/cobra"
109
)
@@ -75,18 +74,15 @@ var versionCmd = &cobra.Command{
7574
`,
7675
Example: "newrelic version",
7776
Run: func(cmd *cobra.Command, args []string) {
78-
fmt.Printf("newrelic version %s\n", version.Version)
77+
fmt.Printf("newrelic version %s\n", version)
7978
},
8079
}
8180

8281
// Execute adds all child commands to the root command and sets flags appropriately.
8382
// This is called by main.main(). It only needs to happen once to the RootCmd.
84-
func Execute(appName string) error {
85-
if appName != "" {
86-
Command.Use = appName
87-
}
88-
89-
Command.Version = version.Version
83+
func Execute() error {
84+
Command.Use = appName
85+
Command.Version = version
9086

9187
return Command.Execute()
9288
}

0 commit comments

Comments
 (0)