Skip to content

Commit

Permalink
chore: updated make targets with safety checks
Browse files Browse the repository at this point in the history
Signed-off-by: William Artero <git@artero.dev>
  • Loading branch information
wwmoraes committed Dec 5, 2023
1 parent 8ab292a commit 19328fa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/integration.yml
Expand Up @@ -35,9 +35,8 @@ on:

env:
GOLANG_FLAGS: -race -mod=readonly
GOLANG_INTEGRATION_SRC_PATH: cmd/internal/integration
GOLANG_MERGED_GOCOV_FILE: merged.txt
GOLANG_RUN_REPORT_FILE: run-report.json
GOLANG_MERGED_GOCOV_FILE: coverage/merged.txt
GOLANG_RUN_REPORT_FILE: coverage/run-report.json
GOLANG_VERSION: "1.20"
WORK_DIR: /usr/src

Expand Down
6 changes: 4 additions & 2 deletions .make/code-climate.mk
Expand Up @@ -2,10 +2,12 @@ CC_TEST_REPORTER ?= cc-test-reporter

CC_REPORT_JSON_PATH ?= coverage/codeclimate.json

.PHONY: code-climate-report
code-climate-report: ${CC_REPORT_JSON_PATH}
$(info uploading report to Code Climate)
@${CC_TEST_REPORTER} upload-coverage

${CC_REPORT_JSON_PATH}: ${GOLANG_COVERAGE_REPORT_SOURCE}
${CC_REPORT_JSON_PATH}:
$(if $<,,$(error target $${CC_REPORT_JSON_PATH} must have a source file as dependency))
$(info converting gocov to Code Climate format)
@${CC_TEST_REPORTER} format-coverage -o $@ -t gocov -p ${GOLANG_PACKAGE} $<
@${CC_TEST_REPORTER} format-coverage -o $@ -t gocov -p ${GOLANG_PACKAGE} "$<"
7 changes: 4 additions & 3 deletions .make/codecov.mk
@@ -1,8 +1,9 @@
CODECOV ?= codecov
CODECOV_FLAGS ?= -X fixes -f ${GOLANG_COVERAGE_REPORT_SOURCE}
CODECOV_FLAGS ?= -X fixes
CODECOV_TOKEN ?=

.PHONY: codecov-report
codecov-report: ${GOLANG_COVERAGE_REPORT_SOURCE}
codecov-report:
$(if $<,,$(error target codecov-report must have a source file as dependency))
$(info uploading Codecov report)
@${CODECOV} create-report -t ${CODECOV_TOKEN} ${CODECOV_FLAGS}
@${CODECOV} create-report -c -t ${CODECOV_TOKEN} ${CODECOV_FLAGS} -f "$<"
3 changes: 1 addition & 2 deletions .make/golang.mk
Expand Up @@ -25,10 +25,9 @@ INTERNAL_SOURCE_FILES := $(shell ${GO} list -f '{{ range .GoFiles }}{{ printf "%
SOURCE_FILES := ${CMD_SOURCE_FILES} ${INTERNAL_SOURCE_FILES}

### use either the unit test or the merged gocov file for reports
GOLANG_COVERAGE_REPORT_SOURCE := ${GOLANG_UNIT_TEST_GOCOV_FILE}
ifneq (${GOLANG_INTEGRATION_ENABLED},)
GOLANG_COVERAGE_REPORT_SOURCE := ${GOLANG_MERGED_GOCOV_FILE}
else
GOLANG_COVERAGE_REPORT_SOURCE := ${GOLANG_UNIT_TEST_GOCOV_FILE}
endif

### prefix the relative paths with the package name. Required by go tool covdata
Expand Down
8 changes: 8 additions & 0 deletions Makefile
@@ -1,3 +1,8 @@
# Disable built-in rules and variables and suffixes
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
.SUFFIXES:

-include .env
-include .env.local
export
Expand All @@ -10,6 +15,9 @@ GOLANG_INTEGRATION_PACKAGES = internal/usecases,internal/adapters

-include .make/*.mk

codecov-report: ${GOLANG_COVERAGE_REPORT_SOURCE}
${CC_REPORT_JSON_PATH}: ${GOLANG_COVERAGE_REPORT_SOURCE}

### local targets

.PHONY: build
Expand Down

0 comments on commit 19328fa

Please sign in to comment.