refactor: split Makefile by topics
Signed-off-by: William Artero <git@artero.dev>
This commit is contained in:
parent
2169ee96ec
commit
25c15bbf10
7
.make/codecov.mk
Normal file
7
.make/codecov.mk
Normal file
|
@ -0,0 +1,7 @@
|
|||
CODECOV ?= codecov
|
||||
CODECOV_FLAGS ?=
|
||||
CODECOV_TOKEN ?=
|
||||
|
||||
.PHONY: codecov-report
|
||||
codecov-report:
|
||||
@${CODECOV} create-report -t ${CODECOV_TOKEN} ${CODECOV_FLAGS}
|
23
.make/container.mk
Normal file
23
.make/container.mk
Normal file
|
@ -0,0 +1,23 @@
|
|||
CONTAINER ?= docker
|
||||
CONTAINER_STRUCTURE_TEST ?= container-structure-test
|
||||
|
||||
CONTAINER_IMAGE ?=
|
||||
CONTAINER_STRUCTURE_TEST_FILE ?=
|
||||
|
||||
## https://github.com/moby/moby/issues/46129
|
||||
container-image: OTEL_EXPORTER_OTLP_ENDPOINT=
|
||||
container-image: CREATED=$(shell date -u +"%Y-%m-%dT%TZ")
|
||||
container-image: REVISION=$(shell git log -n 1 --format="%H")
|
||||
container-image: VERSION=$(patsubst v%,%,$(shell git describe --tags 2> /dev/null || echo "0.1.0-rc.0"))
|
||||
container-image:
|
||||
$(info building image ${CONTAINER_IMAGE})
|
||||
@${CONTAINER} build --load $(if ${TARGET},--target ${TARGET}) \
|
||||
-t ${CONTAINER_IMAGE} \
|
||||
--build-arg VERSION=${VERSION} \
|
||||
--label org.opencontainers.image.created=${CREATED} \
|
||||
--label org.opencontainers.image.revision=${REVISION} \
|
||||
--label org.opencontainers.image.version=${VERSION} \
|
||||
.
|
||||
|
||||
container-test: ${CONTAINER_STRUCTURE_TEST_FILE}
|
||||
@${CONTAINER_STRUCTURE_TEST} test -c "$<" -i "${CONTAINER_IMAGE}"
|
6
.make/gcov2lcov.mk
Normal file
6
.make/gcov2lcov.mk
Normal file
|
@ -0,0 +1,6 @@
|
|||
GCOV2LCOV ?= gcov2lcov
|
||||
|
||||
GCOV2LCOV_LCOV_FILE ?= ${GOLANG_COVERAGE_PATH}/lcov.info
|
||||
|
||||
${GCOV2LCOV_LCOV_FILE}: ${GOLANG_REPORT_SOURCE}
|
||||
@${GCOV2LCOV} -infile $< -outfile $@
|
78
.make/golang.mk
Normal file
78
.make/golang.mk
Normal file
|
@ -0,0 +1,78 @@
|
|||
GO ?= go
|
||||
|
||||
GOLANG_PACKAGE = $(shell ${GO} list)
|
||||
|
||||
GOCOVERDIR ?= coverage/integration
|
||||
|
||||
GOLANG_FLAGS ?= -race -mod=readonly
|
||||
GOLANG_COVERAGE_PATH ?= coverage
|
||||
GOLANG_OUTPUT_BIN_PATH ?= bin
|
||||
|
||||
GOLANG_INTEGRATION_ENABLED ?=
|
||||
GOLANG_INTEGRATION_SRC_PATH ?=
|
||||
GOLANG_INTEGRATION_PACKAGES ?=
|
||||
|
||||
CMD_SOURCE_FILES := $(shell ${GO} list -f '{{ range .GoFiles }}{{ printf "%s/%s\n" $$.Dir . }}{{ end }}' ./cmd/...)
|
||||
INTERNAL_SOURCE_FILES := $(shell ${GO} list -f '{{ range .GoFiles }}{{ printf "%s/%s\n" $$.Dir . }}{{ end }}' ./internal/...)
|
||||
SOURCE_FILES := ${CMD_SOURCE_FILES} ${INTERNAL_SOURCE_FILES}
|
||||
|
||||
ifneq (${GOLANG_INTEGRATION_ENABLED},)
|
||||
GOLANG_REPORT_SOURCE := ${GOLANG_COVERAGE_PATH}/merged.txt
|
||||
else
|
||||
GOLANG_REPORT_SOURCE := ${GOLANG_COVERAGE_PATH}/test.txt
|
||||
endif
|
||||
|
||||
.PHONY: golang-build
|
||||
golang-build:
|
||||
$(info generating files)
|
||||
@${GO} generate ./...
|
||||
$(info building binaries)
|
||||
@${GO} build ${GOLANG_FLAGS} -o ./${GOLANG_OUTPUT_BIN_PATH} ./...
|
||||
|
||||
.PHONY: golang-clean
|
||||
golang-clean:
|
||||
-@${RM} -r ${GOLANG_COVERAGE_PATH}
|
||||
-@${RM} -r ${GOLANG_OUTPUT_BIN_PATH}
|
||||
|
||||
.PHONY: golang-test
|
||||
golang-test:
|
||||
@${GO} test ${GOLANG_FLAGS} -v ./...
|
||||
|
||||
.PHONY: golang-report
|
||||
golang-report: ${GOLANG_COVERAGE_PATH}/coverage.html
|
||||
|
||||
.PHONY: golang-coverage
|
||||
golang-coverage: ${GOLANG_REPORT_SOURCE}
|
||||
golang-coverage:
|
||||
$(info generating coverage report from $<)
|
||||
@${GO} tool cover -func="$<"
|
||||
|
||||
${GOLANG_COVERAGE_PATH}/coverage.html: ${GOLANG_REPORT_SOURCE}
|
||||
$(info ${SEPARATOR})
|
||||
$(info generating html report from ${GOLANG_REPORT_SOURCE})
|
||||
$(info ${SEPARATOR})
|
||||
@${GO} tool cover -html=$< -o $@
|
||||
|
||||
${GOLANG_COVERAGE_PATH}/test.txt: ${SOURCE_FILES}
|
||||
${GOLANG_COVERAGE_PATH}/test.txt:
|
||||
$(info running unit tests)
|
||||
@${GO} test -v ${GOLANG_FLAGS} -coverprofile=$@ ./...
|
||||
|
||||
### only run and merge test results if we have a configured integration binary
|
||||
ifneq (${GOLANG_INTEGRATION_ENABLED},)
|
||||
${GOLANG_COVERAGE_PATH}/merged.txt: ${GOLANG_COVERAGE_PATH}/integration.txt ${GOLANG_COVERAGE_PATH}/test.txt
|
||||
$(info merging test results)
|
||||
@${GO} run github.com/wadey/gocovmerge@latest $^ > $@
|
||||
|
||||
${GOLANG_COVERAGE_PATH}/integration.txt: ${GOCOVERDIR}
|
||||
$(info converting integration results to gocov)
|
||||
@${GO} tool covdata textfmt -i="$<" -o="$@" -pkg="${GOLANG_INTEGRATION_PACKAGES}"
|
||||
|
||||
${GOCOVERDIR}: ${SOURCE_FILES}
|
||||
${GOCOVERDIR}:
|
||||
$(info running integration test)
|
||||
@mkdir -p "$@"
|
||||
@${GO} run -cover ${GOLANG_FLAGS} ./${GOLANG_INTEGRATION_SRC_PATH}/...
|
||||
@echo "raw report"
|
||||
@${GO} tool covdata percent -i="$@" | column -t
|
||||
endif
|
12
.make/golangci-lint.mk
Normal file
12
.make/golangci-lint.mk
Normal file
|
@ -0,0 +1,12 @@
|
|||
GO ?= go
|
||||
GOLANGCI_LINT ?= golangci-lint
|
||||
GOLANGCI_LINT_REPORT_FILE ?= golangci-lint-report.xml
|
||||
|
||||
GOLANGCI_LINT_SOURCE_FILES ?= $(shell ${GO} list -f '{{ range .GoFiles }}{{ printf "%s/%s\n" $$.Dir . }}{{ end }}' ./...)
|
||||
|
||||
.PHONY: golang-lint
|
||||
golang-lint: ${GOLANGCI_LINT_REPORT_FILE}
|
||||
@${GOLANGCI_LINT} run
|
||||
|
||||
${GOLANGCI_LINT_REPORT_FILE}: ${GOLANGCI_LINT_SOURCE_FILES}
|
||||
@${GOLANGCI_LINT} run --out-format checkstyle > $@
|
5
.make/goreleaser.mk
Normal file
5
.make/goreleaser.mk
Normal file
|
@ -0,0 +1,5 @@
|
|||
GORELEASER ?= goreleaser
|
||||
|
||||
.PHONY: golang-release
|
||||
golang-release:
|
||||
@${GORELEASER} release --clean --skip-publish --skip-announce --snapshot
|
15
Dockerfile
15
Dockerfile
|
@ -27,11 +27,14 @@ FROM alpine:${ALPINE_VERSION} AS tmp
|
|||
FROM scratch
|
||||
|
||||
LABEL org.opencontainers.image.authors="William Artero <docker@artero.dev>"
|
||||
LABEL org.opencontainers.image.description="anilist custom list provider for sonarr/radarr"
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.title="Anilistarr"
|
||||
LABEL org.opencontainers.image.vendor="William Artero <docker@artero.dev>"
|
||||
LABEL org.opencontainers.image.base.name="scratch"
|
||||
LABEL org.opencontainers.image.description="anilist custom list provider for sonarr/radarr"
|
||||
LABEL org.opencontainers.image.documentation="https://github.com/wwmoraes/anilistarr/blob/master/README.md"
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.source="https://github.com/wwmoraes/anilistarr"
|
||||
LABEL org.opencontainers.image.title="Anilistarr"
|
||||
LABEL org.opencontainers.image.url="https://hub.docker.com/r/wwmoraes/anilistarr"
|
||||
LABEL org.opencontainers.image.vendor="William Artero <docker@artero.dev>"
|
||||
|
||||
CMD ["/usr/local/bin/handler"]
|
||||
EXPOSE 8080
|
||||
|
@ -39,9 +42,7 @@ EXPOSE 8080
|
|||
COPY --from=tmp --chown=20000:20000 /tmp /var/handler
|
||||
COPY --from=certificates /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
ARG VERSION
|
||||
LABEL org.opencontainers.image.version="${VERSION}"
|
||||
|
||||
COPY --from=build /src/bin/handler /usr/local/bin/handler
|
||||
|
||||
WORKDIR /
|
||||
USER 20000:20000
|
||||
|
|
127
Makefile
127
Makefile
|
@ -1,119 +1,52 @@
|
|||
-include .env
|
||||
-include .env.local
|
||||
DOCKER ?= docker
|
||||
GO ?= go
|
||||
LINTER ?= golangci-lint
|
||||
GORELEASER ?= goreleaser
|
||||
GOCOVERDIR ?= coverage/integration
|
||||
export
|
||||
|
||||
SEPARATOR = $(shell printf "%0.s=" {1..80})
|
||||
GOLANG_INTEGRATION_ENABLED = 1
|
||||
|
||||
PKG = github.com/wwmoraes/anilistarr
|
||||
CMD_SOURCE_FILES := $(shell find cmd -type f -name '*.go')
|
||||
INTERNAL_SOURCE_FILES := $(shell find internal -type f -name '*.go')
|
||||
SOURCE_FILES := $(CMD_SOURCE_FILES) $(INTERNAL_SOURCE_FILES)
|
||||
-include .make/*.mk
|
||||
|
||||
CONTAINER_IMAGE = wwmoraes/anilistarr
|
||||
CONTAINER_STRUCTURE_TEST_FILE = container-structure-test.yaml
|
||||
CODECOV_FLAGS = -X fixes -f coverage/merged.txt
|
||||
GOLANG_INTEGRATION_SRC_PATH = cmd/internal/integration
|
||||
GOLANG_INTEGRATION_PACKAGES = ${GOLANG_PACKAGE}/internal/usecases,${GOLANG_PACKAGE}/internal/adapters
|
||||
|
||||
codecov-report: coverage/merged.txt
|
||||
|
||||
# SEPARATOR = $(shell printf "%0.s=" {1..80})
|
||||
|
||||
.PHONY: build
|
||||
build: generate
|
||||
$(info building)
|
||||
@${GO} build -o ./bin/ ./...
|
||||
build: golang-build
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-@${RM} -r coverage
|
||||
clean: golang-clean
|
||||
|
||||
.PHONY: release
|
||||
release:
|
||||
@${GORELEASER} release --clean --skip-publish --skip-announce --snapshot
|
||||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
$(info generating files)
|
||||
@${GO} generate ./...
|
||||
release: golang-release
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
@${GO} test -race -v ./...
|
||||
test: golang-test
|
||||
|
||||
.PHONY: lint
|
||||
lint: golangci-lint-report.xml
|
||||
@${LINTER} run
|
||||
lint: golang-lint
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: GOCOVERDIR=coverage/integration
|
||||
coverage: PKGS="${PKG}/internal/usecases,${PKG}/internal/adapters"
|
||||
coverage: coverage/merged.txt
|
||||
coverage:
|
||||
$(info ${SEPARATOR})
|
||||
$(info coverage report)
|
||||
$(info ${SEPARATOR})
|
||||
@${GO} tool cover -func="$<"
|
||||
coverage: golang-coverage
|
||||
|
||||
PHONY: coverage-html
|
||||
coverage-html: coverage/coverage.html
|
||||
.PHONY: report
|
||||
report: golang-report
|
||||
|
||||
${GOCOVERDIR}: ${SOURCE_FILES}
|
||||
${GOCOVERDIR}:
|
||||
$(info ${SEPARATOR})
|
||||
$(info running integration test)
|
||||
$(info ${SEPARATOR})
|
||||
@mkdir -p "$@"
|
||||
@${GO} run -cover -race -mod=readonly ./cmd/internal/integration/...
|
||||
@echo "${SEPARATOR}"
|
||||
@echo "raw report"
|
||||
@echo "${SEPARATOR}"
|
||||
@${GO} tool covdata percent -i="$@" | column -t
|
||||
.PHONY: image
|
||||
image: container-image
|
||||
|
||||
%/integration.txt: PKGS="${PKG}/internal/usecases,${PKG}/internal/adapters"
|
||||
%/integration.txt: ${GOCOVERDIR}
|
||||
$(info ${SEPARATOR})
|
||||
$(info generating gcov data)
|
||||
$(info ${SEPARATOR})
|
||||
@${GO} tool covdata textfmt -i="$<" -o="$@" -pkg="${PKGS}"
|
||||
.PHONY: image-test
|
||||
image-test: container-test
|
||||
|
||||
coverage/test.txt: ${SOURCE_FILES}
|
||||
coverage/test.txt:
|
||||
$(info ${SEPARATOR})
|
||||
$(info running unit tests)
|
||||
$(info ${SEPARATOR})
|
||||
@${GO} test -v -race -mod=readonly -coverprofile=$@ ./...
|
||||
|
||||
coverage/merged.txt: coverage/integration.txt coverage/test.txt
|
||||
@${GO} run github.com/wadey/gocovmerge@latest $^ > $@
|
||||
|
||||
coverage/coverage.html: coverage/merged.txt
|
||||
$(info ${SEPARATOR})
|
||||
$(info generating html report)
|
||||
$(info ${SEPARATOR})
|
||||
@${GO} tool cover -html=$< -o $@
|
||||
|
||||
golangci-lint-report.xml: ${SOURCE_FILES}
|
||||
@${LINTER} run --out-format checkstyle > $@
|
||||
|
||||
IMAGE ?= wwmoraes/anilistarr
|
||||
# needs go install github.com/Khan/genqlient@latest
|
||||
anilist:
|
||||
@cd internal/drivers/anilist && genqlient
|
||||
|
||||
## https://github.com/moby/moby/issues/46129
|
||||
image: OTEL_EXPORTER_OTLP_ENDPOINT=
|
||||
image: CREATED=$(shell date -u +"%Y-%m-%dT%TZ")
|
||||
image: REVISION=$(shell git log -n 1 --format="%H")
|
||||
image: VERSION=$(patsubst v%,%,$(shell git describe --tags 2> /dev/null || echo "0.1.0-rc.0"))
|
||||
image:
|
||||
$(info building image ${IMAGE})
|
||||
@${DOCKER} build --load $(if ${TARGET},--target ${TARGET}) \
|
||||
-t ${IMAGE} \
|
||||
--build-arg VERSION=${VERSION} \
|
||||
--label org.opencontainers.image.created=${CREATED} \
|
||||
--label org.opencontainers.image.revision=${REVISION} \
|
||||
--label org.opencontainers.image.documentation=https://github.com/${IMAGE}/blob/master/README.md \
|
||||
--label org.opencontainers.image.source=https://github.com/${IMAGE} \
|
||||
--label org.opencontainers.image.url=https://hub.docker.com/r/${IMAGE} \
|
||||
.
|
||||
@container-structure-test test -c container-structure-test.yaml -i wwmoraes/anilistarr
|
||||
|
||||
run:
|
||||
@${GO} run ./cmd/handler/...
|
||||
|
||||
|
@ -135,6 +68,16 @@ docs:
|
|||
|
||||
run-image: DATA_PATH=/var/handler
|
||||
run-image:
|
||||
@${DOCKER} run --rm \
|
||||
@${CONTAINER} run --rm \
|
||||
-e DATA_PATH \
|
||||
-it ${IMAGE}
|
||||
|
||||
diagrams:
|
||||
@structurizr-cli export -f plantuml/c4plantuml -w workspace.dsl -o docs
|
||||
@plantuml docs/*.puml
|
||||
|
||||
watch-diagrams:
|
||||
@fswatch -o --event Updated workspace.dsl | xargs -n 1 sh -c "clear; date; ${MAKE} diagrams"
|
||||
|
||||
# edit-diagrams:
|
||||
# @ structurizr/lite
|
||||
|
|
|
@ -3,15 +3,15 @@ fileExistenceTests:
|
|||
- name: handler binary
|
||||
path: /usr/local/bin/handler
|
||||
shouldExist: true
|
||||
gid: 0
|
||||
uid: 0
|
||||
gid: 20000
|
||||
uid: 20000
|
||||
permissions: -rwxr-xr-x
|
||||
isExecutableBy: any
|
||||
|
||||
metadataTest:
|
||||
cmd: [/usr/local/bin/handler]
|
||||
workdir: /
|
||||
entrypoint: []
|
||||
# entrypoint: []
|
||||
exposedPorts:
|
||||
- "8080"
|
||||
labels:
|
||||
|
|
Loading…
Reference in a new issue