Skip to content

Commit

Permalink
feat: add separate config (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: tkrop <[email protected]>
  • Loading branch information
tkrop committed Jan 4, 2024
1 parent 4f6f188 commit 21b323e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion 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].15
GOMAKE ?= github.com/tkrop/[email protected].16
TARGETS := $(shell command -v go-make >/dev/null || \
go install $(GOMAKE) && go-make targets)

Expand Down
46 changes: 24 additions & 22 deletions Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ TARGETS_TEST ?= test-all $(if $(filter $(CODACY),enabled),test-upload,)
TARGETS_LINT ?= lint-leaks? lint-$(CODE_QUALITY) lint-markdown lint-apis \
$(if $(filter $(CODACY),enabled),lint-codacy,)

INIT_MAKE ?= $(FILE_MAKE) $(FILE_VARS)
INIT_MAKE ?= $(notdir $(FILE_MAKE) $(FILE_VARS))
UPDATE_MAKE ?= $(FILE_MAKE) $(FILE_GOLANGCI) $(FILE_MARKDOWN) \
$(FILE_GITLEAKS) $(FILE_CODACY) $(FILE_REVIVE)

Expand Down Expand Up @@ -238,7 +238,7 @@ MOCKS := $(shell for TARGET in $(MOCK_TARGETS); \
# Prepare make targets lists with phony execution.
TARGETS_PUBLISH := $(addprefix publish-, all $(COMMANDS))
TARGETS_TEST_INIT := test-clean init-sources init-hooks
TARGETS_INIT_MAKE := $(addprefix update/,$(INIT_MAKE))
TARGETS_INIT_MAKE := $(addprefix init/,$(INIT_MAKE))
TARGETS_INIT_CODACY := $(addprefix init-, $(CODACY_BINARIES))
TARGETS_LINT_CODACY_CLIENTS := $(addprefix lint-, $(CODACY_CLIENTS))
TARGETS_LINT_CODACY_BINARIES := $(addprefix lint-, $(CODACY_BINARIES))
Expand Down Expand Up @@ -273,9 +273,6 @@ TARGETS_UPDATE_ALL? := udate-go? update-deps? update-make?
TARGETS_UPDATE? := $(filter $(addsuffix ?,$(TARGETS_UPDATE)), \
$(TARGETS_UPDATE_ALL?) $(TARGETS_UPDATE_MAKE?))

# Setup explicit phony make targets to always be executed (others are using ::).
.PHONY:: $(TARGETS_INIT_MAKE)

# Setup docker or podman command.
IMAGE_CMD ?= $(shell command -v docker || command -v podman)
ifndef IMAGE_CMD
Expand Down Expand Up @@ -369,6 +366,18 @@ targets::
}' | sort -d | egrep -v -e '^[^[:alnum:]]'; \
else cat -; fi || true;

#@ create a clone of the base repository to update from.
BASE := [email protected]:tkrop/go-make.git
setup/base::
@$(eval BASEDIR = $(shell mktemp -d)) ( \
trap "rm -rf $${DIR}" INT TERM EXIT; \
while pgrep $(MAKE) > /dev/null; do sleep 1; done; \
rm -rf $${DIR} \
) & \
git clone --no-checkout --depth 2 --single-branch \
--branch main $(BASE) $(BASEDIR) 2> /dev/null; \


#@ pushes the current branch to the same branch of the origin.
push::
@git push --set-upstream origin \
Expand Down Expand Up @@ -535,10 +544,14 @@ $(TARGETS_INIT_CODACY):: init-%:

#@ initialize project by copying config makefile from template.
init-make:: $(TARGETS_INIT_MAKE)
$(TARGETS_INIT_MAKE):: init/%: setup/base
@DIR="$$(pwd)"; FILE="$*"; FILE="$${FILE##$(DIR_CONFIG)}"; \
cd "$(BASEDIR)"; git show HEAD:config/$${FILE} > $${DIR}/$${FILE} 2>/dev/null; \

#@ initialize project by copying Makefile.base from template.
init-make!:: update-base
init-make!:: setup/base
@DIR="$$(pwd)"; cd $(BASEDIR); \
git show HEAD:Makefile.base > $${DIR}/Makefile 2>/dev/null; \
git show HEAD:config/Makefile.base > $${DIR}/Makefile 2>/dev/null; \
( echo -e "<!-- do not change!!! -->\n\n# Makefile"; \
git show HEAD:README.md 2>/dev/null | \
sed -n '/^## Standard/,/^## Terms/p' | sed '1d;$$d'; \
Expand Down Expand Up @@ -1256,17 +1269,17 @@ update/go.mod?:: $(GOBIN)/gomajor

#@ update this build environment to latest version.
update-make:: $(TARGETS_UPDATE_MAKE)
$(TARGETS_UPDATE_MAKE):: update/%: update-base
$(TARGETS_UPDATE_MAKE):: update/%: setup/base
@DIR="$$(pwd)"; FILE="$*"; FILE="$${FILE##$(DIR_CONFIG)}"; \
if [ ! -e "$${DIR}/$${FILE}" ]; then \
echo "info: $${DIR}/$${FILE} (not configured - update skipped)"; \
else cd "$(BASEDIR)"; \
DIFF="$$(diff <(git show HEAD:$${FILE} 2>/dev/null) $${DIR}/$${FILE})"; \
DIFF="$$(diff <(git show HEAD:config/$${FILE} 2>/dev/null) $${DIR}/$${FILE})"; \
if [ -n "$${DIFF}" ]; then \
if [ -n "$$(cd $${DIR}; git diff $${FILE})" ]; then \
echo "info: $${DIR}/$${FILE} (was updated - update blocked)"; \
else echo "info: $${DIR}/$${FILE} (has changed - update executed)"; \
git show HEAD:$${FILE} > $${DIR}/$${FILE} 2>/dev/null; \
git show HEAD:config/$${FILE} > $${DIR}/$${FILE} 2>/dev/null; \
fi; \
else \
echo "info: $${DIR}/$${FILE} (not changed - update skipped)" >/dev/null; \
Expand All @@ -1275,7 +1288,7 @@ $(TARGETS_UPDATE_MAKE):: update/%: update-base

#@ check whether updates for build environment exist.
update-make?:: $(TARGETS_UPDATE_MAKE?)
$(TARGETS_UPDATE_MAKE?):: update/%?: update-base
$(TARGETS_UPDATE_MAKE?):: update/%?: setup/base
@DIR="$$(pwd)"; cd $(BASEDIR); \
if [ ! -e "$${DIR}/$*" ]; then \
echo "info: $* is not tracked"; \
Expand All @@ -1287,17 +1300,6 @@ $(TARGETS_UPDATE_MAKE?):: update/%?: update-base
fi; \
fi; \

#@ create a clone of the base repository to update from.
BASE := [email protected]:tkrop/go-make.git
update-base::
@$(eval BASEDIR = $(shell mktemp -d)) ( \
trap "rm -rf $${DIR}" INT TERM EXIT; \
while pgrep $(MAKE) > /dev/null; do sleep 1; done; \
rm -rf $${DIR} \
) & \
git clone --no-checkout --depth 1 --single-branch \
--branch main $(BASE) $(BASEDIR) 2> /dev/null; \

#@ update all tools required by the project.
update-tools:: $(TARGETS_UPDATE_GO) $(TARGETS_INSTALL_SH) $(TARGETS_INSTALL_NPM)
go mod tidy -compat=${GOVERSION};
Expand Down
8 changes: 7 additions & 1 deletion Makefile.ext
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ bump::
@VERSION="$$(cat VERSION)"; \
sed -i -e "s#\(github.com/tkrop/go-make@v\)[^ ]*#\1$${VERSION}#" Makefile;

commit::
@for FILE in $$(find config -type f ! -name "Makefile.vars"); do \
if [ -n "$$(diff "$${FILE}" "$${FILE#*/}")" ]; then \
echo "error: $${FILE} (not synchronized)" > "/dev/stderr"; exit -1; \
fi; \
done;

install:: install-go-make.config;
install-go-make.config:: uninstall-go-make.config
mkdir -p $(GOBIN)/go-make.config;
cp -rf . $(GOBIN)/go-make.config;

uninstall:: uninstall-go-make.config
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.15
0.0.16
7 changes: 4 additions & 3 deletions internal/make/fixtures/targets-trace.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Makefile.base:364: target 'targets' does not exist
Makefile.base:361: target 'targets' does not exist
make --no-builtin-rules --no-builtin-variables --print-data-base \
--question --makefile=Makefile.base 2>/dev/null | \
if [ "" != "raw" ]; then awk -v RS= -F: ' \
Expand Down Expand Up @@ -38,6 +38,8 @@ init-gosec
init-hooks
init-make
init-make!
init/Makefile
init/Makefile.vars
init-sources
init-staticcheck
install
Expand Down Expand Up @@ -92,6 +94,7 @@ run-clean
run-clean-aws
run-clean-db
run-db
setup/base
show
targets
test
Expand Down Expand Up @@ -127,7 +130,6 @@ update
update?
update-all
update-all?
update-base
update-deadcode
update-deps
update-deps?
Expand Down Expand Up @@ -157,7 +159,6 @@ update/.golangci.yaml
update/.golangci.yaml?
update/Makefile
update/Makefile?
update/Makefile.vars
update/.markdownlint.yaml
update/.markdownlint.yaml?
update/revive.toml
Expand Down
5 changes: 3 additions & 2 deletions internal/make/fixtures/targets.out
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ init-gosec
init-hooks
init-make
init-make!
init/Makefile
init/Makefile.vars
init-sources
init-staticcheck
install
Expand Down Expand Up @@ -84,6 +86,7 @@ run-clean
run-clean-aws
run-clean-db
run-db
setup/base
show
targets
test
Expand Down Expand Up @@ -119,7 +122,6 @@ update
update?
update-all
update-all?
update-base
update-deadcode
update-deps
update-deps?
Expand Down Expand Up @@ -149,7 +151,6 @@ update/.golangci.yaml
update/.golangci.yaml?
update/Makefile
update/Makefile?
update/Makefile.vars
update/.markdownlint.yaml
update/.markdownlint.yaml?
update/revive.toml
Expand Down

0 comments on commit 21b323e

Please sign in to comment.