From 293de41479b5fe988f46c2620f9703bea0b69208 Mon Sep 17 00:00:00 2001 From: Tronje Krop Date: Mon, 23 Sep 2024 15:16:48 +0200 Subject: [PATCH] feat: add compat test action (#102) Signed-off-by: Tronje Krop --- .github/workflows/build.yaml | 101 +++++++++++++++++- .github/workflows/release.yaml | 29 ----- Makefile | 2 +- VERSION | 2 +- config/Makefile | 2 +- config/Makefile.base | 49 ++++++--- internal/make/fixtures/git-verify/log-all.err | 2 +- .../make/fixtures/git-verify/msg-failed.err | 2 +- .../make/fixtures/git-verify/msg-okay.err | 2 +- internal/make/fixtures/targets/cat.err | 2 +- internal/make/fixtures/targets/std.err | 2 +- internal/make/fixtures/targets/trace.err | 2 +- 12 files changed, 141 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d20d9d6..9c67af7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 }} @@ -22,3 +22,96 @@ 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 search gmake; + 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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 08102a7..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Go Release -on: [push] -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.23.1 - - - 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 diff --git a/Makefile b/Makefile index db0f8eb..3176292 100644 --- a/Makefile +++ b/Makefile @@ -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/go-make@v0.0.100 +GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.101 INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto # Request targets from go-make targets target. TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \ diff --git a/VERSION b/VERSION index 8e3cdca..39d8d9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.100 +0.0.101 diff --git a/config/Makefile b/config/Makefile index db0f8eb..3176292 100644 --- a/config/Makefile +++ b/config/Makefile @@ -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/go-make@v0.0.100 +GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.101 INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto # Request targets from go-make targets target. TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \ diff --git a/config/Makefile.base b/config/Makefile.base index 82457de..715ed61 100644 --- a/config/Makefile.base +++ b/config/Makefile.base @@ -24,7 +24,7 @@ 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) @@ -32,6 +32,7 @@ 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. @@ -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}/$(4)" && brew install $(2) $(3) >&2; \ + echo -n "$${XPATH}:$(5)") # System depdendent helper functions. ifeq ("$(shell uname)","Linux") uname-all := uname --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,--version=4.3,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 | \ @@ -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 ?= @@ -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' @@ -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/go-make@v0.0.100 +GOMAKE_DEP := github.com/tkrop/go-make@v0.0.101 GOMAKE_MAKEFILE := $(realpath $(firstword $(MAKEFILE_LIST))) GOMAKE_MAKEFILES := $(GOMAKE_MAKEFILE) \ $(wildcard Makefile.vars) $(wildcard Makefile.ext) @@ -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 = \ @@ -524,15 +540,18 @@ 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 @@ -540,6 +559,10 @@ 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. @@ -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' @@ -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!); diff --git a/internal/make/fixtures/git-verify/log-all.err b/internal/make/fixtures/git-verify/log-all.err index afbd4e5..7dedd21 100644 --- a/internal/make/fixtures/git-verify/log-all.err +++ b/internal/make/fixtures/git-verify/log-all.err @@ -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)] diff --git a/internal/make/fixtures/git-verify/msg-failed.err b/internal/make/fixtures/git-verify/msg-failed.err index 97907a4..bff4bfd 100644 --- a/internal/make/fixtures/git-verify/msg-failed.err +++ b/internal/make/fixtures/git-verify/msg-failed.err @@ -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 ; author=John Doe ] diff --git a/internal/make/fixtures/git-verify/msg-okay.err b/internal/make/fixtures/git-verify/msg-okay.err index 84b6280..af97787 100644 --- a/internal/make/fixtures/git-verify/msg-okay.err +++ b/internal/make/fixtures/git-verify/msg-okay.err @@ -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] diff --git a/internal/make/fixtures/targets/cat.err b/internal/make/fixtures/targets/cat.err index d2e722f..43d5f4f 100644 --- a/internal/make/fixtures/targets/cat.err +++ b/internal/make/fixtures/targets/cat.err @@ -1,2 +1,2 @@ warning: please customize variables in go-make/run/Makefile.vars -info: captured arguments [cat] +info: make call [cat] diff --git a/internal/make/fixtures/targets/std.err b/internal/make/fixtures/targets/std.err index 82f5b1c..5a33278 100644 --- a/internal/make/fixtures/targets/std.err +++ b/internal/make/fixtures/targets/std.err @@ -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] diff --git a/internal/make/fixtures/targets/trace.err b/internal/make/fixtures/targets/trace.err index 828f4c8..c72a317 100644 --- a/internal/make/fixtures/targets/trace.err +++ b/internal/make/fixtures/targets/trace.err @@ -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]