Skip to content

Commit

Permalink
fix: revision compare bug (#0)
Browse files Browse the repository at this point in the history
Signed-off-by: tkrop <[email protected]>
  • Loading branch information
tkrop committed Dec 14, 2023
1 parent 0afbfc5 commit 7b1d22c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
13 changes: 6 additions & 7 deletions Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,18 @@ fix-update:

#@ <version|major|minor|patch[+-]?> # update version and prepare release of the software.
bump:
@if [ -z "$(RUNARGS)" ]; then \
echo "error: missing new version"; exit 1; \
elif [[ "$(RUNARGS)" =~ ^(major|minor|patch|[.+-]*)[+-]?$$ ]]; then \
VERSION="$$(awk -v arg=$(RUNARGS) '{ \
@if [ -z "$(RUNARGS)" ]; then ARGS="patch"; else ARGS="$(RUNARGS)"; fi; \
if [[ "$${ARGS}" =~ ^(major|minor|patch|[.+-]*)[+-]?$$ ]]; then \
VERSION="$$(awk -v arg=$${ARGS} '{ \
op["major"] = 1; op["minor"] = 2; op["patch"] = 3; \
if ((pos = op[substr(arg,1,5)]) == 0) { pos = length(arg) }; \
patsplit($$0, v, "[0-9]*", seps); len = length(seps); \
if (arg !~ "-$$") {v[pos]++ } else { v[pos]-- }; \
for (i = 1; i < len; i++) { printf("%d%s", v[i], seps[i]) } \
}' VERSION)"; \
elif ! [[ "$(RUNARGS)" =~ ^[0-9]+(\.[0-9]+){0,2}(-.*)?$$ ]]; then \
echo "error: invalid new version [$(RUNARGS)]"; exit 1; \
else VERSION="$(RUNARGS)"; fi; echo $${VERSION} >VERSION; \
elif ! [[ "$${ARGS}" =~ ^[0-9]+(\.[0-9]+){0,2}(-.*)?$$ ]]; then \
echo "error: invalid new version [$${ARGS}]"; exit 1; \
else VERSION="$${ARGS}"; fi; echo $${VERSION} >VERSION; \
echo "Bumped version to $${VERSION} for auto release!"; \


Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.5
0.0.6
2 changes: 0 additions & 2 deletions internal/make/fixtures/targets-trace.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
make[1]: Entering directory 'go-make/internal/make'
Makefile.base:383: target 'targets' does not exist
make --no-builtin-rules --no-builtin-variables --print-data-base \
--question --makefile=Makefile.base 2>/dev/null | \
Expand Down Expand Up @@ -170,4 +169,3 @@ update/revive.toml?
update-tools
update-vegeta
update-zally
make[1]: Leaving directory 'go-make/internal/make'
2 changes: 0 additions & 2 deletions internal/make/fixtures/targets.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
make[1]: Entering directory 'go-make/internal/make'
all
all-clean
build
Expand Down Expand Up @@ -162,4 +161,3 @@ update/revive.toml?
update-tools
update-vegeta
update-zally
make[1]: Leaving directory 'go-make/internal/make'
6 changes: 3 additions & 3 deletions internal/make/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ func (gm *GoMake) findRevision() (string, error) {
CmdGitHashHead()...); err != nil {
return "", err
}
return builder.String(), nil
return strings.TrimSpace(builder.String()), nil
} else if gm.Info.Version == gm.Info.Revision {
builder := strings.Builder{}
if err := gm.exec(&builder, gm.Stderr, gm.MakeDir,
CmdGitHashTag(gm.Info.Revision)...); err != nil {
return "", err
}
return builder.String(), nil
return strings.TrimSpace(builder.String()), nil
}
return gm.Info.Revision, nil
}
Expand All @@ -275,7 +275,7 @@ func (gm *GoMake) isOnRevision(hash string) (bool, error) {
CmdGitHashNow()...); err != nil {
return false, err
}
return strings.HasPrefix(builder.String(), hash), nil
return hash == strings.TrimSpace(builder.String()), nil
}

// makeTargets executes the provided make targets.
Expand Down
38 changes: 38 additions & 0 deletions internal/make/make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
goMakeHTTP = "https://github.com/tkrop/go-make.git"
// revisionHead contains an arbitrary head revision.
revisionHead = "1b66f320c950b25fa63b81fd4e660c5d1f9d758e"
// revisionHeadExt contains an arbitrary untrimmed revision.
revisionHeadExt = "1b66f320c950b25fa63b81fd4e660c5d1f9d758e\n"
// HeadRevision contains an arbitrary default revision.
revisionDefault = "c0a7f81b82937ffe379ac39ece2925fa4d19fd40"
// revisionOther contains an arbitrary different revision.
Expand Down Expand Up @@ -369,6 +371,39 @@ var testMakeParams = map[string]MakeParams{
args: argsTarget,
goMakeDir: goMakeDirNew,
},
"clone go-make head ext-1 to run target": {
mockSetup: mock.Chain(
Exec("stderr", "stderr", dirExec,
make.CmdGitClone(goMakeGit, goMakeDirNew), nil, "", ""),
Exec("builder", "stderr", goMakeDirNew,
make.CmdGitHashHead(), nil, revisionHead, ""),
Exec("builder", "stderr", goMakeDirNew,
make.CmdGitHashNow(), nil, revisionHeadExt, ""),
Exec("stdout", "stderr", dirExec,
make.CmdMakeTargets(make.Makefile, argsTarget...),
nil, "", ""),
),
info: infoHead,
args: argsTarget,
goMakeDir: goMakeDirNew,
},

"clone go-make head ext-2 to run target": {
mockSetup: mock.Chain(
Exec("stderr", "stderr", dirExec,
make.CmdGitClone(goMakeGit, goMakeDirNew), nil, "", ""),
Exec("builder", "stderr", goMakeDirNew,
make.CmdGitHashHead(), nil, revisionHeadExt, ""),
Exec("builder", "stderr", goMakeDirNew,
make.CmdGitHashNow(), nil, revisionHead, ""),
Exec("stdout", "stderr", dirExec,
make.CmdMakeTargets(make.Makefile, argsTarget...),
nil, "", ""),
),
info: infoHead,
args: argsTarget,
goMakeDir: goMakeDirNew,
},

"clone go-make hash to run target": {
mockSetup: mock.Chain(
Expand Down Expand Up @@ -808,6 +843,8 @@ var (
// build path dependent parts.
regexMatchSourceDir = regexp.MustCompile( //nolint:gosimple // Just wrong!
"(?m)(['\\[])([^'\\]]*/)(go-make/[^'\\]]*)(['\\]])")
regexMatchMakeLog = regexp.MustCompile( //nolint:gosimple // Just wrong!
"(?m)make\\[[0-9]*\\]: (Entering|Leaving) directory [^\\n]*\\n")

replacerFixture = strings.NewReplacer(
"{{GOVERSION}}", runtime.Version()[2:],
Expand All @@ -816,6 +853,7 @@ var (
)

func FilterMakeOutput(str string) string {
str = regexMatchMakeLog.ReplaceAllString(str, "")
str = regexMatchTestDir.ReplaceAllString(str, "")
str = regexMatchSourceDir.ReplaceAllString(str, "$1$3$4")
return str
Expand Down

0 comments on commit 7b1d22c

Please sign in to comment.