Skip to content
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
1 change: 1 addition & 0 deletions .nextchanges/cli/apps-validate-package-managers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Select npm or pnpm from `packageManager` declarations and lockfiles for `apps validate` and project validation during `apps deploy`. ([#6892](https://github.com/databricks/cli/pull/6892))
1 change: 1 addition & 0 deletions acceptance/apps/validate/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions acceptance/apps/validate/bin/npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
printf '%s %s\n' "${0##*/}" "$*" >> commands.log
if [ "$*" = "${VALIDATION_TEST_FAIL:-}" ]; then
echo "validation stdout"
echo "validation stderr" >&2
exit 17
fi
7 changes: 7 additions & 0 deletions acceptance/apps/validate/bin/npm.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off
echo %~n0 %*>>commands.log
if "%*"=="%VALIDATION_TEST_FAIL%" (
echo validation stdout
echo validation stderr 1>&2
exit /b 17
)
7 changes: 7 additions & 0 deletions acceptance/apps/validate/bin/pnpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
printf '%s %s\n' "${0##*/}" "$*" >> commands.log
if [ "$*" = "${VALIDATION_TEST_FAIL:-}" ]; then
echo "validation stdout"
echo "validation stderr" >&2
exit 17
fi
7 changes: 7 additions & 0 deletions acceptance/apps/validate/bin/pnpm.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off
echo %~n0 %*>>commands.log
if "%*"=="%VALIDATION_TEST_FAIL%" (
echo validation stdout
echo validation stderr 1>&2
exit /b 17
)
5 changes: 5 additions & 0 deletions acceptance/apps/validate/bom/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"build": "node -e \"console.log('BOM build ran'); process.exit(17)\""
}
}
1 change: 1 addition & 0 deletions acceptance/apps/validate/conflicting/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions acceptance/apps/validate/conflicting/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions acceptance/apps/validate/conflicting/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions acceptance/apps/validate/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundle:
name: validate-app
1 change: 1 addition & 0 deletions acceptance/apps/validate/invalid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{
8 changes: 8 additions & 0 deletions acceptance/apps/validate/lifecycle/add-build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "validation-add-build",
"version": "1.0.0",
"scripts": {
"install": "node ../update-manifest.cjs",
"typegen": "node ../update-manifest.cjs"
}
}
8 changes: 8 additions & 0 deletions acceptance/apps/validate/lifecycle/invalidated/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "validation-invalidated-manifest",
"version": "1.0.0",
"scripts": {
"install": "node ../update-manifest.cjs",
"typegen": "node ../update-manifest.cjs"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "validation-remove-build",
"version": "1.0.0",
"scripts": {
"install": "node ../update-manifest.cjs",
"typegen": "node ../update-manifest.cjs",
"build": "node -e \"process.exit(17)\""
}
}
17 changes: 17 additions & 0 deletions acceptance/apps/validate/lifecycle/update-manifest.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require("node:fs");

if (process.env.npm_lifecycle_event === process.env.VALIDATION_UPDATE_STEP) {
const manifest = JSON.parse(fs.readFileSync("package.json", "utf8"));
switch (process.env.VALIDATION_UPDATE_ACTION) {
case "add":
manifest.scripts.build = "node -e \"console.log('added build ran'); process.exit(17)\"";
break;
case "remove":
delete manifest.scripts.build;
break;
case "invalidate":
fs.writeFileSync("package.json", "{");
return;
}
fs.writeFileSync("package.json", JSON.stringify(manifest));
}
2 changes: 2 additions & 0 deletions acceptance/apps/validate/metadata-npm/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundle:
name: validation-metadata-npm
8 changes: 8 additions & 0 deletions acceptance/apps/validate/metadata-npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "validation-metadata-npm",
"version": "1.0.0",
"packageManager": "npm@10.9.2",
"scripts": {
"build": "node -e \"console.log('declared npm build ran'); process.exit(17)\""
}
}
1 change: 1 addition & 0 deletions acceptance/apps/validate/metadata-npm/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions acceptance/apps/validate/non-runnable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"typegen": "",
"typecheck": null,
"test": "",
"//": ["a comment"],
"build": "node -e \"console.log('non-runnable entries ignored'); process.exit(17)\""
}
}
1 change: 1 addition & 0 deletions acceptance/apps/validate/null/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
2 changes: 2 additions & 0 deletions acceptance/apps/validate/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
196 changes: 196 additions & 0 deletions acceptance/apps/validate/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@

=== Validate the directory selected by --path
>>> withdir app [CLI] apps validate --path ..
Validating project using pnpm...
✅ Installing dependencies ([DURATION])
✅ Generating types ([DURATION])
✅ Running AST-grep lint ([DURATION])
✅ Type checking ([DURATION])
✅ Building ([DURATION])
✅ Running tests ([DURATION])
✅ All validation checks passed ([DURATION])

=== Skip tests
>>> [CLI] apps validate --skip-tests
Validating project using pnpm...
✅ Installing dependencies ([DURATION])
✅ Generating types ([DURATION])
✅ Running AST-grep lint ([DURATION])
✅ Type checking ([DURATION])
✅ Building ([DURATION])
⏭️ Skipped Running tests
✅ All validation checks passed ([DURATION])

=== Report a failed script
>>> VALIDATION_TEST_FAIL=run --if-present test musterr [CLI] apps validate
Validating project using pnpm...
✅ Installing dependencies ([DURATION])
✅ Generating types ([DURATION])
✅ Running AST-grep lint ([DURATION])
✅ Type checking ([DURATION])
✅ Building ([DURATION])
Error: tests failed (duration: [DURATION])
❌ Running tests failed ([DURATION])
validation failed (exit code 17)
Stdout:
validation stdout

Stderr:
validation stderr

Error: validation failed

=== Deploy validates with the same package manager before uploading
>>> VALIDATION_TEST_FAIL=run --if-present build musterr [CLI] apps deploy
Validating project using pnpm...
✅ Installing dependencies ([DURATION])
✅ Generating types ([DURATION])
✅ Running AST-grep lint ([DURATION])
✅ Type checking ([DURATION])
Error: build failed (duration: [DURATION])
❌ Building failed ([DURATION])
validation failed (exit code 17)
Stdout:
validation stdout

Stderr:
validation stderr

Error: validation failed - fix errors before deploying

=== Commands executed in the project directory
>>> cat commands.log
pnpm install
pnpm run --if-present typegen
pnpm run --if-present lint:ast-grep
pnpm run --if-present typecheck
pnpm run --if-present build
pnpm run --if-present test
pnpm install
pnpm run --if-present typegen
pnpm run --if-present lint:ast-grep
pnpm run --if-present typecheck
pnpm run --if-present build
pnpm install
pnpm run --if-present typegen
pnpm run --if-present lint:ast-grep
pnpm run --if-present typecheck
pnpm run --if-present build
pnpm run --if-present test
pnpm install
pnpm run --if-present typegen
pnpm run --if-present lint:ast-grep
pnpm run --if-present typecheck
pnpm run --if-present build

=== Warn but continue on conflicting lockfiles
>>> [CLI] apps validate --path conflicting
Warn: found conflicting package managers; using npm from package-lock.json and ignoring pnpm-lock.yaml
Validating project using npm...
✅ Installing dependencies ([DURATION])
✅ Generating types ([DURATION])
✅ Running AST-grep lint ([DURATION])
✅ Type checking ([DURATION])
✅ Building ([DURATION])
✅ Running tests ([DURATION])
✅ All validation checks passed ([DURATION])

=== Warn but continue on unsupported lockfiles
>>> [CLI] apps validate --path unsupported
Warn: ignoring unsupported lockfile yarn.lock; apps validation uses npm or pnpm
Validating project using npm...
✅ Installing dependencies ([DURATION])
✅ Generating types ([DURATION])
✅ Running AST-grep lint ([DURATION])
✅ Type checking ([DURATION])
✅ Building ([DURATION])
✅ Running tests ([DURATION])
✅ All validation checks passed ([DURATION])

=== Validate npm workspace scripts without root scripts
>>> grep -x workspace build ran LOG.workspaces
workspace build ran

>>> grep -F validation failed (exit code 17) LOG.workspaces
validation failed (exit code 17)

=== Deploy rejects a failing npm workspace build
>>> grep -x workspace build ran LOG.workspaces-deploy
workspace build ran

>>> grep -F validation failed - fix errors before deploying LOG.workspaces-deploy
Error: validation failed - fix errors before deploying

=== Use declared npm despite a pnpm lockfile
>>> grep -x declared npm build ran LOG.metadata-npm
declared npm build ran

>>> grep -F validation failed (exit code 17) LOG.metadata-npm
validation failed (exit code 17)

=== Deploy honors the declared package manager
>>> grep -x declared npm build ran LOG.metadata-npm-deploy
declared npm build ran

>>> grep -F validation failed - fix errors before deploying LOG.metadata-npm-deploy
Error: validation failed - fix errors before deploying

=== Reject a missing package.json
>>> musterr [CLI] apps validate --path missing
Error: no supported project type detected (looking for package.json)

=== Report native manifest errors with dependencies absent
>>> grep -x Error: validation failed LOG.invalid-absent
Error: validation failed

=== Report native manifest errors with dependencies present
>>> grep -x Error: validation failed LOG.invalid-present
Error: validation failed

=== Reject a null manifest through the package manager
>>> grep -x Error: validation failed LOG.null
Error: validation failed

=== Run scripts from a manifest with a UTF-8 BOM
>>> grep -x BOM build ran LOG.bom
BOM build ran

>>> grep -F validation failed (exit code 17) LOG.bom
validation failed (exit code 17)

=== Let the package manager ignore non-runnable script entries
>>> grep -x non-runnable entries ignored LOG.non-runnable
non-runnable entries ignored

>>> grep -F validation failed (exit code 17) LOG.non-runnable
validation failed (exit code 17)

=== Run a build added by install
>>> grep -x added build ran LOG.add-build-install
added build ran

>>> grep -F validation failed (exit code 17) LOG.add-build-install
validation failed (exit code 17)

=== Skip a build removed by install
>>> grep -F All validation checks passed LOG.remove-build-install
✅ All validation checks passed ([DURATION])

=== Report native errors after install invalidates the manifest
>>> grep -x Error: validation failed LOG.invalidated-install
Error: validation failed

=== Run a build added by typegen
>>> grep -x added build ran LOG.add-build-typegen
added build ran

>>> grep -F validation failed (exit code 17) LOG.add-build-typegen
validation failed (exit code 17)

=== Skip a build removed by typegen
>>> grep -F All validation checks passed LOG.remove-build-typegen
✅ All validation checks passed ([DURATION])

=== Report native errors after typegen invalidates the manifest
>>> grep -x Error: validation failed LOG.invalidated-typegen
Error: validation failed
6 changes: 6 additions & 0 deletions acceptance/apps/validate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scripts": {
"build": "echo build",
"test": "echo test"
}
}
1 change: 1 addition & 0 deletions acceptance/apps/validate/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading