Skip to content

Commit a6d3965

Browse files
BioPhotonJohn Doematejchalk
authored
chore: add standalone target with plugin caching (#1062)
**Followup of:** - #1059 **Precondition:** - #1061 **This PR includes:** - ~add helper to load envVars~ - adjusted `nx.json` - add `defaultTargets` for main and plugin `code-pushup` targets - add default inputs - add plugin caching to code-pushup target - cache js-packages and invalidate daily - GH adjustments - added `affected` and `--parallel=3` - Adjust path helper that that created Nx project graph to use `readCachedProjectGraph` to avoid problems when running plugins in parallel > [!note] > I cache the `js-packges` plugin target, against our discussion, as only in this PR I would have saved ~4min **Followup Todos:** - move `zod2md.ts` under `tools` and leverage `"!{projectRoot}/tools/**/*"` in `nx.json#namedInputs.production` - rename `nx-plugin/mock` to `models/mocks` and adjust inputs - cleanup e2e targets leverage `nx.json#targetDefaults` - include only relevant projects in `plugin-eslint` config - stricter task dependencies to avoid running tracked libs e.g. `nx run test-nx-utils:unit-test` is executed ATM - understand why e2e tests fail if `nx.json#defaultTargets[N].@nx/vite:test` as empty (`{}`) target is removed **Followup PRs:** - #1035 --------- Co-authored-by: John Doe <john.doe@example.com> Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com>
1 parent 158ee7a commit a6d3965

File tree

15 files changed

+318
-80
lines changed

15 files changed

+318
-80
lines changed

.github/workflows/code-pushup-fork.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Code PushUp (fork)
1+
name: Code PushUp - Standalone Mode (fork)
22

33
# separated from code-pushup.yml for security reasons
44
# => requires permissions to create PR comment
@@ -20,19 +20,23 @@ permissions:
2020
jobs:
2121
code-pushup:
2222
runs-on: ubuntu-latest
23-
name: Code PushUp
23+
name: Run Code PushUp (fork)
2424
if: github.event.pull_request.head.repo.fork
2525
steps:
2626
- name: Checkout repository
2727
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
2830
- name: Set up Node.js
2931
uses: actions/setup-node@v4
3032
with:
3133
node-version-file: .nvmrc
3234
cache: npm
35+
- name: Set base and head for Nx affected commands
36+
uses: nrwl/nx-set-shas@v4
3337
- name: Install dependencies
3438
run: npm ci
3539
- name: Run Code PushUp action
3640
uses: code-pushup/github-action@v0
3741
with:
38-
bin: npx nx code-pushup --
42+
bin: npx nx code-pushup --nx-bail --

.github/workflows/code-pushup.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Code PushUp
1+
name: Code PushUp - Standalone Mode
22

33
on:
44
push:
@@ -16,7 +16,7 @@ permissions:
1616
jobs:
1717
code-pushup:
1818
runs-on: ubuntu-latest
19-
name: Code PushUp
19+
name: Run Code PushUp
2020
# ignore PRs from forks, handled by code-pushup-fork.yml
2121
if: ${{ !github.event.pull_request.head.repo.fork }}
2222
env:
@@ -27,14 +27,18 @@ jobs:
2727
steps:
2828
- name: Checkout repository
2929
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
3032
- name: Set up Node.js
3133
uses: actions/setup-node@v4
3234
with:
3335
node-version-file: .nvmrc
3436
cache: npm
37+
- name: Set base and head for Nx affected commands
38+
uses: nrwl/nx-set-shas@v4
3539
- name: Install dependencies
3640
run: npm ci
3741
- name: Run Code PushUp action
3842
uses: code-pushup/github-action@v0
3943
with:
40-
bin: npx nx code-pushup --
44+
bin: npx nx code-pushup --nx-bail --

code-pushup.config.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dotenv/config';
2-
import { z } from 'zod';
32
import {
43
coverageCoreConfigNx,
54
eslintCoreConfigNx,
@@ -11,25 +10,17 @@ import {
1110
import type { CoreConfig } from './packages/models/src/index.js';
1211
import { mergeConfigs } from './packages/utils/src/index.js';
1312

14-
// load upload configuration from environment
15-
const envSchema = z.object({
16-
CP_SERVER: z.string().url(),
17-
CP_API_KEY: z.string().min(1),
18-
CP_ORGANIZATION: z.string().min(1),
19-
CP_PROJECT: z.string().min(1),
20-
});
21-
const { data: env } = await envSchema.safeParseAsync(process.env);
13+
const project = process.env['NX_TASK_TARGET_PROJECT'] || 'cli-workspace';
2214

2315
const config: CoreConfig = {
24-
...(env && {
16+
...(process.env['CP_API_KEY'] && {
2517
upload: {
26-
server: env.CP_SERVER,
27-
apiKey: env.CP_API_KEY,
28-
organization: env.CP_ORGANIZATION,
29-
project: 'cli-workspace',
18+
project,
19+
organization: 'code-pushup',
20+
server: 'https://api.staging.code-pushup.dev/graphql',
21+
apiKey: process.env['CP_API_KEY'],
3022
},
3123
}),
32-
3324
plugins: [],
3425
};
3526

code-pushup.preset.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import coveragePlugin, {
77
getNxCoveragePaths,
88
} from './packages/plugin-coverage/src/index.js';
99
import eslintPlugin, {
10-
eslintConfigFromNxProject,
10+
eslintConfigFromAllNxProjects,
1111
} from './packages/plugin-eslint/src/index.js';
1212
import type { ESLintTarget } from './packages/plugin-eslint/src/lib/config.js';
1313
import { nxProjectsToConfig } from './packages/plugin-eslint/src/lib/nx/projects-to-config.js';
@@ -172,11 +172,12 @@ export const eslintCoreConfigNx = async (
172172
projectName?: string,
173173
): Promise<CoreConfig> => ({
174174
plugins: [
175-
await eslintPlugin(
176-
await (projectName
177-
? eslintConfigFromNxProject(projectName)
178-
: eslintConfigFromPublishableNxProjects()),
179-
),
175+
projectName
176+
? await eslintPlugin({
177+
eslintrc: `packages/${projectName}/eslint.config.js`,
178+
patterns: ['.'],
179+
})
180+
: await eslintPlugin(await eslintConfigFromAllNxProjects()),
180181
],
181182
categories: eslintCategories,
182183
});

examples/plugins/code-pushup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
* `nx run-collect examples-plugins`
1717
*
1818
* - For all formats use `--persist.format=md,json`
19-
* - For better debugging use `--verbose --no-progress`
19+
* - For better debugging, use `--verbose --no-progress`
2020
*
2121
*/
2222

0 commit comments

Comments
 (0)