Skip to content

Commit

Permalink
fix: support (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrop committed Jan 12, 2024
1 parent 17d21cb commit 12b33f6
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 54 deletions.
8 changes: 6 additions & 2 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ most prominent ones
GOMAKE := github.com/tkrop/go-make@latest
# Setup code quality level (default: base).
CODE_QUALITY := plus
# Customizing codacy server (default: https://codacy.bus.zalan.do).
CODACY_API_BASE_URL := https://api.codacy.com
# Setup codacy integration (default: enabled [enabled, disabled]).
CODACY := enabled

Expand All @@ -97,8 +99,10 @@ IMAGE_PUSH ?= never
# Setup default test timeout (default: 10s).
TEST_TIMEOUT := 15s

# Setup custom delivery file (default: delivery.yaml).
FILE_DELIVERY := delivery-template.yaml
# Setup custom delivery files scanned for updating go versions
# (default: delivery*.yaml/.github/workflows/*.yaml).
#DELIVERY := delivery.yaml

# Setup custom local build targets (default: init test lint build).
TARGETS_ALL := init delivery test lint build

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ else
$(warning warning: please customize variables in Makefile.vars)
endif


#GOBIN := $(CURDIR)/build/bin
#PATH := $(GOBIN):$(PATH)
GOBIN ?= $(shell go env GOPATH)/bin
GOMAKE ?= github.com/tkrop/[email protected].34
GOMAKE ?= github.com/tkrop/[email protected].35
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
make -f config/Makefile.base install >/dev/stderr && \
$(GOBIN)/go-make targets)
Expand Down
30 changes: 18 additions & 12 deletions Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ FILE_REVIVE ?= $(call search-default,revive.toml)
FILE_CODACY ?= $(call search-default,.codacy.yaml)

FILE_CONTAINER ?= Dockerfile
FILE_DELIVERY ?= delivery.yaml
FILE_DELIVERY_REGEX ?= (cdp-runtime\/go-|go-version: \^?)[0-9.]*

# Setup custom delivery files to be scanned for updating go versions.
DELIVERY := $(strip $(wildcard delivery.yaml) $(wildcard .github/workflows/*.yaml))
DELIVERY_REGEX ?= (cdp-runtime\/go-|go-version: \^?)[0-9.]*

REPOSITORY ?= $(shell git remote get-url origin | \
sed "s/^https:\/\///; s/^git@//; s/.git$$//; s/:/\//")
Expand Down Expand Up @@ -62,7 +64,7 @@ TOOLS_GO := $(TOOLS_GO) \
github.com/icholy/gomajor \
github.com/golang/mock/mockgen \
github.com/tkrop/go-testing/cmd/mock \
github.com/tkrop/[email protected].34
github.com/tkrop/[email protected].35
TOOLS_SH := $(TOOLS_SH) \
github.com/anchore/syft \
github.com/anchore/grype
Expand Down Expand Up @@ -578,7 +580,7 @@ test-go = \
echo -e "\trun 'make update-go $${VERSION}' to adjust the project!"; \
exit 1; \
fi; \
done;
done

#@ test whether project is using the latest go-version.
test-go::
Expand All @@ -587,11 +589,13 @@ test-go::
VERSIONS=$$(grep "^go [0-9.]*$$" go.mod | cut -f2 -d' '); \
$(call test-go,go.mod) \
fi; \
if [ -f "$(FILE_DELIVERY)" ]; then \
VERSIONS="$$(grep -Eo "$(FILE_DELIVERY_REGEX)" \
"$(FILE_DELIVERY)" | grep -Eo "[0-9.]*" | sort -u)"; \
$(call test-go,$(FILE_DELIVERY)) \
fi; \
for FILE in $(DELIVERY); do \
if [ -f "$$(FILE)" ]; then \
VERSIONS="$$(grep -Eo "$(DELIVERY_REGEX)" "$$(FILE)" | \
grep -Eo "[0-9.]*" | sort -u)"; \
$(call test-go,$${FILE}); \
fi; \
done;

# process test arguments.
testargs = \
Expand Down Expand Up @@ -1279,9 +1283,11 @@ update-go::
else VERSION="$(RUNARGS)"; fi; \
echo "info: update golang version to $${VERSION}"; \
go get go@latest; go mod tidy -go=$${VERSION}; \
if [ -f $(FILE_DELIVERY) ]; then \
sed -E -i -e "s/$(FILE_DELIVERY_REGEX)/\1$${VERSION}/" $(FILE_DELIVERY); \
fi; \
for FILE in $(DELIVERY); do \
if [ -f "$${FILE}" ]; then \
sed -E -i -e "s/$(DELIVERY_REGEX)/\1$${VERSION}/" "$${FILE}"; \
fi; \
done; \
if [ "$(GOVERSION)" != "$${VERSION}" ]; then \
echo "warning: current compiler is using $(GOVERSION)" >/dev/stderr; \
fi; \
Expand Down
5 changes: 1 addition & 4 deletions Makefile.vars
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CODE_QUALITY := plus

# Setup codacy integration (default: enabled [enabled, disabled]).
CODACY := enabled
# Customizing codacy server for open source.
# Customizing codacy server (default: https://codacy.bus.zalan.do).
CODACY_API_BASE_URL := https://api.codacy.com
# Continue after codacy shows violation (default: false / true [cdp-pipeline]).
#CODACY_CONTINUE := true
Expand All @@ -21,9 +21,6 @@ IMAGE_PUSH ?= never
# Setup default test timeout (default: 10s).
TEST_TIMEOUT := 10s

# Setup custom delivery file (default: delivery.yaml).
FILE_DELIVERY := .github/workflows/go.yaml

# Custom linters applied to prepare next level (default: <empty>).
LINTERS_CUSTOM := nonamedreturns tagliatelle
# Linters swithed off to complete next level (default: <empty>).
Expand Down
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ building, installing, updating, running, and releasing libraries, commands, and
container images.

`go-make` can be either run as command line tool or hooked into an existing
project as minimal [`Makefile`](Makefile). Technically `go-make` is just a thin
wrapper around a very generic and extensible [`Makefile`](Makefile.base) that
is based on a standard [`go`][go]-project supporting different tools:
project as minimal [`Makefile`](config/Makefile). Technically `go-make` is just
a thin wrapper around a very generic and extensible [`Makefile`](Makefile.base)
that is based on a standard [`go`][go]-project supporting different tools:

* [`gomock`][gomock] - go generating mocks.
* [`codacy`][codacy] - for code quality documentation.
Expand Down Expand Up @@ -175,18 +175,19 @@ source <(go-make --completion=bash)

To extend the `Makefile`, you develop own receipts in a custom file called
[`Makefile.ext`](Makefile.ext) that is included automatically. If you want to
extend original receipts, you can replace the wrapper [`Makefile`](Makefile)
and install [`Makefile.base`](Makefile.base) and the [`MANUAL.md`](MANUAL.md)
in your project by calling `go-make init-make!`. But be careful, this command
always overwrites your `Makefile` with the latest version.
extend original receipts, you can use `make install-make!` to automatically
replace the wrapper [`Makefile`](config/Makefile) against the original
[`Makefile.base`](config/Makefile.base) and adding a local
[`MANUAL.md`](MANUAL.md) to your project.


## Standard `go`-Project

The [Makefile](Makefile) provided in this project is working under the
conventions of a standard [`go`][go]-project. The standard [`go`][go]-project
is defined to meet Zalando in-house requirements, but is general enough to be
useful in open source projects too. It adheres to the following conventions:
The [`Makefile.base`](config/Makefile.base) provided in this project is based
on a standard [`go`][go]-project setting some limitations. The standard
[`go`][go]-project is defined to meet Zalando in-house requirements, but is
general enough to be useful in open source projects too. It adheres to the
following conventions:

1. All commands (services, jobs) are provided by a `main.go` placed as usual
under `cmd` using the pattern `cmd/<name>/main.go` or in the root folder. In
Expand Down Expand Up @@ -220,16 +221,30 @@ useful in open source projects too. It adheres to the following conventions:
6. For running a command in a container image, make sure that the command is
installed in the default execution directory of the container image - usually
the root directory. The container image must either be generated with suffix
matching the command or without suffix.
matching the command or without suffix in common container.

All targets in the [Makefile](Makefile) are designated to autonomously set up
setup the [`go`][go]-project, installing the necessary tools - except for the
golang compiler and build environment -, and triggering the precondition
All targets in the [Makefile](config/Makefile.base) are designated to set up
the [`go`][go]-project automatically, installing the necessary tools - except
for the golang compiler and build environment -, and triggering the required
targets as necessary.

[go]: <https://go.dev/>


## Trouble Shooting

If we have published an non-working version of `go-make` and your project is
not able to build, test, run, etc, the quickest way to reset the project
[Makefile](config/Makefile) working `go-make` version is to run:

```bash
go install github.com/tkrop/go-make@latest; go-make update;
```

If the latest version is not fixed yet, you can also try to move backward
finding the last working [tagged version](tags).


## Terms of usage

This software is open source as is under the MIT license. If you start using
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.34
0.0.35
2 changes: 1 addition & 1 deletion config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else
endif

GOBIN ?= $(shell go env GOPATH)/bin
GOMAKE ?= github.com/tkrop/[email protected].34
GOMAKE ?= github.com/tkrop/[email protected].35
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
go install $(GOMAKE) >/dev/stderr && $(GOBIN)/go-make targets)

Expand Down
30 changes: 18 additions & 12 deletions config/Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ FILE_REVIVE ?= $(call search-default,revive.toml)
FILE_CODACY ?= $(call search-default,.codacy.yaml)

FILE_CONTAINER ?= Dockerfile
FILE_DELIVERY ?= delivery.yaml
FILE_DELIVERY_REGEX ?= (cdp-runtime\/go-|go-version: \^?)[0-9.]*

# Setup custom delivery files to be scanned for updating go versions.
DELIVERY := $(strip $(wildcard delivery.yaml) $(wildcard .github/workflows/*.yaml))
DELIVERY_REGEX ?= (cdp-runtime\/go-|go-version: \^?)[0-9.]*

REPOSITORY ?= $(shell git remote get-url origin | \
sed "s/^https:\/\///; s/^git@//; s/.git$$//; s/:/\//")
Expand Down Expand Up @@ -62,7 +64,7 @@ TOOLS_GO := $(TOOLS_GO) \
github.com/icholy/gomajor \
github.com/golang/mock/mockgen \
github.com/tkrop/go-testing/cmd/mock \
github.com/tkrop/[email protected].34
github.com/tkrop/[email protected].35
TOOLS_SH := $(TOOLS_SH) \
github.com/anchore/syft \
github.com/anchore/grype
Expand Down Expand Up @@ -578,7 +580,7 @@ test-go = \
echo -e "\trun 'make update-go $${VERSION}' to adjust the project!"; \
exit 1; \
fi; \
done;
done

#@ test whether project is using the latest go-version.
test-go::
Expand All @@ -587,11 +589,13 @@ test-go::
VERSIONS=$$(grep "^go [0-9.]*$$" go.mod | cut -f2 -d' '); \
$(call test-go,go.mod) \
fi; \
if [ -f "$(FILE_DELIVERY)" ]; then \
VERSIONS="$$(grep -Eo "$(FILE_DELIVERY_REGEX)" \
"$(FILE_DELIVERY)" | grep -Eo "[0-9.]*" | sort -u)"; \
$(call test-go,$(FILE_DELIVERY)) \
fi; \
for FILE in $(DELIVERY); do \
if [ -f "$$(FILE)" ]; then \
VERSIONS="$$(grep -Eo "$(DELIVERY_REGEX)" "$$(FILE)" | \
grep -Eo "[0-9.]*" | sort -u)"; \
$(call test-go,$${FILE}); \
fi; \
done;

# process test arguments.
testargs = \
Expand Down Expand Up @@ -1279,9 +1283,11 @@ update-go::
else VERSION="$(RUNARGS)"; fi; \
echo "info: update golang version to $${VERSION}"; \
go get go@latest; go mod tidy -go=$${VERSION}; \
if [ -f $(FILE_DELIVERY) ]; then \
sed -E -i -e "s/$(FILE_DELIVERY_REGEX)/\1$${VERSION}/" $(FILE_DELIVERY); \
fi; \
for FILE in $(DELIVERY); do \
if [ -f "$${FILE}" ]; then \
sed -E -i -e "s/$(DELIVERY_REGEX)/\1$${VERSION}/" "$${FILE}"; \
fi; \
done; \
if [ "$(GOVERSION)" != "$${VERSION}" ]; then \
echo "warning: current compiler is using $(GOVERSION)" >/dev/stderr; \
fi; \
Expand Down
7 changes: 2 additions & 5 deletions config/Makefile.vars
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ CODE_QUALITY := base

# Setup codacy integration (default: enabled [enabled, disabled]).
CODACY := enabled
# Customizing codacy server for open source.
CODACY_API_BASE_URL := https://codacy.bus.zalan.do
# Customizing codacy server (default: https://codacy.bus.zalan.do).
#CODACY_API_BASE_URL := https://api.codacy.com
# Continue after codacy shows violation (default: false / true [cdp-pipeline]).
CODACY_CONTINUE := true

Expand All @@ -21,9 +21,6 @@ IMAGE_PUSH ?= never
# Setup default test timeout (default: 10s).
TEST_TIMEOUT := 10s

# Setup custom delivery file (default: delivery.yaml).
FILE_DELIVERY := delivery.yaml

# Custom linters applied to prepare next level (default: <empty>).
LINTERS_CUSTOM :=
# Linters swithed off to complete next level (default: <empty>).
Expand Down
2 changes: 1 addition & 1 deletion internal/make/fixtures/targets-trace.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
../../config/Makefile.base:365: target 'targets' does not exist
../../config/Makefile.base:367: target 'targets' does not exist
make --no-builtin-rules --no-builtin-variables --print-data-base \
--question --makefile=../../config/Makefile.base 2>/dev/null | \
if [ "" != "raw" ]; then awk -v RS= -F: ' \
Expand Down

0 comments on commit 12b33f6

Please sign in to comment.