From 14d270806c421a9bb65e9b50e354c0d76f8b425f Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Mon, 24 Jan 2022 17:00:08 +0100 Subject: [PATCH 1/7] add install task to Makefile go install builds the executable and move it to GOBIN. This is useful for installing the tool but can become troublesome during development. Having go install performed in the build task is confusing, as running make build would create a "system wide" binary (as most devs have GOBIN in their PATH). To overcome this go install is moved to a dedicated make task: install. --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 55cc4bd1aa..7b48af61c6 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,11 @@ clean: format: go run golang.org/x/tools/cmd/goimports -local github.com/elastic/elastic-package/ -w . +install: + go install -ldflags \ + "-X $(VERSION_IMPORT_PATH).CommitHash=`git describe --always --long --dirty` -X $(VERSION_IMPORT_PATH).BuildTime=`date +%s` -X $(VERSION_IMPORT_PATH).Tag=`(git describe --exact-match --tags 2>/dev/null || echo '') | tr -d '\n'`" \ + github.com/elastic/elastic-package + lint: go run honnef.co/go/tools/cmd/staticcheck ./... From 45474b53c910fb45f5f93fbed1d81320d2b4cec4 Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Mon, 24 Jan 2022 17:18:12 +0100 Subject: [PATCH 2/7] change build task to only build binary --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7b48af61c6..23e5837e69 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ VERSION_IMPORT_PATH = github.com/elastic/elastic-package/internal/version .PHONY: build build: - go install -ldflags \ + go build -ldflags \ "-X $(VERSION_IMPORT_PATH).CommitHash=`git describe --always --long --dirty` -X $(VERSION_IMPORT_PATH).BuildTime=`date +%s` -X $(VERSION_IMPORT_PATH).Tag=`(git describe --exact-match --tags 2>/dev/null || echo '') | tr -d '\n'`" \ - github.com/elastic/elastic-package + -o elastic-package clean: rm -rf build From aae600e0f6694c153871459d4168f7e5f0050222 Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Mon, 24 Jan 2022 18:23:11 +0100 Subject: [PATCH 3/7] use make install in test step --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index a927bf3189..4a85c06c41 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -204,7 +204,7 @@ def generateTestCommandStage(Map args = [:]){ withMageEnv(){ withKubernetes() { withCloudTestEnv() { - sh(label: 'Check',script: "make build ${command} check-git-clean") + sh(label: 'Check',script: "make install ${command} check-git-clean") } } } From 96a36915790387487a34dbf2fd50f9addfd581a8 Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Tue, 25 Jan 2022 10:36:56 +0100 Subject: [PATCH 4/7] add make install to README --- README.md | 4 +++- tools/readme/readme.md.tmpl | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4080873def..7bc4f62408 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,8 @@ source code: `make format` - format the Go code +`make install` - build the tool source and move binary to `$GOBIN` + `make vendor` - vendor code of dependencies `make check` - one-liner, used by CI to verify if source code is ready to be pushed to the repository @@ -297,4 +299,4 @@ git push upstream v0.15.0 ``` The CI will run a new job for the just pushed tag and publish released artifacts. Please expect an automated follow-up PR -in the [Integrations](https://github.com/elastic/integrations) repository to bump up the version ([sample PR](https://github.com/elastic/integrations/pull/1516)). \ No newline at end of file +in the [Integrations](https://github.com/elastic/integrations) repository to bump up the version ([sample PR](https://github.com/elastic/integrations/pull/1516)). diff --git a/tools/readme/readme.md.tmpl b/tools/readme/readme.md.tmpl index 72a6109933..d6ef21cff1 100644 --- a/tools/readme/readme.md.tmpl +++ b/tools/readme/readme.md.tmpl @@ -99,6 +99,8 @@ source code: `make format` - format the Go code +`make install` - build the tool source and move binary to `$GOBIN` + `make vendor` - vendor code of dependencies `make check` - one-liner, used by CI to verify if source code is ready to be pushed to the repository @@ -131,4 +133,4 @@ git push upstream v0.15.0 ``` The CI will run a new job for the just pushed tag and publish released artifacts. Please expect an automated follow-up PR -in the [Integrations](https://github.com/elastic/integrations) repository to bump up the version ([sample PR](https://github.com/elastic/integrations/pull/1516)). \ No newline at end of file +in the [Integrations](https://github.com/elastic/integrations) repository to bump up the version ([sample PR](https://github.com/elastic/integrations/pull/1516)). From 60ed6bd5a7ab23000a65ab20b3cd74a40e830bbf Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Tue, 25 Jan 2022 10:41:39 +0100 Subject: [PATCH 5/7] fixup! use make install in test step --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 4a85c06c41..456153f915 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -161,7 +161,7 @@ def generateTestCheckSinglePackageStage(Map args = [:]) { dir("${BASE_DIR}"){ withMageEnv(){ withCloudTestEnv() { - sh(label: 'Build elastic-package',script: "make build") + sh(label: 'Install elastic-package',script: "make install") sh(label: 'Build elastic-package',script: "make PACKAGE_UNDER_TEST=${it} test-check-packages-parallel") } } From 8182d2f5e5b70b1a1c9b7611187a72a615fdd588 Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Tue, 25 Jan 2022 10:52:44 +0100 Subject: [PATCH 6/7] extract version ldflags in Makefile --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 23e5837e69..6fd7b16d4d 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,16 @@ CODE_COVERAGE_REPORT_FOLDER = $(PWD)/build/test-coverage CODE_COVERAGE_REPORT_NAME_UNIT = $(CODE_COVERAGE_REPORT_FOLDER)/coverage-unit-report VERSION_IMPORT_PATH = github.com/elastic/elastic-package/internal/version +VERSION_COMMIT_HASH = `git describe --always --long --dirty` +VERSION_BUILD_TIME = `date +%s` +VERSION_TAG = `(git describe --exact-match --tags 2>/dev/null || echo '') | tr -d '\n'` +VERSION_LDFLAGS = -X $(VERSION_IMPORT_PATH).CommitHash=$(VERSION_COMMIT_HASH) -X $(VERSION_IMPORT_PATH).BuildTime=$(VERSION_BUILD_TIME) -X $(VERSION_IMPORT_PATH).Tag=$(VERSION_TAG) .PHONY: build build: - go build -ldflags \ - "-X $(VERSION_IMPORT_PATH).CommitHash=`git describe --always --long --dirty` -X $(VERSION_IMPORT_PATH).BuildTime=`date +%s` -X $(VERSION_IMPORT_PATH).Tag=`(git describe --exact-match --tags 2>/dev/null || echo '') | tr -d '\n'`" \ + go build \ + -ldflags "$(VERSION_LDFLAGS)" \ -o elastic-package clean: @@ -16,8 +20,8 @@ format: go run golang.org/x/tools/cmd/goimports -local github.com/elastic/elastic-package/ -w . install: - go install -ldflags \ - "-X $(VERSION_IMPORT_PATH).CommitHash=`git describe --always --long --dirty` -X $(VERSION_IMPORT_PATH).BuildTime=`date +%s` -X $(VERSION_IMPORT_PATH).Tag=`(git describe --exact-match --tags 2>/dev/null || echo '') | tr -d '\n'`" \ + go install \ + -ldflags "$(VERSION_LDFLAGS)" \ github.com/elastic/elastic-package lint: From 5af928c528296a79007bb13cda3f094147a40148 Mon Sep 17 00:00:00 2001 From: endorama <526307+endorama@users.noreply.github.com> Date: Thu, 27 Jan 2022 16:24:06 +0100 Subject: [PATCH 7/7] move commands to single line --- Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 6fd7b16d4d..10341a52c0 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,7 @@ VERSION_LDFLAGS = -X $(VERSION_IMPORT_PATH).CommitHash=$(VERSION_COMMIT_HASH) -X .PHONY: build build: - go build \ - -ldflags "$(VERSION_LDFLAGS)" \ - -o elastic-package + go build -ldflags "$(VERSION_LDFLAGS)" -o elastic-package clean: rm -rf build @@ -20,9 +18,7 @@ format: go run golang.org/x/tools/cmd/goimports -local github.com/elastic/elastic-package/ -w . install: - go install \ - -ldflags "$(VERSION_LDFLAGS)" \ - github.com/elastic/elastic-package + go install -ldflags "$(VERSION_LDFLAGS)" github.com/elastic/elastic-package lint: go run honnef.co/go/tools/cmd/staticcheck ./...