Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): various makefile improvements #3410

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 15 additions & 2 deletions packages/config/Makefile
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions packages/config/scripts/ci.cjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,4 +46,5 @@ function shuffleArray(array) {

module.exports = {
getPartitionedTestFiles,
depsToDevDeps,
}
2 changes: 2 additions & 0 deletions packages/config/src/index.cjs
Original file line number Diff line number Diff line change
@@ -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,
}
20 changes: 19 additions & 1 deletion packages/config/src/mk/help.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 <target>\`"; echo "---"
@echo "The following targets can be used by running \`make <target>\` 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.
Expand All @@ -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


8 changes: 5 additions & 3 deletions packages/config/src/mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 14 additions & 9 deletions packages/config/src/mk/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$(NPM_WORKFLOW_CONFIG_PATH)" ]; then \
echo "Error: NPM_WORKFLOW_CONFIG_PATH 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 "$(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 "$(EXCLUDE_PATH)" ]; then \
echo "Error: EXCLUDE_PATH does not exist or is not a directory: $(EXCLUDE_PATH)"; \
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('$(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
1 change: 1 addition & 0 deletions packages/config/src/mk/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
11 changes: 7 additions & 4 deletions packages/kuma-gui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`)

Expand Down
Loading