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 f4c2cd9
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 56 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
48 changes: 34 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,14 @@ 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 \
XPATH="$(shell brew --prefix)/opt/$(1)/libexec/gnubin"; \
echo "$${XPATH}/$(2)" >&2 ; \
test ! -e "$${XPATH}/$(2)" && brew install $(1) >&2; \
echo -n "$${XPATH}:$(3)")
# System depdendent helper functions.
ifeq ("$(shell uname)","Linux")
uname-all := uname --all
Expand All @@ -52,11 +58,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,coreutils,ls,$(PATH))
export PATH := $(call path-setup,findutils,find,$(PATH))
export PATH := $(call path-setup,bash,bash,$(PATH))
export PATH := $(call path-setup,gawk,awk,$(PATH))
export PATH := $(call path-setup,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 +112,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 +188,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 +242,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 +478,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 +539,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 +832,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 +1104,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]

0 comments on commit f4c2cd9

Please sign in to comment.