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: double reset (#18) #18

Merged
merged 1 commit into from
Jan 11, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.project
.vscode

build
run
Expand Down
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].24
GOMAKE ?= github.com/tkrop/[email protected].25
TARGETS := $(shell command -v go-make >/dev/null || \
go install $(GOMAKE) && go-make targets)

Expand Down
32 changes: 16 additions & 16 deletions Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -64,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].24
github.com/tkrop/[email protected].25
TOOLS_SH := $(TOOLS_SH) \
github.com/anchore/syft \
github.com/anchore/grype
Expand Down Expand Up @@ -145,10 +145,10 @@ AWS_IMAGE ?= localstack/localstack:$(AWS_VERSION)

# Setup codacy integration.
CODACY ?= enabled
ifdef CDP_PULL_REQUEST_NUMBER
CODACY_CONTINUE ?= true
else
ifeq ($(IMAGE_VERSION),snapshot)
CODACY_CONTINUE ?= false
else
CODACY_CONTINUE ?= true
endif
CODACY_PROVIDER ?= ghe
CODACY_USER ?= $(GITORGNAME)
Expand All @@ -163,7 +163,7 @@ CODACY_STATICCHECK_VERSION ?= 3.0.12
upper = $(shell echo "$(1)" | tr '[:lower:]' '[:upper:]')


# Default target list for all and cdp builds.
# Default target list for all and pipeline builds.
TARGETS_ALL ?= init test lint build image
TARGETS_INIT ?= init-hooks init-go $(if $(filter $(CODACY),enabled),init-codacy,)
TARGETS_CLEAN ?= clean-build
Expand Down Expand Up @@ -977,16 +977,16 @@ image:: $(if $(filter $(IMAGE_PUSH),never),,image-push)
image-build:: $(TARGETS_IMAGE_BUILD)

setup-image-file = \
FILE="$*"; IMAGE=$(IMAGE); \
PREFIX="$$(basename "$${FILE%$(FILE_CONTAINER)*}")"; \
SUFFIX="$$(echo $${FILE\#*$(FILE_CONTAINER)} | sed "s/^[^[:alnum:]]*//")"; \
INFIX="$${SUFFIX:-$${PREFIX}}"; \
if [ -n "$${INFIX}" ]; then \
IMAGE="$${IMAGE/:/-$${INFIX}:}"; \
fi;
FILE="$*"; IMAGE=$(IMAGE); \
PREFIX="$$(basename "$${FILE%$(FILE_CONTAINER)*}")"; \
SUFFIX="$$(echo $${FILE\#*$(FILE_CONTAINER)} | sed "s/^[^[:alnum:]]*//")"; \
INFIX="$${SUFFIX:-$${PREFIX}}"; \
if [ -n "$${INFIX}" ]; then \
IMAGE="$${IMAGE/:/-$${INFIX}:}"; \
fi

$(TARGETS_IMAGE_BUILD):: image-build/%: build-linux
@$(call setup-image-file $*) \
@$(call setup-image-file $*); \
if [ "$(IMAGE_PUSH)" == "never" ]; then \
echo "We never build images, aborting [$${IMAGE}]."; exit 0; \
fi; \
Expand All @@ -1004,12 +1004,12 @@ $(TARGETS_IMAGE_BUILD):: image-build/%: build-linux
#@ push contianer images - if setup and allowed.
image-push:: $(TARGETS_IMAGE_PUSH)
$(TARGETS_IMAGE_PUSH):: image-push/%: image-build/%
@$(call setup-image-file $*) \
@$(call setup-image-file $*); VERSION="${IMAGE##*:}; \
if [ "$(IMAGE_PUSH)" == "never" ]; then \
echo "We never push images, aborting [$${IMAGE}]."; exit 0; \
elif [ "$(IMAGE_VERSION)" == "snapshot" ]; then \
elif [ "$${VERSION}" == "snapshot" ]; then \
echo "We never push snapshot images, aborting [$${IMAGE}]."; exit 0; \
elif [ -n "$(CDP_PULL_REQUEST_NUMBER)" -a "$(IMAGE_PUSH)" != "pulls" ]; then \
elif [[ "$${VERSION}" =~ "^pr-.*$$" ]] && [ "$(IMAGE_PUSH)" != "pulls" ]; then \
echo "We never push pull request images, aborting [$${IMAGE}]."; exit 0; \
fi; \
$(IMAGE_CMD) push $${IMAGE}; \
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.24
0.0.25
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].24
GOMAKE ?= github.com/tkrop/[email protected].25
TARGETS := $(shell command -v go-make >/dev/null || \
go install $(GOMAKE) && go-make targets)

Expand Down
32 changes: 16 additions & 16 deletions config/Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -64,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].24
github.com/tkrop/[email protected].25
TOOLS_SH := $(TOOLS_SH) \
github.com/anchore/syft \
github.com/anchore/grype
Expand Down Expand Up @@ -145,10 +145,10 @@ AWS_IMAGE ?= localstack/localstack:$(AWS_VERSION)

# Setup codacy integration.
CODACY ?= enabled
ifdef CDP_PULL_REQUEST_NUMBER
CODACY_CONTINUE ?= true
else
ifeq ($(IMAGE_VERSION),snapshot)
CODACY_CONTINUE ?= false
else
CODACY_CONTINUE ?= true
endif
CODACY_PROVIDER ?= ghe
CODACY_USER ?= $(GITORGNAME)
Expand All @@ -163,7 +163,7 @@ CODACY_STATICCHECK_VERSION ?= 3.0.12
upper = $(shell echo "$(1)" | tr '[:lower:]' '[:upper:]')


# Default target list for all and cdp builds.
# Default target list for all and pipeline builds.
TARGETS_ALL ?= init test lint build image
TARGETS_INIT ?= init-hooks init-go $(if $(filter $(CODACY),enabled),init-codacy,)
TARGETS_CLEAN ?= clean-build
Expand Down Expand Up @@ -977,16 +977,16 @@ image:: $(if $(filter $(IMAGE_PUSH),never),,image-push)
image-build:: $(TARGETS_IMAGE_BUILD)

setup-image-file = \
FILE="$*"; IMAGE=$(IMAGE); \
PREFIX="$$(basename "$${FILE%$(FILE_CONTAINER)*}")"; \
SUFFIX="$$(echo $${FILE\#*$(FILE_CONTAINER)} | sed "s/^[^[:alnum:]]*//")"; \
INFIX="$${SUFFIX:-$${PREFIX}}"; \
if [ -n "$${INFIX}" ]; then \
IMAGE="$${IMAGE/:/-$${INFIX}:}"; \
fi;
FILE="$*"; IMAGE=$(IMAGE); \
PREFIX="$$(basename "$${FILE%$(FILE_CONTAINER)*}")"; \
SUFFIX="$$(echo $${FILE\#*$(FILE_CONTAINER)} | sed "s/^[^[:alnum:]]*//")"; \
INFIX="$${SUFFIX:-$${PREFIX}}"; \
if [ -n "$${INFIX}" ]; then \
IMAGE="$${IMAGE/:/-$${INFIX}:}"; \
fi

$(TARGETS_IMAGE_BUILD):: image-build/%: build-linux
@$(call setup-image-file $*) \
@$(call setup-image-file $*); \
if [ "$(IMAGE_PUSH)" == "never" ]; then \
echo "We never build images, aborting [$${IMAGE}]."; exit 0; \
fi; \
Expand All @@ -1004,12 +1004,12 @@ $(TARGETS_IMAGE_BUILD):: image-build/%: build-linux
#@ push contianer images - if setup and allowed.
image-push:: $(TARGETS_IMAGE_PUSH)
$(TARGETS_IMAGE_PUSH):: image-push/%: image-build/%
@$(call setup-image-file $*) \
@$(call setup-image-file $*); VERSION="${IMAGE##*:}; \
if [ "$(IMAGE_PUSH)" == "never" ]; then \
echo "We never push images, aborting [$${IMAGE}]."; exit 0; \
elif [ "$(IMAGE_VERSION)" == "snapshot" ]; then \
elif [ "$${VERSION}" == "snapshot" ]; then \
echo "We never push snapshot images, aborting [$${IMAGE}]."; exit 0; \
elif [ -n "$(CDP_PULL_REQUEST_NUMBER)" -a "$(IMAGE_PUSH)" != "pulls" ]; then \
elif [[ "$${VERSION}" =~ "^pr-.*$$" ]] && [ "$(IMAGE_PUSH)" != "pulls" ]; then \
echo "We never push pull request images, aborting [$${IMAGE}]."; exit 0; \
fi; \
$(IMAGE_CMD) push $${IMAGE}; \
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (*defaultExecutor) Exec(
//#nosec G204 -- caller ensures safe commands
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir, cmd.Env = dir, os.Environ()
cmd.Env = append(cmd.Env, "MAKE=go-make")
cmd.Env = append(cmd.Env, "MAKE=make")
cmd.Stdout, cmd.Stderr = stdout, stderr

return cmd.Run() //nolint:wrapcheck // checked on next layer
Expand Down
59 changes: 39 additions & 20 deletions internal/make/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var (
// Base command array for `git rev-parse HEAD` arguments.
cmdGitHashHead = []string{"git", "rev-parse", "HEAD"}
// Base command array for `git log --max-count=1 --format="%H"` arguments.
cmdGitHashNow = []string{"git", "log", "--max-count=1", "--format=\"%H\""}
cmdGitHashNow = []string{"git", "log", "--max-count=1", "--format=%H"}
)

// CmdGitClone creates the argument array of a `git clone` command of the given
Expand Down Expand Up @@ -145,12 +145,6 @@ func CmdMakeTargets(file string, args ...string) []string {
type GoMake struct {
// Info provides the build information of go-make.
Info *info.Info
// The directory of the go-make command.
MakeDir string
// The actual working directory.
WorkDir string
// The path to the go-make command Makefile.
Makefile string
// Executor provides the command executor.
Executor cmd.Executor
// Logger provides the logger.
Expand All @@ -159,6 +153,13 @@ type GoMake struct {
Stdout io.Writer
// Stderr provides the standard error writer.
Stderr io.Writer

// The actual working directory.
WorkDir string
// The directory of the go-make command.
MakeDir string
// The path to the go-make command Makefile.
Makefile string
// Trace provides the flags to trace commands.
Trace bool
}
Expand All @@ -168,16 +169,8 @@ type GoMake struct {
func NewGoMake(
stdout, stderr io.Writer, info *info.Info,
) *GoMake {
//revive:disable-next-line:redefines-builtin-id // Is package name.
make, _ := os.Executable() //nolint:predeclared // Is package name.
makeDir := make + ".config"
workdir, _ := os.Getwd()

return &GoMake{
Info: info,
MakeDir: makeDir,
WorkDir: workdir,
Makefile: filepath.Join(makeDir, Makefile),
Executor: cmd.NewExecutor(),
Logger: log.NewLogger(),
Stdout: stdout,
Expand Down Expand Up @@ -318,20 +311,46 @@ func (gm *GoMake) exec(
return nil
}

func (gm *GoMake) Setup(version string) *GoMake {
if version == "" {
if gm.Info != nil && gm.Info.Version == gm.Info.Revision {
version = gm.Info.Version
// } else {
// version = "latest"
}
}

// ---revive:disable-next-line:redefines-builtin-id // Is package name.
gm.WorkDir, _ = os.Getwd()
if version != "" {
gm.MakeDir = filepath.Join(os.Getenv("GOPATH"),
"pkg", "mod", gm.Info.Path+"@"+version, "config")
} else {
path, _ := os.Executable()
gm.MakeDir = path + ".config"
}
gm.Makefile = filepath.Join(gm.MakeDir, Makefile)

return gm
}

// Make runs the go-make command with given arguments and return exit code.
func (gm *GoMake) Make(args ...string) (int, error) {
for _, arg := range args {
switch arg {
case "--trace":
switch {
case arg == "--trace":
gm.Logger.Call(gm.Stderr, args...)
gm.Logger.Info(gm.Stderr, gm.Info, false)
gm.Trace = true

case "--version":
case strings.HasPrefix(arg, "--version="):
gm.Setup(arg[10:])

case arg == "--version":
gm.Logger.Info(gm.Stdout, gm.Info, true)
return 0, nil

case "--completion=bash":
case strings.HasPrefix(arg, "--completion"):
gm.Logger.Message(gm.Stdout, BashCompletion)
return 0, nil
}
Expand Down Expand Up @@ -381,7 +400,7 @@ func Make(
// output that creates hard to validate output.
// NewMakeFilter(stdout), NewMakeFilter(stderr), info,
stdout, stderr, info,
).Make(args[1:]...)
).Setup("").Make(args[1:]...)

return exit
}
6 changes: 3 additions & 3 deletions internal/make/make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var (

// infoTag with version and revision hash from git.
infoTag = info.NewInfo(goMakePath,
"v1.1.1",
"v1.1.1",
"v0.0.24",
"v0.0.24",
"2023-11-14T13:02:46+01:00",
"2023-11-10T16:22:54+01:00",
false)
Expand Down Expand Up @@ -114,7 +114,7 @@ func GoMakeSetup(
mocks.GetArg("stdout").(io.Writer),
mocks.GetArg("stderr").(io.Writer),
param.info,
)
).Setup("")

if param.goMakeDir == "" {
param.goMakeDir = goMakeDirExist
Expand Down