Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generic targets (#3) #3

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ jobs:
with:
path-to-profile: ./build/test-all.cover

- name: Release and publish
- name: Release new version
env:
GH_TOKEN: ${{ github.token }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |-
make --file=Makefile.base --trace release && \
make --file=Makefile.base --trace publish
- name: Publish new version
env:
GH_TOKEN: ${{ github.token }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |-
make --file=Makefile.base --trace publish || true
5 changes: 2 additions & 3 deletions 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].10
GOMAKE ?= github.com/tkrop/[email protected].11
TARGETS := $(shell command -v go-make >/dev/null || \
go install $(GOMAKE) && go-make targets)

Expand All @@ -17,6 +17,5 @@ TARGETS := $(shell command -v go-make >/dev/null || \

# Delegate all targets to go-make in one call.
# TODO: consider solution that does not delegate local goals.
$(eval $(lastwords $(MAKECMDGOALS)):;@:)
all $(firstword $(MAKECMDGOALS))::
$(firstword $(MAKECMDGOALS) all)::
$(GOBIN)/go-make $(MAKEFLAGS) $(MAKECMDGOALS);
30 changes: 19 additions & 11 deletions Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CODE_QUALITY ?= base
TEST_TIMEOUT ?= 10s

# Function to search default config files
search-default = $(firstword $(wildcard $(1)) $(wildcard $(DIR_CONFIG)/$(1)))
search-default = $(firstword $(wildcard $(1)) $(wildcard $(DIR_CONFIG)$(1)))

FILE_MAKE ?= $(call search-default,Makefile)
FILE_VARS ?= $(call search-default,Makefile.vars)
Expand Down Expand Up @@ -373,10 +373,13 @@ targets::
push::
@git push --set-upstream origin \
$$(git branch 2> /dev/null | sed -e '/^[^*]/d; s/* \(.*\)/\1/');
#@ pushes the latest changes adding it to the previous commit of the origin.
#@ pushes the latest changes to the previous commit of the origin.
fix::
@git commit --amend --no-edit && git push --force;
#@ pushes the latest changes adding it to the previous commit updating the message of the origin.
#@ pushes the latest changes to the previous commit of the origin without verifying them.
fix-no-verify::
@git commit --amend --no-edit --no-verify && git push --force;
#@ pushes the latest changes to the previous commit of the origin updating the message.
fix-update::
@git commit --amend && git push --force;

Expand Down Expand Up @@ -1253,14 +1256,19 @@ update/go.mod?: $(GOBIN)/gomajor
#@ update this build environment to latest version.
update-make:: $(TARGETS_UPDATE_MAKE)
$(TARGETS_UPDATE_MAKE):: update/%: update-base
@DIR="$$(pwd)"; cd $(BASEDIR); \
if [ ! -e "$${DIR}/$*" ]; then touch "$${DIR}/$*"; fi; \
DIFF="$$(diff <(git show HEAD:$* 2>/dev/null) $${DIR}/$*)"; \
if [ -n "$${DIFF}" ]; then \
if [ -n "$$(cd $${DIR}; git diff $*)" ]; then \
echo "info: $* is blocked (has been changed)"; \
else echo "info: $* is updated"; \
git show HEAD:$* > $${DIR}/$* 2>/dev/null; \
@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})"; \
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; \
fi; \
else \
echo "info: $${DIR}/$${FILE} (not changed - update skipped)" >/dev/null; \
fi; \
fi; \

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ also [Makefile](Makefile)):

```Makefile
GOBIN ?= $(shell go env GOPATH)/bin
GOMAKE ?= github.com/tkrop/go-make@v0.0.10
GOMAKE ?= github.com/tkrop/go-make@latest
TARGETS := $(shell command -v go-make >/dev/null || \
go install $(GOMAKE) && go-make targets)

# Declare all targets phony to make them available for auto-completion.
.PHONY: $(TARGETS)

# Delegate all targets to go-make in one call.
$(eval $(lastwords $(MAKECMDGOALS)):;@:)
$(firstword $(MAKECMDGOALS))::
# TODO: consider solution that does not delegate local goals.
$(firstword $(MAKECMDGOALS) all)::
$(GOBIN)/go-make $(MAKEFLAGS) $(MAKECMDGOALS);
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.10
0.0.11
1 change: 1 addition & 0 deletions internal/make/fixtures/targets-trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ clean-run-aws
clean-run-db
commit
fix
fix-no-verify
fix-update
go.sum
help
Expand Down
1 change: 1 addition & 0 deletions internal/make/fixtures/targets.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ clean-run-aws
clean-run-db
commit
fix
fix-no-verify
fix-update
go.sum
help
Expand Down
2 changes: 1 addition & 1 deletion internal/make/make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ var (
// regexMatchTestDir is the regular expression that is used to remove the
// test execution path dependent parts.
regexMatchTestDir = regexp.MustCompile(
"(?m)/?/tmp/go-build.*/make.test.config/")
"(?m)/tmp/go-build.*/make.test.config/")
// regexMatchBuildDir is the regular expression that is used to remove the
// build path dependent parts.
//lint:ignore S1007 // Escaping makes it less readable.
Expand Down