From def123ae57604e045a9c83880a3d8daac18c5592 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Thu, 16 Jan 2025 15:24:38 +0000 Subject: [PATCH 1/3] chore(ci): various makefile improvements Signed-off-by: John Cowen --- Makefile | 15 ++++++++++----- packages/config/Makefile | 17 +++++++++++++++-- packages/config/scripts/ci.cjs | 14 ++++++++++++++ packages/config/src/index.cjs | 2 ++ packages/config/src/mk/help.mk | 18 ++++++++++++++++++ packages/config/src/mk/install.mk | 8 +++++--- packages/config/src/mk/release.mk | 14 +++++++------- packages/kuma-gui/Makefile | 11 +++++++---- 8 files changed, 78 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 6a5583fa47..b0f160ff41 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,23 @@ +# Please keep this file free of actual scripts +# It should only be used for adding "non-dot" aliases and documentation + SHELL := /usr/bin/env bash -MK := ./packages/config/src/mk + +KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path') +MK := $(KUMAHQ_CONFIG)/src/mk ## make help: if you're aren't sure use `make help` .DEFAULT_GOAL := help +include $(MK)/help.mk include $(MK)/install.mk include $(MK)/check.mk -include $(MK)/help.mk + +.PHONY: help +help: .help ## Display this help screen .PHONY: clean clean: .clean ## Dev: Remove all `node_modules` recursively .PHONY: install install: .install ## Dev: Install all dependencies - -.PHONY: help -help: .help ## Display this help screen diff --git a/packages/config/Makefile b/packages/config/Makefile index 66ec1de345..6fe0a4f685 100644 --- a/packages/config/Makefile +++ b/packages/config/Makefile @@ -1,13 +1,26 @@ -MK := ./src/mk +# Please keep this file free of actual scripts +# It should only be used for adding "non-dot" aliases and documentation + +SHELL := /usr/bin/env bash + +KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path') +MK := $(KUMAHQ_CONFIG)/src/mk ## make help: if you're aren't sure use `make help` .DEFAULT_GOAL := help +include $(MK)/help.mk +include $(MK)/install.mk include $(MK)/check.mk -include $(MK)/help.mk .PHONY: help help: .help ## Display this help screen +.PHONY: clean +clean: .clean ## Dev: Remove all `node_modules` recursively + +.PHONY: install +install: .install ## Dev: Install all dependencies + .PHONY: lint lint: .lint/script ## Dev: Run all lint script checks (js,ts) diff --git a/packages/config/scripts/ci.cjs b/packages/config/scripts/ci.cjs index 1914ac4529..fa21fc404e 100644 --- a/packages/config/scripts/ci.cjs +++ b/packages/config/scripts/ci.cjs @@ -1,5 +1,18 @@ const { sync: globSync } = require('glob') +const { readFileSync: read } = require('fs') +const depsToDevDeps = (path) => { + const pkg = JSON.parse(read(path, 'utf-8')) + return JSON.stringify({ + ...pkg, + dependencies: {}, + peerDependencies: {}, + devDependencies: { + ...pkg.dependencies, + ...pkg.devDependencies, + }, + }) +} /** * @param {number} length * @param {string} prefix @@ -33,4 +46,5 @@ function shuffleArray(array) { module.exports = { getPartitionedTestFiles, + depsToDevDeps, } diff --git a/packages/config/src/index.cjs b/packages/config/src/index.cjs index a4658e7ff2..462c790380 100644 --- a/packages/config/src/index.cjs +++ b/packages/config/src/index.cjs @@ -1,7 +1,9 @@ const { createEslintConfig } = require('./eslint.cjs') const { createStylelintConfig } = require('./stylelint.cjs') +const ci = require('../scripts/ci.cjs') module.exports = { eslint: createEslintConfig, stylelint: createStylelintConfig, + ci, } diff --git a/packages/config/src/mk/help.mk b/packages/config/src/mk/help.mk index eba1b16196..b49c79d1b5 100644 --- a/packages/config/src/mk/help.mk +++ b/packages/config/src/mk/help.mk @@ -1,3 +1,7 @@ +NPM_WORKSPACE_ROOT := $(shell npm prefix) +NODE_VERSION := v$(shell cat $(NPM_WORKSPACE_ROOT)/.nvmrc) +KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path') + .PHONY: .help .help: ## Display this help screen @echo "The following targets can be used by running \`make \`"; echo "---" @@ -14,3 +18,17 @@ awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' ; \ done +.PHONY: confirm +confirm: + @if [[ -z "$(CI)" ]]; then \ + CONFIRM="" ; \ + read -p "=== Please confirm [y/n]: " -r ; \ + if [[ ! $$CONFIRM =~ ^[Yy]$$ ]]; then \ + echo "Aborting" ; \ + exit 1 ; \ + else \ + exit 0; \ + fi \ + fi + + diff --git a/packages/config/src/mk/install.mk b/packages/config/src/mk/install.mk index 3dec8d385e..b3ff2c539e 100644 --- a/packages/config/src/mk/install.mk +++ b/packages/config/src/mk/install.mk @@ -8,6 +8,8 @@ .PHONY: .clean .clean: - @echo "Recursively removing all node_modules/ directories in `pwd`..."; \ - find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + - + @echo "Recursively removing all node_modules/ directories in $(NPM_WORKSPACE_ROOT)..." + @find $(NPM_WORKSPACE_ROOT) -name 'node_modules' -type d -prune + @if $(MAKE) -s confirm ; then \ + find $(NPM_WORKSPACE_ROOT) -name 'node_modules' -type d -prune -exec rm -rf '{}' +; \ + fi diff --git a/packages/config/src/mk/release.mk b/packages/config/src/mk/release.mk index 8f598f0b5f..960812ed6c 100644 --- a/packages/config/src/mk/release.mk +++ b/packages/config/src/mk/release.mk @@ -37,14 +37,14 @@ # from 872 to 157 at the time of this change. .PHONY: .release/prune .release/prune: - @if [ -z "$(NPM_WORKFLOW_CONFIG_PATH)" ]; then \ - echo "Error: NPM_WORKFLOW_CONFIG_PATH is not set or empty."; \ + @if [ -z "$(KUMAHQ_CONFIG)" ]; then \ + echo "Error: KUMAHQ_CONFIG is not set or empty."; \ exit 1; \ fi - @if [ ! -d "$(NPM_WORKFLOW_CONFIG_PATH)" ]; then \ - echo "Error: NPM_WORKFLOW_CONFIG_PATH does not exist or is not a directory: $(NPM_WORKFLOW_CONFIG_PATH)"; \ + @if [ ! -d "$(KUMAHQ_CONFIG)" ]; then \ + echo "Error: KUMAHQ_CONFIG does not exist or is not a directory: $(KUMAHQ_CONFIG)"; \ exit 1; \ fi - npm pkg delete devDependencies.@kumahq/config - rm -rf $(NPM_WORKFLOW_CONFIG_PATH) - npm install --package-lock-only + @echo '$(shell node -e "console.log(require('@kumahq/config').ci.depsToDevDeps('$(KUMAHQ_CONFIG)/package.json'))")' \ + > $(KUMAHQ_CONFIG)/package.json + @npm install --package-lock-only diff --git a/packages/kuma-gui/Makefile b/packages/kuma-gui/Makefile index bae2f57d06..0eea128233 100644 --- a/packages/kuma-gui/Makefile +++ b/packages/kuma-gui/Makefile @@ -2,14 +2,14 @@ # It should only be used for adding "non-dot" aliases and documentation SHELL := /usr/bin/env bash -MK := ../config/src/mk -NODE_VERSION:=v$(shell cat ../../.nvmrc) -NPM_WORKFLOW_CONFIG_PATH ?= $(shell readlink -f ../config) + +KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path') +MK := $(KUMAHQ_CONFIG)/src/mk ## make help: if you're aren't sure use `make help` .DEFAULT_GOAL := help - include $(MK)/help.mk + include $(MK)/run.mk include $(MK)/install.mk include $(MK)/check.mk @@ -28,6 +28,9 @@ install/sync: .install/sync .PHONY: help help: .help ## Display this help screen +.PHONY: clean +clean: .clean ## Dev: Delete all node_modules directories + .PHONY: install install: .install ## Dev: install all dependencies (runs before `make run`) From c3ac66cbb01f10b4e221198115ceb75d9ac0bea3 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Thu, 16 Jan 2025 16:05:12 +0000 Subject: [PATCH 2/3] make sure we wait for port 5681 to run the tests Signed-off-by: John Cowen --- packages/config/src/mk/test.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/config/src/mk/test.mk b/packages/config/src/mk/test.mk index 76d8f9e79a..4276e81fa4 100644 --- a/packages/config/src/mk/test.mk +++ b/packages/config/src/mk/test.mk @@ -26,6 +26,7 @@ ifdef KUMA_TEST_BROWSER --e2e \ --browser $(KUMA_TEST_BROWSER) else + @while ! nc -z localhost 5681; do sleep 1; done; @CYPRESS_video=true \ TZ=UTC \ npx cypress \ From 1d81b99c458cc9ad595b91bde7af91a2f700ad82 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 17 Jan 2025 12:41:44 +0000 Subject: [PATCH 3/3] Make sbom exclusion reusable Signed-off-by: John Cowen --- packages/config/src/mk/help.mk | 2 +- packages/config/src/mk/release.mk | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/config/src/mk/help.mk b/packages/config/src/mk/help.mk index b49c79d1b5..b33f3959e8 100644 --- a/packages/config/src/mk/help.mk +++ b/packages/config/src/mk/help.mk @@ -4,7 +4,7 @@ KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@k .PHONY: .help .help: ## Display this help screen - @echo "The following targets can be used by running \`make \`"; echo "---" + @echo "The following targets can be used by running \`make \` in this directory:"; echo "---" @# Display top-level targets since they are the ones most developers will need. @grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -k1 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @# Now show hierarchical targets in separate sections. diff --git a/packages/config/src/mk/release.mk b/packages/config/src/mk/release.mk index 960812ed6c..c65f8df662 100644 --- a/packages/config/src/mk/release.mk +++ b/packages/config/src/mk/release.mk @@ -35,16 +35,21 @@ # # This reduces incorrect SBOM entries, decreasing cataloged dependencies # from 872 to 157 at the time of this change. -.PHONY: .release/prune -.release/prune: - @if [ -z "$(KUMAHQ_CONFIG)" ]; then \ - echo "Error: KUMAHQ_CONFIG is not set or empty."; \ +.PHONY: .sbom/exclude +.sbom/exclude: EXCLUDE_PATH?=$(KUMAHQ_CONFIG) +.sbom/exclude: + @if [ -z "$(EXCLUDE_PATH)" ]; then \ + echo "Error: EXCLUDE_PATH is not set or empty."; \ exit 1; \ fi - @if [ ! -d "$(KUMAHQ_CONFIG)" ]; then \ - echo "Error: KUMAHQ_CONFIG does not exist or is not a directory: $(KUMAHQ_CONFIG)"; \ + @if [ ! -d "$(EXCLUDE_PATH)" ]; then \ + echo "Error: EXCLUDE_PATH does not exist or is not a directory: $(EXCLUDE_PATH)"; \ exit 1; \ fi - @echo '$(shell node -e "console.log(require('@kumahq/config').ci.depsToDevDeps('$(KUMAHQ_CONFIG)/package.json'))")' \ - > $(KUMAHQ_CONFIG)/package.json + @echo '$(shell node -e "console.log(require('@kumahq/config').ci.depsToDevDeps('$(EXCLUDE_PATH)/package.json'))")' \ + > $(EXCLUDE_PATH)/package.json + +.PHONY: .release/prune +.release/prune: + @$(MAKE) .sbom/exclude EXCLUDE_PATH=$(KUMAHQ_CONFIG) @npm install --package-lock-only