Skip to content

Commit

Permalink
ci: add Nx target for running Code PushUp commands on whole repo
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Jan 9, 2024
1 parent a59d3f1 commit 3e0e878
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for uploading to portal
CP_SERVER=
CP_API_KEY=
CP_ORGANIZATION=
CP_PROJECT=
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ jobs:
cache: npm
- name: Install dependencies
run: npm ci
- name: Build CLI and ESLint plugin
run: npx nx run-many -t build -p cli,plugin-eslint,examples-plugins --parallel=3
- name: Collect Code PushUp report
run: npx dist/packages/cli --config code-pushup.config.ts collect
run: npx nx run-collect
- name: Upload Code PushUp report to portal
run: npx dist/packages/cli --config code-pushup.config.ts upload
run: npx nx run-upload
- name: Save report files as workflow artifact
uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ npx nx build cli

# lint projects affected by changes (compared to main branch)
npx nx affected:lint

# run Code PushUp command on this repository
npx nx run-collect
```

## Git
Expand Down
31 changes: 19 additions & 12 deletions code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import eslintPlugin, {
import type { CoreConfig } from './packages/models/src';

// load upload configuration from environment
const envSchema = z.object({
CP_SERVER: z.string().url(),
CP_API_KEY: z.string().min(1),
CP_ORGANIZATION: z.string().min(1),
CP_PROJECT: z.string().min(1),
});
const envSchema = z
.object({
CP_SERVER: z.string().url(),
CP_API_KEY: z.string().min(1),
CP_ORGANIZATION: z.string().min(1),
CP_PROJECT: z.string().min(1),
})
.partial();
const env = await envSchema.parseAsync(process.env);

const config: CoreConfig = {
Expand All @@ -29,12 +31,17 @@ const config: CoreConfig = {
format: ['json', 'md'],
},

upload: {
server: env.CP_SERVER,
apiKey: env.CP_API_KEY,
organization: env.CP_ORGANIZATION,
project: env.CP_PROJECT,
},
...(env.CP_SERVER &&
env.CP_API_KEY &&
env.CP_ORGANIZATION &&
env.CP_PROJECT && {
upload: {
server: env.CP_SERVER,
apiKey: env.CP_API_KEY,
organization: env.CP_ORGANIZATION,
project: env.CP_PROJECT,
},
}),

plugins: [
await eslintPlugin(await eslintConfigFromNxProjects()),
Expand Down
27 changes: 27 additions & 0 deletions project.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@
"tag": "{tag}",
"notes": "{notes}"
}
},
"run-collect": {
"command": "npx dist/packages/cli collect --config=code-pushup.config.ts",
"dependsOn": [
{
"projects": ["cli", "plugin-eslint", "examples-plugins"],
"target": "build"
}
]
},
"run-upload": {
"command": "npx dist/packages/cli upload --config=code-pushup.config.ts",
"dependsOn": [
{
"projects": ["cli", "plugin-eslint", "examples-plugins"],
"target": "build"
}
]
},
"run-autorun": {
"command": "npx dist/packages/cli autorun --config=code-pushup.config.ts",
"dependsOn": [
{
"projects": ["cli", "plugin-eslint", "examples-plugins"],
"target": "build"
}
]
}
}
}

0 comments on commit 3e0e878

Please sign in to comment.