From 313727626d17f100550178629a26dbbdceefec69 Mon Sep 17 00:00:00 2001 From: Jeremias Weber Date: Thu, 30 Mar 2023 14:19:36 +0200 Subject: [PATCH] #207 Update makefiles --- Makefile | 2 +- build/make/bower.mk | 6 +- build/make/build.mk | 9 +- build/make/clean.mk | 7 +- build/make/dependencies-glide.mk | 24 ----- build/make/dependencies-godep.mk | 10 -- build/make/dependencies-gomod.mk | 4 +- build/make/deploy-debian.mk | 21 ++--- build/make/digital-signature.mk | 11 ++- build/make/info.mk | 8 -- build/make/package-debian.mk | 6 +- build/make/package-tar.mk | 4 +- build/make/release.mk | 9 +- build/make/release.sh | 156 ++++++++----------------------- build/make/self-update.mk | 4 +- build/make/static-analysis.mk | 19 ++-- build/make/test-common.mk | 9 +- build/make/test-integration.mk | 19 ++-- build/make/test-unit.mk | 8 +- build/make/variables.mk | 42 ++++++++- build/make/yarn.mk | 6 +- 21 files changed, 167 insertions(+), 217 deletions(-) delete mode 100644 build/make/dependencies-glide.mk delete mode 100644 build/make/dependencies-godep.mk delete mode 100644 build/make/info.mk diff --git a/Makefile b/Makefile index 2b1dd28d..b7120bf0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -MAKEFILES_VERSION=4.3.1 +MAKEFILES_VERSION=7.5.0 .DEFAULT_GOAL:=dogu-release diff --git a/build/make/bower.mk b/build/make/bower.mk index 1289b702..a2c76a97 100644 --- a/build/make/bower.mk +++ b/build/make/bower.mk @@ -1,7 +1,9 @@ +##@ Bower dependency management + BOWER_JSON=$(WORKDIR)/bower.json .PHONY: bower-install -bower-install: $(BOWER_TARGET) +bower-install: $(BOWER_TARGET) ## Execute yarn run bower (in Docker) ifeq ($(ENVIRONMENT), ci) @@ -19,7 +21,7 @@ $(BOWER_TARGET): $(BOWER_JSON) $(PASSWD) $(YARN_TARGET) -v $(PASSWD):/etc/passwd:ro \ -v $(WORKDIR):$(WORKDIR) \ -w $(WORKDIR) \ - node:8 \ + node:$(NODE_VERSION) \ yarn run bower @touch $@ diff --git a/build/make/build.mk b/build/make/build.mk index 4066aa09..b102149b 100644 --- a/build/make/build.mk +++ b/build/make/build.mk @@ -1,3 +1,5 @@ +##@ Compiling go software + ADDITIONAL_LDFLAGS?=-extldflags -static LDFLAGS?=-ldflags "$(ADDITIONAL_LDFLAGS) -X main.Version=$(VERSION) -X main.CommitID=$(COMMIT_ID)" GOIMAGE?=golang @@ -7,11 +9,12 @@ GOARCH?=amd64 PRE_COMPILE?= GO_ENV_VARS?= CUSTOM_GO_MOUNT?=-v /tmp:/tmp +GO_BUILD_FLAGS?=-mod=vendor -a -tags netgo $(LDFLAGS) -installsuffix cgo -o $(BINARY) .PHONY: compile -compile: $(BINARY) +compile: $(BINARY) ## Compile the go program via Docker -compile-ci: +compile-ci: ## Compile the go program without Docker @echo "Compiling (CI)..." make compile-generic @@ -19,7 +22,7 @@ compile-generic: @echo "Compiling..." # here is go called without mod capabilities because of error "go: error loading module requirements" # see https://github.com/golang/go/issues/30868#issuecomment-474199640 - @$(GO_ENV_VARS) go build -mod=vendor -a -tags netgo $(LDFLAGS) -installsuffix cgo -o $(BINARY) + @$(GO_ENV_VARS) go build $(GO_BUILD_FLAGS) ifeq ($(ENVIRONMENT), ci) diff --git a/build/make/clean.mk b/build/make/clean.mk index 4f11678d..119387f7 100644 --- a/build/make/clean.mk +++ b/build/make/clean.mk @@ -1,10 +1,13 @@ +##@ Cleaning + .PHONY: clean -clean: $(ADDITIONAL_CLEAN) +clean: $(ADDITIONAL_CLEAN) ## Remove target and tmp directories rm -rf ${TARGET_DIR} rm -rf ${TMP_DIR} + rm -rf ${UTILITY_BIN_PATH} .PHONY: dist-clean -dist-clean: clean +dist-clean: clean ## Remove all generated directories rm -rf node_modules rm -rf public/vendor rm -rf vendor diff --git a/build/make/dependencies-glide.mk b/build/make/dependencies-glide.mk deleted file mode 100644 index 87eb43fb..00000000 --- a/build/make/dependencies-glide.mk +++ /dev/null @@ -1,24 +0,0 @@ -GLIDE=$(GOPATH)/bin/glide -GLIDEFLAGS= -GLIDEHOME=$(GLIDE_HOME) - -ifeq ($(ENVIRONMENT), ci) - GLIDEFLAGS+=--no-color - GLIDEHOME=$(WORKDIR)/.glide_home - GLIDEFLAGS+= --home $(GLIDEHOME) -endif - -.PHONY: update-dependencies -update-dependencies: $(GLIDE) - -.PHONY: dependencies -dependencies: vendor - -vendor: $(GLIDE) glide.yaml glide.lock - @echo "Installing dependencies using Glide..." - $(GLIDE) $(GLIDEFLAGS) install -v - -$(GLIDE): - @echo "installing glide" - @curl https://glide.sh/get | sh - diff --git a/build/make/dependencies-godep.mk b/build/make/dependencies-godep.mk deleted file mode 100644 index 455a69d3..00000000 --- a/build/make/dependencies-godep.mk +++ /dev/null @@ -1,10 +0,0 @@ -GODEP=$(GOPATH)/bin/dep - -$(GODEP): - @curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - -vendor: $(GODEP) Gopkg.toml Gopkg.lock - @echo "Installing dependencies using go dep..." - @dep ensure - -dependencies: vendor diff --git a/build/make/dependencies-gomod.mk b/build/make/dependencies-gomod.mk index 1a71d6d7..3b3b9899 100644 --- a/build/make/dependencies-gomod.mk +++ b/build/make/dependencies-gomod.mk @@ -1,5 +1,7 @@ +##@ Go mod dependency management + .PHONY: dependencies -dependencies: vendor +dependencies: vendor ## Install dependencies using go mod vendor: go.mod go.sum @echo "Installing dependencies using go modules..." diff --git a/build/make/deploy-debian.mk b/build/make/deploy-debian.mk index 8427cd90..89b0fbe8 100644 --- a/build/make/deploy-debian.mk +++ b/build/make/deploy-debian.mk @@ -1,3 +1,5 @@ +##@ Debian package deployment + # This Makefile holds all targets for deploying and undeploying # Uses the variable APT_REPO to determine which apt repos should be used to deploy @@ -21,11 +23,8 @@ ifeq ($(APT_REPO), ces-premium) @echo "... add package to ces-premium repository" @$(APTLY) -X POST "${APT_API_BASE_URL}/repos/ces-premium/file/$$(basename ${DEBIAN_PACKAGE})" else - @echo "... add package to ces and xenial repositories" - # heads up: For migration to a new repo structure we use two repos, new (ces) and old (xenial) - # '?noRemove=1': aptly removes the file on success. This leads to an error on the second package add. Keep it this round - @$(APTLY) -X POST "${APT_API_BASE_URL}/repos/ces/file/$$(basename ${DEBIAN_PACKAGE})?noRemove=1" - @$(APTLY) -X POST "${APT_API_BASE_URL}/repos/xenial/file/$$(basename ${DEBIAN_PACKAGE})" + @echo "\n... add package to ces repository" + @$(APTLY) -X POST "${APT_API_BASE_URL}/repos/ces/file/$$(basename ${DEBIAN_PACKAGE})" endif define aptly_publish @@ -34,17 +33,16 @@ endef .PHONY: publish publish: - @echo "... publish packages" + @echo "\n... publish packages" ifeq ($(APT_REPO), ces-premium) @$(call aptly_publish,ces-premium,bionic) else - @$(call aptly_publish,xenial,xenial) - @$(call aptly_publish,ces,xenial) + @$(call aptly_publish,ces,focal) @$(call aptly_publish,ces,bionic) endif .PHONY: deploy -deploy: add-package-to-repo publish +deploy: add-package-to-repo publish ## Deploy package to apt repository define aptly_undeploy PREF=$$(${APTLY} "${APT_API_BASE_URL}/repos/$(1)/packages?q=${ARTIFACT_ID}%20(${VERSION})"); \ @@ -56,13 +54,12 @@ remove-package-from-repo: ifeq ($(APT_REPO), ces-premium) @$(call aptly_undeploy,ces-premium) else - @$(call aptly_undeploy,xenial) @$(call aptly_undeploy,ces) endif .PHONY: undeploy -undeploy: deploy-check remove-package-from-repo publish +undeploy: deploy-check remove-package-from-repo publish ## Undeploy package from apt repository .PHONE: lint-deb-package -lint-deb-package: debian +lint-deb-package: debian ## Lint debian package @lintian -i $(DEBIAN_PACKAGE) diff --git a/build/make/digital-signature.mk b/build/make/digital-signature.mk index dd005fd3..c0eba357 100644 --- a/build/make/digital-signature.mk +++ b/build/make/digital-signature.mk @@ -1,7 +1,9 @@ +##@ Digital signatures + CHECKSUM=$(TARGET_DIR)/$(ARTIFACT_ID).sha256sum .PHONY: checksum -checksum: $(CHECKSUM) +checksum: $(CHECKSUM) ## Generate checksums # we have to depend on target dir, because we want to rebuild the checksum # if one of the artefacts was changed $(CHECKSUM): $(TARGET_DIR) @@ -11,7 +13,12 @@ $(CHECKSUM): $(TARGET_DIR) SIGNATURE=$(CHECKSUM).asc .PHONY: signature -signature: $(SIGNATURE) +signature: $(SIGNATURE) ## Generate signature $(SIGNATURE): $(CHECKSUM) @echo "Generating Signature" @gpg --batch --yes --detach-sign --armor -o $@ $< + +.PHONY: signature-ci +signature-ci: $(CHECKSUM) + @echo "Generating Signature" + @gpg2 --batch --pinentry-mode loopback --passphrase="${passphrase}" --yes --detach-sign --armor -o ${SIGNATURE} $< diff --git a/build/make/info.mk b/build/make/info.mk deleted file mode 100644 index e402a375..00000000 --- a/build/make/info.mk +++ /dev/null @@ -1,8 +0,0 @@ -.PHONY: info -info: - @echo "dumping build information ..." - @echo "Version : $(VERSION)" - @echo "Commit-ID : $(COMMIT_ID)" - @echo "Environment: $(ENVIRONMENT)" - @echo "Branch : $(BRANCH)" - @echo "Packages : $(PACKAGES)" diff --git a/build/make/package-debian.mk b/build/make/package-debian.mk index 168e8e22..ad55ea1b 100644 --- a/build/make/package-debian.mk +++ b/build/make/package-debian.mk @@ -1,3 +1,5 @@ +##@ Debian packaging + # This Makefile holds all targets for building a debian package # For deployment of the deb package include the deploy-debian.mk! @@ -8,10 +10,10 @@ CONFFILES_FILE_TMP="$(DEBIAN_CONTENT_DIR)/conffiles_" DEBSRC:=$(shell find "${WORKDIR}/deb" -type f) .PHONY: package -package: debian-with-binary +package: debian-with-binary ## Build binary and package into .deb file .PHONY: debian -debian: $(DEBIAN_PACKAGE) +debian: $(DEBIAN_PACKAGE) ## Create .deb package without building the binary before .PHONY: debian-with-binary debian-with-binary: $(BINARY) $(DEBIAN_PACKAGE) diff --git a/build/make/package-tar.mk b/build/make/package-tar.mk index 307212f6..9b842a3e 100644 --- a/build/make/package-tar.mk +++ b/build/make/package-tar.mk @@ -1,7 +1,9 @@ +##@ Tar packaging + TAR_PACKAGE:=$(ARTIFACT_ID)-$(VERSION).tar.gz .PHONY: package -package: $(TAR_PACKAGE) +package: $(TAR_PACKAGE) ## Build binary and create tar package from it $(TAR_PACKAGE): $(BINARY) # Check owner and group id diff --git a/build/make/release.mk b/build/make/release.mk index d8a58921..11dde9a8 100644 --- a/build/make/release.mk +++ b/build/make/release.mk @@ -1,6 +1,11 @@ +##@ Releases + # This makefile holds the dogu-release target for starting a new dogu release .PHONY: dogu-release -dogu-release: - build/make/release.sh +dogu-release: ## Start a dogu release + build/make/release.sh dogu +.PHONY: go-release +go-release: ## Start a go tool release + build/make/release.sh go-tool \ No newline at end of file diff --git a/build/make/release.sh b/build/make/release.sh index 2d64cdd1..4fd45698 100755 --- a/build/make/release.sh +++ b/build/make/release.sh @@ -3,132 +3,52 @@ set -o errexit set -o nounset set -o pipefail -wait_for_ok(){ - printf "\n" - OK=false - while [[ ${OK} != "ok" ]] ; do - read -r -p "${1} (type 'ok'): " OK - done -} - -ask_yes_or_no(){ - local ANSWER="" - - while [ "${ANSWER}" != "y" ] && [ "${ANSWER}" != "n" ]; do - read -r -p "${1} (type 'y/n'): " ANSWER - done - - echo "${ANSWER}" -} - -# dogu.json will always exist. So get current dogu version from dogu.json. -CURRENT_DOGU_VERSION=$(jq ".Version" --raw-output dogu.json) - -# Enter the target version -read -r -p "Current Version is v${CURRENT_DOGU_VERSION}. Please provide the new version: v" NEW_RELEASE_VERSION - -# Validate that release version does not start with vv -if [[ ${NEW_RELEASE_VERSION} = v* ]]; then - echo "WARNING: The new release version (v${NEW_RELEASE_VERSION}) starts with 'vv'." - echo "You must not enter the v when defining the new version." - ANSWER=$(ask_yes_or_no "Should the first v be removed?") - if [ "${ANSWER}" == "y" ]; then - NEW_RELEASE_VERSION="${NEW_RELEASE_VERSION:1}" - echo "Release version now is: ${NEW_RELEASE_VERSION}" +# Extension points in release.sh: +# +# A custom release argument file will be sourced if found. The custom release arg file may implement one or more bash +# functions which either release.sh or release_functions.sh define. If such a custom release function is found the +# release script must define the argument list which the custom release function will receive during the release. + +sourceCustomReleaseArgs() { + RELEASE_ARGS_FILE="${1}" + + if [[ -f "${RELEASE_ARGS_FILE}" ]]; then + echo "Using custom release args file ${RELEASE_ARGS_FILE}" + + sourceCustomReleaseExitCode=0 + # shellcheck disable=SC1090 + source "${RELEASE_ARGS_FILE}" || sourceCustomReleaseExitCode=$? + if [[ ${sourceCustomReleaseExitCode} -ne 0 ]]; then + echo "Error while sourcing custom release arg file ${sourceCustomReleaseExitCode}. Exiting." + exit 9 + fi fi -fi; - -# Do gitflow -git flow init -df -git checkout master -git pull origin master -git checkout develop -git pull origin develop -git flow release start v"${NEW_RELEASE_VERSION}" - -# Update version in dogu.json -jq ".Version = \"${NEW_RELEASE_VERSION}\"" dogu.json > dogu2.json && mv dogu2.json dogu.json -# Update version in Dockerfile -sed -i "s/\(^[ ]*VERSION=\"\)\([^\"]*\)\(.*$\)/\1${NEW_RELEASE_VERSION}\3/" Dockerfile -# Update version in Makefile -if [ -f "Makefile" ]; then - sed -i "s/\(^VERSION=\)\(.*\)$/\1${NEW_RELEASE_VERSION}/" Makefile -fi -# Update version in package.json -if [ -f "package.json" ]; then - jq ".version = \"${NEW_RELEASE_VERSION}\"" package.json > package2.json && mv package2.json package.json -fi -# Update version in pom.xml -if [ -f "pom.xml" ]; then - echo "Updating version in pom.xml..." - mvn versions:set -DgenerateBackupPoms=false -DnewVersion="${NEW_RELEASE_VERSION}" -fi - - -# Commit changes to version -wait_for_ok "Please make sure that all versions have been updated correctly now (e.g. via \"git diff\")." -git add Dockerfile -git add dogu.json -if [ -f "Makefile" ]; then - git add Makefile -fi -if [ -f "package.json" ]; then - git add package.json -fi -if [ -f "pom.xml" ]; then - git add pom.xml -fi -git commit -m "Bump version" +} -# Changelog update -CURRENT_DATE=$(date --rfc-3339=date) -NEW_CHANGELOG_TITLE="## [v${NEW_RELEASE_VERSION}] - ${CURRENT_DATE}" -# Check if "Unreleased" tag exists -while ! grep --silent "## \[Unreleased\]" CHANGELOG.md; do - echo "" - echo -e "\e[31mYour CHANGELOG.md does not contain a \"## [Unreleased]\" line!\e[0m" - echo "Please add one to make it comply to https://keepachangelog.com/en/1.0.0/" - wait_for_ok "Please insert a \"## [Unreleased]\" line into CHANGELOG.md now." -done +PROJECT_DIR="$(pwd)" +RELEASE_ARGS_FILE="${PROJECT_DIR}/release_args.sh" -# Add new title line to changelog -sed -i "s|## \[Unreleased\]|## \[Unreleased\]\n\n${NEW_CHANGELOG_TITLE}|g" CHANGELOG.md +sourceCustomReleaseArgs "${RELEASE_ARGS_FILE}" -# Wait for user to validate changelog changes -wait_for_ok "Please make sure your CHANGELOG.md looks as desired." +source "$(pwd)/build/make/release_functions.sh" -# Check if new version tag still exists -while ! grep --silent "## \[v${NEW_RELEASE_VERSION}\] - ${CURRENT_DATE}" CHANGELOG.md; do - echo "" - echo -e "\e[31mYour CHANGELOG.md does not contain \"${NEW_CHANGELOG_TITLE}\"!\e[0m" - wait_for_ok "Please update your CHANGELOG.md now." -done +TYPE="${1}" -git add CHANGELOG.md -git commit -m "Update changelog" +echo "=====Starting Release process=====" -if ! git diff --exit-code > /dev/null; then - echo "There are still uncommitted changes:" - echo "" - echo "# # # # # # # # # #" - echo "" - git --no-pager diff - echo "" - echo "# # # # # # # # # #" +if [ "${TYPE}" == "dogu" ];then + CURRENT_TOOL_VERSION=$(get_current_version_by_dogu_json) +else + CURRENT_TOOL_VERSION=$(get_current_version_by_makefile) fi -echo "All changes compared to develop branch:" -echo "" -echo "# # # # # # # # # #" -echo "" -git --no-pager diff develop -echo "" -echo "# # # # # # # # # #" +NEW_RELEASE_VERSION="$(read_new_version)" -# Push changes and delete release branch -wait_for_ok "Dogu upgrade from version v${CURRENT_DOGU_VERSION} to version v${NEW_RELEASE_VERSION} finished. Should the changes be pushed?" -git push origin release/v"${NEW_RELEASE_VERSION}" +validate_new_version "${NEW_RELEASE_VERSION}" +start_git_flow_release "${NEW_RELEASE_VERSION}" +update_versions "${NEW_RELEASE_VERSION}" +update_changelog "${NEW_RELEASE_VERSION}" +show_diff +finish_release_and_push "${CURRENT_TOOL_VERSION}" "${NEW_RELEASE_VERSION}" -echo "Switching back to develop and deleting branch release/v${NEW_RELEASE_VERSION}..." -git checkout develop -git branch -D release/v"${NEW_RELEASE_VERSION}" +echo "=====Finished Release process=====" diff --git a/build/make/self-update.mk b/build/make/self-update.mk index 8eaa8077..175f8a65 100644 --- a/build/make/self-update.mk +++ b/build/make/self-update.mk @@ -1,5 +1,7 @@ +##@ Makefile management + .PHONY: update-makefiles -update-makefiles: do-update-makefiles +update-makefiles: do-update-makefiles ## Update Makefiles to MAKEFILES_VERSION .PHONY: do-update-makefiles do-update-makefiles: $(TMP_DIR) download-and-extract remove-old-files copy-new-files diff --git a/build/make/static-analysis.mk b/build/make/static-analysis.mk index b93213cb..70e64685 100644 --- a/build/make/static-analysis.mk +++ b/build/make/static-analysis.mk @@ -1,15 +1,19 @@ +##@ Static analysis + STATIC_ANALYSIS_DIR=$(TARGET_DIR)/static-analysis GOIMAGE?=golang -GOTAG?=1.14.13 +GOTAG?=1.18 CUSTOM_GO_MOUNT?=-v /tmp:/tmp REVIEW_DOG=$(TMP_DIR)/bin/reviewdog LINT=$(TMP_DIR)/bin/golangci-lint +LINT_VERSION?=v1.49.0 # ignore tests and mocks -LINTFLAGS=--tests=false --skip-files="^.*_mock.go$$" --skip-files="^.*/mock.*.go$$" +LINTFLAGS=--tests=false --skip-files="^.*_mock.go$$" --skip-files="^.*/mock.*.go$$" --timeout 10m --issues-exit-code 0 +ADDITIONAL_LINTER=-E bodyclose -E containedctx -E contextcheck -E decorder -E dupl -E errname -E forcetypeassert -E funlen -E unparam .PHONY: static-analysis -static-analysis: static-analysis-$(ENVIRONMENT) +static-analysis: static-analysis-$(ENVIRONMENT) ## Start a static analysis of the code .PHONY: static-analysis-ci static-analysis-ci: @@ -39,11 +43,11 @@ $(STATIC_ANALYSIS_DIR)/static-analysis.log: $(STATIC_ANALYSIS_DIR) @echo "" @echo "complete static analysis:" @echo "" - @$(LINT) $(LINTFLAGS) run ./... | tee $@ + @$(LINT) $(LINTFLAGS) run ./... $(ADDITIONAL_LINTER) > $@ $(STATIC_ANALYSIS_DIR)/static-analysis-cs.log: $(STATIC_ANALYSIS_DIR) @echo "run static analysis with export to checkstyle format" - @$(LINT) $(LINTFLAGS) run --out-format=checkstyle ./... > $@ | true + @$(LINT) $(LINTFLAGS) run --out-format=checkstyle ./... $(ADDITIONAL_LINTER) > $@ $(STATIC_ANALYSIS_DIR): $(LINT) @mkdir -p $(STATIC_ANALYSIS_DIR) @@ -55,7 +59,8 @@ static-analysis-ci-report-local: $(STATIC_ANALYSIS_DIR)/static-analysis-cs.log $ @cat $(STATIC_ANALYSIS_DIR)/static-analysis-cs.log | $(REVIEW_DOG) -f checkstyle -diff "git diff develop" $(LINT): $(TMP_DIR) - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TMP_DIR)/bin v1.33.0 + @echo "Download golangci-lint $(LINT_VERSION)..." + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TMP_DIR)/bin $(LINT_VERSION) $(REVIEW_DOG): $(TMP_DIR) - @curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(TMP_DIR)/bin \ No newline at end of file + @curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(TMP_DIR)/bin diff --git a/build/make/test-common.mk b/build/make/test-common.mk index c8d1dd73..6eaa0da2 100644 --- a/build/make/test-common.mk +++ b/build/make/test-common.mk @@ -1,3 +1,6 @@ -$(GOPATH)/bin/go-junit-report: - @$(GO_CALL) get -u github.com/jstemmer/go-junit-report - @go mod vendor +GO_JUNIT_REPORT=$(UTILITY_BIN_PATH)/go-junit-report +GO_JUNIT_REPORT_VERSION=v1.0.0 + +$(GO_JUNIT_REPORT): $(UTILITY_BIN_PATH) + @echo "Download go-junit-report..." + @$(call go-get-tool,$@,github.com/jstemmer/go-junit-report@$(GO_JUNIT_REPORT_VERSION)) diff --git a/build/make/test-integration.mk b/build/make/test-integration.mk index 2bf53c27..9a3103c6 100644 --- a/build/make/test-integration.mk +++ b/build/make/test-integration.mk @@ -1,12 +1,15 @@ +##@ Integration testing + INTEGRATION_TEST_DIR=$(TARGET_DIR)/integration-tests XUNIT_INTEGRATION_XML=$(INTEGRATION_TEST_DIR)/integration-tests.xml INTEGRATION_TEST_LOG=$(INTEGRATION_TEST_DIR)/integration-tests.log INTEGRATION_TEST_REPORT=$(INTEGRATION_TEST_DIR)/coverage.out PRE_INTEGRATIONTESTS?=start-local-docker-compose POST_INTEGRATIONTESTS?=stop-local-docker-compose +INTEGRATION_TEST_NAME_PATTERN?=.* .PHONY: integration-test -integration-test: $(XUNIT_INTEGRATION_XML) +integration-test: $(XUNIT_INTEGRATION_XML) ## Start integration tests .PHONY: start-local-docker-compose start-local-docker-compose: @@ -27,22 +30,16 @@ else echo "Found CI environment. Nothing to be done" endif -$(XUNIT_INTEGRATION_XML): $(SRC) $(GOPATH)/bin/go-junit-report +$(XUNIT_INTEGRATION_XML): $(SRC) $(GO_JUNIT_REPORT) ifneq ($(strip $(PRE_INTEGRATIONTESTS)),) @make $(PRE_INTEGRATIONTESTS) endif @mkdir -p $(INTEGRATION_TEST_DIR) - @echo 'mode: set' > ${INTEGRATION_TEST_REPORT} + @echo 'mode: set' > $(INTEGRATION_TEST_REPORT) @rm -f $(INTEGRATION_TEST_LOG) || true - @for PKG in $(PACKAGES_FOR_INTEGRATION_TEST) ; do \ - ${GO_CALL} test -tags=${GO_BUILD_TAG_INTEGRATION_TEST} -v $$PKG -coverprofile=${INTEGRATION_TEST_REPORT}.tmp 2>&1 | tee $(INTEGRATION_TEST_LOG).tmp ; \ - cat ${INTEGRATION_TEST_REPORT}.tmp | tail +2 >> ${INTEGRATION_TEST_REPORT} ; \ - rm -f ${INTEGRATION_TEST_REPORT}.tmp ; \ - cat $(INTEGRATION_TEST_LOG).tmp >> $(INTEGRATION_TEST_LOG) ; \ - rm -f $(INTEGRATION_TEST_LOG).tmp ; \ - done - @cat $(INTEGRATION_TEST_LOG) | go-junit-report > $@ + @$(GO_CALL) test ./... -v -tags=${GO_BUILD_TAG_INTEGRATION_TEST} -coverpkg=./... -coverprofile=${INTEGRATION_TEST_REPORT} -run ${INTEGRATION_TEST_NAME_PATTERN} 2>&1 | tee $(INTEGRATION_TEST_LOG) + @cat $(INTEGRATION_TEST_LOG) | $(GO_JUNIT_REPORT) > $@ @if grep '^FAIL' $(INTEGRATION_TEST_LOG); then \ exit 1; \ fi diff --git a/build/make/test-unit.mk b/build/make/test-unit.mk index 8b696ee0..6838b1ce 100644 --- a/build/make/test-unit.mk +++ b/build/make/test-unit.mk @@ -1,3 +1,5 @@ +##@ Unit testing + UNIT_TEST_DIR=$(TARGET_DIR)/unit-tests XUNIT_XML=$(UNIT_TEST_DIR)/unit-tests.xml UNIT_TEST_LOG=$(UNIT_TEST_DIR)/unit-tests.log @@ -7,9 +9,9 @@ PRE_UNITTESTS?= POST_UNITTESTS?= .PHONY: unit-test -unit-test: $(XUNIT_XML) +unit-test: $(XUNIT_XML) ## Start unit tests -$(XUNIT_XML): $(SRC) $(GOPATH)/bin/go-junit-report +$(XUNIT_XML): $(SRC) $(GO_JUNIT_REPORT) ifneq ($(strip $(PRE_UNITTESTS)),) @make $(PRE_UNITTESTS) endif @@ -24,7 +26,7 @@ endif cat $(UNIT_TEST_LOG).tmp >> $(UNIT_TEST_LOG) ; \ rm -f $(UNIT_TEST_LOG).tmp ; \ done - @cat $(UNIT_TEST_LOG) | go-junit-report > $@ + @cat $(UNIT_TEST_LOG) | $(GO_JUNIT_REPORT) > $@ @if grep '^FAIL' $(UNIT_TEST_LOG); then \ exit 1; \ fi diff --git a/build/make/variables.mk b/build/make/variables.mk index 02ac1ca9..639a8b13 100644 --- a/build/make/variables.mk +++ b/build/make/variables.mk @@ -15,10 +15,11 @@ GO_ENVIRONMENT?= # GO_CALL accomodates the go CLI command as well as necessary environment variables which are optional. GO_CALL=${GO_ENVIRONMENT} go PACKAGES=$(shell ${GO_CALL} list ./... | grep -v /vendor/) -PACKAGES_FOR_INTEGRATION_TEST?=${PACKAGES} GO_BUILD_TAG_INTEGRATION_TEST?=integration +GOMODULES=on +UTILITY_BIN_PATH?=${WORKDIR}/.bin -SRC:=$(shell find "${WORKDIR}" -type f -name "*.go" -not -path "./vendor/*") +SRC:=$(shell find "${WORKDIR}" -type f -name "*.go" -not -path "*/vendor/*") # debian stuff DEBIAN_BUILD_DIR=$(BUILD_DIR)/deb @@ -35,6 +36,7 @@ endif YARN_TARGET=$(WORKDIR)/node_modules BOWER_TARGET?=$(WORKDIR)/public/vendor +NODE_VERSION?=8 UID_NR:=$(shell id -u) GID_NR:=$(shell id -g) @@ -57,3 +59,39 @@ $(PASSWD): $(TMP_DIR) $(ETCGROUP): $(TMP_DIR) @echo "root:x:0:" > $(ETCGROUP) @echo "$(USER):x:$(GID_NR):" >> $(ETCGROUP) + +$(UTILITY_BIN_PATH): + @mkdir -p $@ + +# Subdirectories of workdir where no mocks should be generated. +# Multiple directories can be separated by space, comma or whatever is not a word to regex. +MOCKERY_IGNORED=vendor,build,docs + +##@ General + +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +.PHONY: info +info: ## Print build information + @echo "dumping build information ..." + @echo "Version : $(VERSION)" + @echo "Commit-ID : $(COMMIT_ID)" + @echo "Environment: $(ENVIRONMENT)" + @echo "Branch : $(BRANCH)" + @echo "Packages : $(PACKAGES)" + + +# go-get-tool will 'go get' any package $2 and install it to $1. +define go-get-tool + @[ -f $(1) ] || { \ + set -e ;\ + TMP_DIR=$$(mktemp -d) ;\ + cd $$TMP_DIR ;\ + go mod init tmp ;\ + echo "Downloading $(2)" ;\ + GOBIN=$(UTILITY_BIN_PATH) go install $(2) ;\ + rm -rf $$TMP_DIR ;\ + } +endef diff --git a/build/make/yarn.mk b/build/make/yarn.mk index 2af31121..12792b45 100644 --- a/build/make/yarn.mk +++ b/build/make/yarn.mk @@ -1,7 +1,9 @@ +##@ Yarn dependency management + YARN_LOCK=$(WORKDIR)/yarn.lock .PHONY: yarn-install -yarn-install: $(YARN_TARGET) +yarn-install: $(YARN_TARGET) ## Execute yarn install ifeq ($(ENVIRONMENT), ci) @@ -18,7 +20,7 @@ $(YARN_TARGET): $(YARN_LOCK) $(PASSWD) -v $(PASSWD):/etc/passwd:ro \ -v $(WORKDIR):$(WORKDIR) \ -w $(WORKDIR) \ - node:8 \ + node:$(NODE_VERSION) \ yarn install @touch $@