-
Notifications
You must be signed in to change notification settings - Fork 16
feat: add caching options to cli #1059
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
bb5afa3
feat: add persist.report output to CLI
BioPhoton b992caf
fix: revert changes
BioPhoton 9b9616e
Merge remote-tracking branch 'origin/main' into add-caching-options-t…
BioPhoton ccfc1df
fix: adjust models
BioPhoton 894cf68
test: adjust e2e tests for caching
BioPhoton 26d5f7b
test: add int tests for caching
BioPhoton 2688343
test: fix int tests
BioPhoton 8f421a6
test: add e2e tests
BioPhoton 30e904c
docs: add docs
BioPhoton e8ac86f
fix: fix lint violation
BioPhoton f510678
docs: update Nx example
BioPhoton d5e9fab
docs: update caching examples
BioPhoton 44f7b7c
Merge remote-tracking branch 'origin/main' into add-caching-options-t…
BioPhoton f9d63b8
Update packages/cli/src/lib/implementation/core-config.options.ts
BioPhoton b2e4fac
Update packages/cli/README.md
BioPhoton fd8c37e
Update packages/cli/docs/nx-caching.md
BioPhoton bf1718c
Update packages/cli/docs/nx-caching.md
BioPhoton caf8053
Update packages/cli/docs/turbo-caching.md
BioPhoton f3b9223
Update packages/cli/docs/nx-caching.md
BioPhoton 531bedb
fix: update help output with caching options
BioPhoton 520faa5
docs: fix typos
BioPhoton 3d1c1cd
docs: adjust command example
BioPhoton 4373c4c
docs: adjust command example
BioPhoton 121ba4e
docs: adjust config example
BioPhoton 0b52c07
Update packages/cli/docs/nx-caching.md
BioPhoton 5fb3d87
docs: options docs
BioPhoton fdcd289
docs: adjust nx targets
BioPhoton 9e6702a
docs: adjust nx targets 2
BioPhoton 005d49e
Update packages/cli/docs/turbo-caching.md
BioPhoton ba7f967
Update packages/cli/docs/turbo-caching.md
BioPhoton 76e3f86
docs: adjust turbo targets 1
BioPhoton b80b659
docs: add category filter
BioPhoton 2fede24
docs: fix typo
BioPhoton 98dedef
docs: fix target outputs
BioPhoton 612dcb8
docs: fix turbo docs
BioPhoton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Caching Example Nx | ||
|
||
To cache plugin runner output, you can use the `--cache.write` and `--cache.read` options in combination with `--onlyPlugins` and `--persist.skipReports` command options. | ||
|
||
## `{projectRoot}/code-pushup.config.ts` | ||
|
||
```ts | ||
import coveragePlugin from '@code-pushup/coverage-plugin'; | ||
import jsPackagesPlugin from '@code-pushup/js-packages-plugin'; | ||
import type { CoreConfig } from '@code-pushup/models'; | ||
|
||
export default { | ||
plugins: [ | ||
await coveragePlugin({ | ||
reports: ['coverage/lcov.info'], | ||
}), | ||
await jsPackagesPlugin(), | ||
], | ||
upload: { | ||
server: 'https://api.code-pushup.example.com/graphql', | ||
organization: 'my-org', | ||
project: 'lib-a', | ||
apiKey: process.env.CP_API_KEY, | ||
}, | ||
} satisfies CoreConfig; | ||
``` | ||
|
||
## `{projectRoot}/project.json` | ||
|
||
```json | ||
{ | ||
"name": "lib-a", | ||
"targets": { | ||
"int-test": { | ||
"cache": true, | ||
"outputs": ["{options.coverage.reportsDirectory}"], | ||
"executor": "@nx/vite:test", | ||
"options": { | ||
"configFile": "packages/lib-a/vitest.int.config.ts", | ||
"coverage.reportsDirectory": "{projectRoot}/coverage/int-test" | ||
} | ||
}, | ||
"unit-test": { | ||
"cache": true, | ||
"outputs": ["{options.coverage.reportsDirectory}"], | ||
"executor": "@nx/vite:test", | ||
"options": { | ||
"configFile": "packages/lib-a/vitest.unit.config.ts", | ||
"coverage.reportsDirectory": "{projectRoot}/coverage/unit-test" | ||
} | ||
}, | ||
"code-pushup-coverage": { | ||
"cache": true, | ||
"outputs": ["{projectRoot}/.code-pushup/coverage"], | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "npx @code-pushup/cli collect", | ||
"args": ["--config={projectRoot}/code-pushup.config.ts", "--cache.write=true", "--persist.skipReports=true", "--persist.outputDir={projectRoot}/.code-pushup", "--upload.project={projectName}"] | ||
}, | ||
"dependsOn": ["unit-test", "int-test"] | ||
}, | ||
"code-pushup": { | ||
"cache": true, | ||
"outputs": ["{projectRoot}/.code-pushup"], | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "npx @code-pushup/cli", | ||
"args": ["--config={projectRoot}/code-pushup.config.ts", "--cache.read=true", "--persist.outputDir={projectRoot}/.code-pushup", "--upload.project={projectName}"] | ||
}, | ||
"dependsOn": ["code-pushup-coverage"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Nx Task Graph | ||
|
||
This configuration creates the following task dependency graph: | ||
|
||
**Legend:** | ||
|
||
- 🐳 = Cached target | ||
|
||
```mermaid | ||
graph TD | ||
A[lib-a:code-pushup 🐳] --> B[lib-a:code-pushup-coverage 🐳] | ||
B --> C[lib-a:unit-test 🐳] | ||
B --> D[lib-a:int-test 🐳] | ||
``` | ||
|
||
## Command Line Example | ||
|
||
```bash | ||
# Run all affected project plugins `coverage` and cache the output if configured | ||
nx affected --target=code-pushup-coverage | ||
|
||
# Run all affected projects with plugins `coverage` and `js-packages` and upload the report to the portal | ||
nx affected --target=code-pushup | ||
``` | ||
|
||
This approach has the following benefits: | ||
|
||
1. **Parallel Execution**: Plugins can run in parallel | ||
2. **Fine-grained Caching**: Code level cache invalidation enables usage of [affected](https://nx.dev/recipes/affected-tasks) command | ||
3. **Dependency Management**: Leverage Nx task dependencies and its caching strategy | ||
4. **Clear Separation**: Each plugin has its own target for better debugging and maintainability |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Caching Example Turborepo | ||
|
||
To cache plugin runner output with Turborepo, wire Code Pushup into your turbo.json pipeline and pass Code Pushup flags (`--cache.write`, `--cache.read`, `--onlyPlugins`, `--persist.skipReports`) through task scripts. Turborepo will cache task outputs declared in outputs, and you can target affected packages with `--filter=[origin/main]`. | ||
|
||
## `{projectRoot}/code-pushup.config.ts` | ||
|
||
```ts | ||
import coveragePlugin from '@code-pushup/coverage-plugin'; | ||
import jsPackagesPlugin from '@code-pushup/js-packages-plugin'; | ||
import type { CoreConfig } from '@code-pushup/models'; | ||
|
||
export default { | ||
plugins: [ | ||
await coveragePlugin({ | ||
reports: ['coverage/lcov.info'], | ||
}), | ||
await jsPackagesPlugin(), | ||
], | ||
upload: { | ||
server: 'https://api.code-pushup.example.com/graphql', | ||
organization: 'my-org', | ||
project: 'lib-a', | ||
apiKey: process.env.CP_API_KEY, | ||
}, | ||
} satisfies CoreConfig; | ||
``` | ||
|
||
## Root `turbo.json` | ||
|
||
```json | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"tasks": { | ||
"unit-test": { | ||
"outputs": ["coverage/unit-test/**"] | ||
}, | ||
"int-test": { | ||
"outputs": ["coverage/int-test/**"] | ||
}, | ||
"code-pushup-coverage": { | ||
"dependsOn": ["unit-test", "int-test"], | ||
"outputs": [".code-pushup/coverage/**"] | ||
}, | ||
"code-pushup": { | ||
"dependsOn": ["code-pushup-coverage"], | ||
"outputs": [".code-pushup/**"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## `packages/lib-a/package.json` | ||
|
||
```json | ||
{ | ||
"name": "lib-a", | ||
"scripts": { | ||
"unit-test": "vitest --config packages/lib-a/vitest.unit.config.ts --coverage", | ||
"int-test": "vitest --config packages/lib-a/vitest.int.config.ts --coverage", | ||
"code-pushup-coverage": "code-pushup collect --config packages/lib-a/code-pushup.config.ts --cache.write --persist.skipReports --persist.outputDir packages/lib-a/.code-pushup --onlyPlugins=coverage", | ||
"code-pushup": "code-pushup autorun --config packages/lib-a/code-pushup.config.ts --cache.read --persist.outputDir packages/lib-a/.code-pushup" | ||
} | ||
} | ||
``` | ||
|
||
> **Note:** `--cache.write` is used on the collect step to persist each plugin's audit-outputs.json; `--cache.read` is used on the autorun step to reuse those outputs. | ||
|
||
## Turborepo Task Graph | ||
|
||
This configuration creates the following task dependency graph: | ||
|
||
**Legend:** | ||
|
||
- ⚡ = Cached target (via outputs) | ||
|
||
```mermaid | ||
graph TD | ||
A[lib-a:code-pushup ⚡] --> B[lib-a:code-pushup-coverage] | ||
B --> C[lib-a:unit-test ⚡] | ||
B --> D[lib-a:int-test ⚡] | ||
``` | ||
|
||
## Command Line Examples | ||
|
||
```bash | ||
# Run all affected project plugins `coverage` and cache the output if configured | ||
turbo run code-pushup-coverage --filter=[origin/main] | ||
|
||
# Run all affected projects with plugins `coverage` and `js-packages` and upload the report to the portal | ||
turbo run code-pushup --filter=[origin/main] | ||
``` | ||
|
||
This approach has the following benefits: | ||
|
||
1. **Parallel Execution**: Plugins can run in parallel | ||
2. **Finegrained Caching**: Code level cache invalidation enables usage of affected packages filtering | ||
3. **Dependency Management**: Leverage Turborepo task dependencies and its caching strategy | ||
4. **Clear Separation**: Each plugin has its own target for better debugging and maintainability |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.