Skip to content

Commit

Permalink
fix(ci): fix release/prune which runs before make install (#3412)
Browse files Browse the repository at this point in the history
Follow up of #3410

---

Turns out `npm query` requires your `node_modules` to be present, I've
no idea why 🤷 , and we have a target that we sometimes run that needs to
run before a `make install` (`make release/prune`) 🤦 .

I saw that you can add a `npm --package-lock-file-only query` to get it
to use the lock file instead of needing access to `node_modules`. This
works when running from workspace root without `node_modules`, but when
you run a Makefile from a sub project without `node_modules` adding this
arg/flag still fails 🤷

I've fallen back to just jq-ing the package-lock.json myself at least
for the moment so we can unblock the release workflow. If I find a
slightly nicer way to do this in the future I'll replace, but I really
want to stick to the runtime resolution of things rather than hardcoding
paths in several files.

How to test:

- Run `make clean` to remove all your `node_modules` folders
- cd into or use `make -C` to run `make release/prune` from within
`packages/kuma-gui`
- Verify that `packages/config` has changes to package.json and
package-lock.json also has changes.

I 'think' this will finally unblock the release workflow 🤞 

---

edit: I just checked a this new approach actually works better elsewhere
also 🎉

Signed-off-by: John Cowen <[email protected]>
  • Loading branch information
johncowen authored Jan 20, 2025
1 parent 601d095 commit 09a9318
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

SHELL := /usr/bin/env bash

KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path')
NPM_WORKSPACE_ROOT := $(shell npm prefix)
KUMAHQ_CONFIG := $(NPM_WORKSPACE_ROOT)/$(shell cat $(NPM_WORKSPACE_ROOT)/package-lock.json | jq -r '.packages | to_entries[] | select(.value.name == "@kumahq/config") | .key')
MK := $(KUMAHQ_CONFIG)/src/mk

## make help: if you're aren't sure use `make help`
Expand Down
3 changes: 2 additions & 1 deletion packages/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

SHELL := /usr/bin/env bash

KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path')
NPM_WORKSPACE_ROOT := $(shell npm prefix)
KUMAHQ_CONFIG := $(NPM_WORKSPACE_ROOT)/$(shell cat $(NPM_WORKSPACE_ROOT)/package-lock.json | jq -r '.packages | to_entries[] | select(.value.name == "@kumahq/config") | .key')
MK := $(KUMAHQ_CONFIG)/src/mk

## make help: if you're aren't sure use `make help`
Expand Down
14 changes: 0 additions & 14 deletions packages/config/scripts/ci.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
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 @@ -46,5 +33,4 @@ function shuffleArray(array) {

module.exports = {
getPartitionedTestFiles,
depsToDevDeps,
}
15 changes: 15 additions & 0 deletions packages/config/scripts/prune.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { readFileSync: read } = require('fs')
module.exports = {
depsToDevDeps: (path) => {
const pkg = JSON.parse(read(path, 'utf-8'))
return JSON.stringify({
...pkg,
dependencies: {},
peerDependencies: {},
devDependencies: {
...pkg.dependencies,
...pkg.devDependencies,
},
})
},
}
2 changes: 0 additions & 2 deletions packages/config/src/index.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { createEslintConfig } = require('./eslint.cjs')
const { createStylelintConfig } = require('./stylelint.cjs')
const ci = require('../scripts/ci.cjs')

module.exports = {
eslint: createEslintConfig,
stylelint: createStylelintConfig,
ci,
}
8 changes: 4 additions & 4 deletions packages/config/src/mk/help.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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')
KUMAHQ_CONFIG := $(NPM_WORKSPACE_ROOT)/$(shell cat $(NPM_WORKSPACE_ROOT)/package-lock.json | jq -r '.packages | to_entries[] | select(.value.name == "@kumahq/config") | .key')

.PHONY: .help
.help: ## Display this help screen
Expand All @@ -21,10 +21,10 @@ KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@k
.PHONY: confirm
confirm:
@if [[ -z "$(CI)" ]]; then \
CONFIRM="" ; \
REPLY="" ; \
read -p "=== Please confirm [y/n]: " -r ; \
if [[ ! $$CONFIRM =~ ^[Yy]$$ ]]; then \
echo "Aborting" ; \
if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
echo $$REPLY ; \
exit 1 ; \
else \
exit 0; \
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/mk/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
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('$(EXCLUDE_PATH)/package.json'))")' \
@echo '$(shell cd $(KUMAHQ_CONFIG) && node -e "console.log(require('./scripts/prune.cjs').depsToDevDeps('$(EXCLUDE_PATH)/package.json'))")' \
> $(EXCLUDE_PATH)/package.json

.PHONY: .release/prune
Expand Down
3 changes: 2 additions & 1 deletion packages/kuma-gui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

SHELL := /usr/bin/env bash

KUMAHQ_CONFIG := $(shell npm query .workspace | jq -r '.[] | select(.name == "@kumahq/config") | .path')
NPM_WORKSPACE_ROOT := $(shell npm prefix)
KUMAHQ_CONFIG := $(NPM_WORKSPACE_ROOT)/$(shell cat $(NPM_WORKSPACE_ROOT)/package-lock.json | jq -r '.packages | to_entries[] | select(.value.name == "@kumahq/config") | .key')
MK := $(KUMAHQ_CONFIG)/src/mk

## make help: if you're aren't sure use `make help`
Expand Down

0 comments on commit 09a9318

Please sign in to comment.