Skip to content

Commit

Permalink
feat: add compat test action (#102)
Browse files Browse the repository at this point in the history
Signed-off-by: Tronje Krop <[email protected]>
  • Loading branch information
tkrop committed Sep 24, 2024
1 parent 8be0ea3 commit 50c2c96
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 58 deletions.
100 changes: 96 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.23.1

- name: Checkout code
uses: actions/checkout@v4

- name: Build and tests
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
Expand All @@ -22,3 +22,95 @@ jobs:
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: ./build/test-all.cover

bash:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23.1

- name: Setup Npm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Checkout code
uses: actions/checkout@v4

- name: Run Bash compatibility tests
env:
BASH_COMPAT: 3.2
run: make --file=config/Makefile.base --trace test-self

linux:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23.1

- name: Setup Npm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Run Bash compatibility tests
run: |-
make --version
make --file=config/Makefile.base --trace test-self
macos:
runs-on: macos-latest
steps:
# - name: Set up Docker
# uses: crazy-max/ghaction-setup-docker@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23.1

- name: Checkout code
uses: actions/checkout@v4

- name: Run MacOS compatibility tests
env:
BASH_COMPAT: 3.2
run: |-
brew install make;
export PATH="/opt/homebrew/opt/make/libexec/gnubin:${PATH}";
make --version;
make --file=config/Makefile.base --trace test-self
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23.1

- name: Checkout code
uses: actions/checkout@v4

- name: Release new version
env:
GH_TOKEN: ${{ github.token }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |-
make --file=config/Makefile.base --trace version-release
- name: Publish new version
env:
GH_TOKEN: ${{ github.token }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |-
sleep 60 && make --file=config/Makefile.base --trace version-publish || true
29 changes: 0 additions & 29 deletions .github/workflows/release.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export GOPATH ?= $(shell $(GO) env GOPATH)
export GOBIN ?= $(GOPATH)/bin

# Setup go-make version to use desired build and config scripts.
GOMAKE_DEP ?= github.com/tkrop/[email protected].100
GOMAKE_DEP ?= github.com/tkrop/[email protected].101
INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto
# Request targets from go-make targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.100
0.0.101
2 changes: 1 addition & 1 deletion config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export GOPATH ?= $(shell $(GO) env GOPATH)
export GOBIN ?= $(GOPATH)/bin

# Setup go-make version to use desired build and config scripts.
GOMAKE_DEP ?= github.com/tkrop/[email protected].100
GOMAKE_DEP ?= github.com/tkrop/[email protected].101
INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto
# Request targets from go-make targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
Expand Down
49 changes: 35 additions & 14 deletions config/Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ COLOR-target := 1;96

# Finding: \$\(call *[ce]*msg
ts = $(shell date '+%F %T.%3N')
eq = $(if $(and $(findstring x$(1),x$(2)),$(findstring x$(2),x$(1))),$(3),$(4))
xifeq = $(if $(and $(findstring x$(1),x$(2)),$(findstring x$(2),x$(1))),$(3),$(4))
msg = $(strip \033[$(COLOR-$(1))m$(2)\033[0m $(3))
cmsg = $(ts) $(call msg,$(1),$(1):,$(2))
emsg = $(if $(2),echo -e "$(ts) $(call msg,$(1),$(1):,$(2))" > /dev/stderr)
dmsg = $(if $(findstring --trace,$(MAKEFLAGS)),$(call emsg,$(1),$(2)),echo -n)

escape = $(subst $$,\$$,$(subst ",\",$(subst \",\\",$(1))))
cerror = $(if $(1),$(error $(shell $(call emsg,error,$(1)))))
cinfo = $(shell $(call emsg,info,$(1)))
cdebug = $(shell $(call dmsg,debug,$(1)))

# Check whether bash version is higher or equal version 3.2 to be compatible.
Expand All @@ -40,9 +41,15 @@ ifneq ($(shell echo $${BASH_VERSION} | grep -E -v "^([4-9]+|3\.2)"),)
endif
# Check whether bash is running in minmal compatibility mode for testing.
ifdef BASH_COMPAT
$(shell $(call emsg,info,bash compatibility mode set [$(BASH_COMPAT)]))
$(call cdebug,bash compatibility mode set [$(BASH_COMPAT)])
endif

path-setup = $(shell \
if [ "$(1)" == "opt" ]; then \
XPATH="$(shell brew --prefix)/$(1)/$(2)/libexec/gnubin"; \
else XPATH="$(shell brew --prefix)/$(1)"; fi; \
test ! -e "$${XPATH}/$(3)" && brew install $(2) >&2; \
echo -n "$${XPATH}:$(4)")
# System depdendent helper functions.
ifeq ("$(shell uname)","Linux")
uname-all := uname --all
Expand All @@ -52,11 +59,18 @@ else ifeq ($(shell uname),Darwin)
uname-all := uname -a
rm-verbose-force := rm -vf
rm-verbose-force-recursive := rm -vrf
export PATH := $(call path-setup,opt,coreutils,ls,$(PATH))
export PATH := $(call path-setup,opt,findutils,find,$(PATH))
export PATH := $(call path-setup,bin,bash,bash,$(PATH))
export PATH := $(call path-setup,opt,gawk,awk,$(PATH))
export PATH := $(call path-setup,opt,make,make,$(PATH))
else
$(call cerror,unsupported operating system [$(shell $(uname-all))])
endif
# Log execution environment for debugging.
$(call cdebug,$(shell $(uname-all)))
$(call cdebug,using BASH [$${0} - $${BASH_VERSION}])
$(call cdebug,using PATH [$(shell echo -n "$${PATH}")])

# Helper function to find and remove source files.
find-all = find $(1) ! -path "./run/*" ! -path "./build/*" \( $(2) \) 2>/dev/null | \
Expand Down Expand Up @@ -99,7 +113,7 @@ else
BUILD_VERSION ?= $(VERSION)
endif

mod-readonly = $(call eq,$(IMAGE_VERSION),snapshot,,-mod=readonly)
mod-readonly = $(call xifeq,$(IMAGE_VERSION),snapshot,,-mod=readonly)

# Setup default variables for building, linking, and installing.
LDFLAGS ?=
Expand Down Expand Up @@ -175,6 +189,11 @@ go-install-module = \
$(call go-install,$(call go-pkg,$(TOOLS_GO),module,^$(1)$$,,$(2)))
go-install = \
$(GO) install $(INSTALL_FLAGS) "$(1)"
# Function to determine whether to filter go-make targets.
go-make-filter = $(call xifeq,$(shell if [ ! -f "$(GOBIN)/go-make" ]; then \
echo "(devel)"; else $(GO) version -m "$(GOBIN)/go-make" | \
grep -E "^\s*(mod|dep)\s*github.com/tkrop/go-make" | cut -f 4; fi), \
(devel),%-go-make,)

# Function for determining the actual version of a go package from downloading.
VERSION_REGEX := 's/.*"Path":\s*"([^"]*)".*"Version":\s*"([^"]*)".*/\1@\2/g'
Expand Down Expand Up @@ -224,7 +243,7 @@ go-pkg = $(shell awk -v mode="$(2)" -v filter="$(3)" \


# Setup go-make to use desired build and config scripts.
GOMAKE_DEP := github.com/tkrop/[email protected].100
GOMAKE_DEP := github.com/tkrop/[email protected].101
GOMAKE_MAKEFILE := $(realpath $(firstword $(MAKEFILE_LIST)))
GOMAKE_MAKEFILES := $(GOMAKE_MAKEFILE) \
$(wildcard Makefile.vars) $(wildcard Makefile.ext)
Expand Down Expand Up @@ -460,12 +479,9 @@ CMDARGS ?= $(shell awk '{ split("$(CMDWORDS)",seps); \
ARGS ?=
ifdef CMDARGS
ARGS := $(strip $(CMDARGS) $(ARGS))
$(shell if [ -n "$(ARGS)" ]; then \
$(call emsg,info,captured arguments [$(ARGS)]); \
fi)
$(eval $(subst :,\:,$(CMDARGS))::;@:)
endif

$(call cinfo,make $(filter-out $(ARGS),$(MAKECMDGOALS)) [$(ARGS)])

# Optimized generation of mocks.
gen-mocks = \
Expand Down Expand Up @@ -524,22 +540,29 @@ TARGETS_UNINSTALL_GO := $(addprefix uninstall-, $(COMMANDS_GO))
TARGETS_UNINSTALL_SH := $(addprefix uninstall-, $(COMMANDS_SH))
TARGETS_UNINSTALL_NPM := $(addprefix uninstall-, $(TOOLS_NPM:-cli=))
TARGETS_UNINSTALL_CODACY := $(addprefix uninstall-codacy-, $(CODACY_BINARIES))
TARGETS_UNINSTALL_ALL := $(TARGETS_UNINSTALL) $(TARGETS_UNINSTALL_GO) \
$(TARGETS_UNINSTALL_SH) $(TARGETS_UNINSTALL_NPM) $(TARGETS_UNINSTALL_CODACY)
# TARGETS_UNINSTALL_ALL := $(TARGETS_UNINSTALL) $(TARGETS_UNINSTALL_GO) \
# $(TARGETS_UNINSTALL_SH) $(TARGETS_UNINSTALL_NPM) $(TARGETS_UNINSTALL_CODACY)
TARGETS_UNINSTALL_ALL := $(filter-out $(go-make-filter), \
$(TARGETS_UNINSTALL) $(TARGETS_UNINSTALL_GO) $(TARGETS_UNINSTALL_SH) \
$(TARGETS_UNINSTALL_NPM) $(TARGETS_UNINSTALL_CODACY))
TARGETS_RUN := $(addprefix run-, $(COMMANDS))
TARGETS_RUN_GO := $(addprefix run-go-, $(COMMANDS))
TARGETS_RUN_IMAGE := $(addprefix run-image-, $(COMMANDS))
TARGETS_RUN_CLEAN := $(addprefix run-clean-, $(COMMANDS) db aws)
TARGETS_CLEAN_ALL := clean-init $(TARGETS_CLEAN) clean-run $(TARGETS_UNINSTALL_ALL)
TARGETS_CLEAN_RUN := $(addprefix clean-run-, $(COMMANDS) db aws)
TARGETS_UPDATE_GO := $(addprefix update-,$(sort $(COMMANDS_GO) go-make))
TARGETS_UPDATE_GO := $(addprefix update-,$(COMMANDS_GO))
TARGETS_UPDATE_MAKE := $(addprefix update/,$(UPDATE_MAKE))
TARGETS_UPDATE_MAKE? := $(addsuffix ?,$(TARGETS_UPDATE_MAKE))
TARGETS_UPDATE_ALL := update-go update-deps update-tools update-make
TARGETS_UPDATE_ALL? := update-go? update-deps? update-make?
TARGETS_UPDATE? := $(filter $(addsuffix ?,$(TARGETS_UPDATE)), \
$(TARGETS_UPDATE_ALL?) $(TARGETS_UPDATE_MAKE?))

$(call cdebug,using TARGETS_UNINSTALL_GO [$(TARGETS_UNINSTALL_GO)])
$(call cdebug,using FILTER [$(filter-out $(go-make-filter),$(TARGETS_UNINSTALL_GO))])
$(call cdebug,using TARGETS_UNINSTALL_ALL [$(TARGETS_UNINSTALL_ALL)])

## Standard: default targets to test, lint, and build.

#@ executes the default targets.
Expand Down Expand Up @@ -810,12 +833,10 @@ go.mod:
#@ initialize git pre-commit and commit-message hooks.
init-hooks:: $(GITHOOKS:%=.git/hooks/%)
git-hooks-commit-msg = echo -ne '\#!/bin/sh\n\n\
echo "make git-verify message $${1}" > /dev/stderr;\n\
command -v $(GOBIN)/go-make >/dev/null || \\\n\
GOBIN=$(GOBIN) $(GO) install $(INSTALL_FLAGS) $(GOMAKE_DEP) && \\\n\
$(GOBIN)/go-make git-verify message $${1};\n' | sed 's/^ *//g'
git-hooks-pre-commit = echo -ne '\#!/bin/sh\n\n\
echo "make commit" > /dev/stderr;\n\
command -v $(GOBIN)/go-make >/dev/null || \\\n\
GOBIN=$(GOBIN) $(GO) install $(INSTALL_FLAGS) $(GOMAKE_DEP) && \\\n\
$(GOBIN)/go-make commit;\n' | sed 's/^ *//g'
Expand Down Expand Up @@ -1084,7 +1105,7 @@ test-cdp:
${CDP_IMAGE} /bin/bash $(ARGS);

#@ execute a kind of self-test running the main targets.
test-self:: update-all? update-all clean-all all-clean install-all
test-self:: clean-all all-clean clean-all install-all update-all? update-all
@$(call emsg,success,test-self finished successfully!);


Expand Down
2 changes: 1 addition & 1 deletion internal/make/fixtures/git-verify/log-all.err
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: please customize variables in go-make/run/Makefile.vars
info: captured arguments [log ../internal/make/fixtures/git-verify/log-all.in]
info: make git-verify [log ../internal/make/fixtures/git-verify/log-all.in]
error: commit type missing [title=commit type is missing (#0)]
error: commit type invalid [title=feature: commit type is invalid (#1)]
error: signed-off-by missing [msg=feat[service]: initial commit (#2)]
Expand Down
2 changes: 1 addition & 1 deletion internal/make/fixtures/git-verify/msg-failed.err
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: please customize variables in go-make/run/Makefile.vars
info: captured arguments [message ../internal/make/fixtures/git-verify/msg-failed.in]
info: make git-verify [message ../internal/make/fixtures/git-verify/msg-failed.in]
error: commit type missing [title=feat(wrong): all is somehow wrong (org#1)]
error: issue missing [titel=feat(wrong): all is somehow wrong (org#1)]
error: signed-off-by not the author [sign=Signed-off-by: Alice Doe <[email protected]>; author=John Doe <[email protected]>]
Expand Down
2 changes: 1 addition & 1 deletion internal/make/fixtures/git-verify/msg-okay.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
warning: please customize variables in go-make/run/Makefile.vars
info: captured arguments [message ../internal/make/fixtures/git-verify/msg-okay.in]
info: make git-verify [message ../internal/make/fixtures/git-verify/msg-okay.in]
success: git-verify message ../internal/make/fixtures/git-verify/msg-okay.in [errors=0]
2 changes: 1 addition & 1 deletion internal/make/fixtures/targets/cat.err
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
warning: please customize variables in go-make/run/Makefile.vars
info: captured arguments [cat]
info: make call [cat]
2 changes: 1 addition & 1 deletion internal/make/fixtures/targets/std.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
warning: please customize variables in go-make/run/Makefile.vars
info: captured arguments [param]
info: make show-targets [param]
info: updating targets [go-make/config/run/targets]
2 changes: 1 addition & 1 deletion internal/make/fixtures/targets/trace.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ exec: git rev-parse --show-toplevel [go-make/run]
exec: test -d go-make/config [go-make/run]
exec: make --file go-make/config/Makefile.base --no-print-directory --trace show-targets [go-make/run]
warning: please customize variables in go-make/run/Makefile.vars
info: captured arguments [param]
info: make show-targets [param]
info: updating targets [go-make/config/run/targets]
4 changes: 2 additions & 2 deletions internal/make/fixtures/targets/trace.out
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
go-make/config/Makefile.base: target 'go-make/config/run' does not exist
if [ ! -d "go-make/config/run" ]; then mkdir -p go-make/config/run; fi;
go-make/config/Makefile.base: update target 'go-make/config/run/targets' due to: go-make/config/run go-make/config/Makefile.base
go-make/config/Makefile.base: update target 'go-make/config/run/targets'
echo -e "\033[1;96minfo:\033[0m updating targets [go-make/config/run/targets]" > /dev/stderr; \
make --no-builtin-rules --no-builtin-variables --print-data-base \
--question --makefile="go-make/config/Makefile.base" 2>/dev/null | \
awk -v RS= -F: ' /(^|\n)# Files(\n|$)/,/(^|\n)# Finished Make data base/ { if ($1 !~ "^[#.]") { print $1 } }' | LC_ALL=C sort --unique | egrep --invert-match --regexp='^[^[:alnum:]]' > "go-make/config/run/targets";
go-make/config/Makefile.base: update target 'show-targets' due to: go-make/config/run/targets
go-make/config/Makefile.base: update target 'show-targets'
cat go-make/config/run/targets || true;
all
all-clean
Expand Down
5 changes: 5 additions & 0 deletions internal/make/make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ var (
// are moved around.
regexMakeTrace = regexp.MustCompile(
`(?m)(go-make/config/Makefile.base:)[0-9]+:`)
// regexMakeTarget is used to match the make trace output and to remove the
// target update message that changes between make 4.3 and make 4.4.
regexMakeTarget = regexp.MustCompile(
`(?m)(go-make/config/Makefile.base:).*('.*') due to:.*`)
// replaceFixture replaces the placeholders in the fixture with the values
// provided to the replacer.
replacerFixture = strings.NewReplacer(
Expand All @@ -476,6 +480,7 @@ func FilterMakeOutput(str string) string {
str = regexGoMakeSource.ReplaceAllString(str, "go-make")
str = regexGoMakeConfig.ReplaceAllString(str, "go-make/config")
str = regexMakeTrace.ReplaceAllString(str, "$1")
str = regexMakeTarget.ReplaceAllString(str, "$1 update target $2")
return str
}

Expand Down

0 comments on commit 50c2c96

Please sign in to comment.