Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cc030f0
feat(ci): detect persist config from print-config
matejchalk Dec 4, 2024
01b6505
feat(ci): remove obsolete output option
matejchalk Dec 4, 2024
bdfc5b1
feat(ci): implement run many command resolution for each monorepo tool
matejchalk Dec 4, 2024
e7090eb
feat(ci): add parallel option
matejchalk Dec 4, 2024
c5611a0
test(ci): unit test individual monorepo handlers
matejchalk Dec 4, 2024
a89d5d0
feat(ci): filter nx run-many by projects from nx show projects as fal…
matejchalk Dec 5, 2024
ef1258c
test(ci): unit test package helpers
matejchalk Dec 5, 2024
ff62fda
test(ci-e2e): run actual git diff, only replace FETCH_HEAD
matejchalk Dec 5, 2024
0952ed6
test(ci-e2e): extract repo setup
matejchalk Dec 5, 2024
aafcd96
test(ci-e2e): extract mock api provider
matejchalk Dec 5, 2024
a5b802d
fix(ci): handle non-JSON prefix/suffix lines from print-config
matejchalk Dec 5, 2024
c9bfd41
test(ci-e2e): rename standalone test fixture
matejchalk Dec 5, 2024
c813dd7
feat(ci): sort nx projects alphabetically
matejchalk Dec 5, 2024
b21c654
test(ci-e2e): set up nx monorepo fixture and test push event
matejchalk Dec 5, 2024
c493a12
fix(ci): ensure valid output directory for reports and merged diff
matejchalk Dec 6, 2024
accf9a9
test(ci-e2e): add e2e test for pull request flow in monorepo mode
matejchalk Dec 6, 2024
d589f97
feat(ci): copy merged-report-diff.md from project to root
matejchalk Dec 6, 2024
a8a6fc8
fix(ci): resolve outputDir correctly by running workspace commands in…
matejchalk Dec 6, 2024
2c8d198
fix(ci): only copy merged-report-diff.md when paths are different
matejchalk Dec 6, 2024
e286887
test(ci-e2e): add e2e test for npm workspaces
matejchalk Dec 6, 2024
ec72489
test(ci-e2e): silence CLI stdout in tests to reduce logs
matejchalk Dec 6, 2024
29205f0
test(ci): prepare integration test setup to reuse for monorepo mode
matejchalk Dec 6, 2024
0ef24a9
test(ci): integration test push event for each monorepo tool
matejchalk Dec 9, 2024
fd2ced2
test(ci): integration test all monorepo tools for pull requests
matejchalk Dec 9, 2024
9a4c6bd
test(ci): reduce nesting in fixtures folder
matejchalk Dec 9, 2024
2c6ab2b
refactor(ci): add missing .js extensions in imports
matejchalk Dec 10, 2024
95edb82
refactor(ci-e2e): add missing .js extensions in imports
matejchalk Dec 10, 2024
823ff28
test(ci-e2e): fix hanging commands by disabling nx daemon
matejchalk Dec 10, 2024
839e17b
refactor(ci): split standalone/monorepo modes into separate functions
matejchalk Dec 11, 2024
3638ba6
feat(utils): implement type guard for nullable object props
matejchalk Dec 11, 2024
b4443ba
feat(ci): implement bulk collecting reports for parallel monorepo runs
matejchalk Dec 11, 2024
cc34b20
test(ci): assert autorun calls in monorepo mode
matejchalk Dec 13, 2024
258d27c
test(ci-e2e): include parallel in Nx monorepo test
matejchalk Dec 13, 2024
2351937
test(ci): add integration tests for custom monorepo setups
matejchalk Dec 13, 2024
491379e
refactor(ci): split up overlarge run.ts and runProjectsInBulk
matejchalk Dec 13, 2024
2b23bb5
refactor(ci): avoid hardcoded default concurrency for turborepo and pnpm
matejchalk Dec 13, 2024
191bc55
test(ci): fix failing path matched on Windows
matejchalk Dec 13, 2024
527eb55
ci(ci): fix code-pushup coverage error for missing tsconfig in nx tests
matejchalk Dec 13, 2024
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
14 changes: 14 additions & 0 deletions e2e/ci-e2e/mocks/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Comment, ProviderAPIClient } from '@code-pushup/ci';

export const MOCK_COMMENT: Comment = {
id: 42,
body: '... <!-- generated by @code-pushup/ci -->',
url: 'https://github.com/<owner>/<repo>/pull/1#issuecomment-42',
};

export const MOCK_API: ProviderAPIClient = {
maxCommentChars: 1_000_000,
createComment: () => Promise.resolve(MOCK_COMMENT),
updateComment: () => Promise.resolve(MOCK_COMMENT),
listComments: () => Promise.resolve([]),
};
1 change: 1 addition & 0 deletions e2e/ci-e2e/mocks/fixtures/basic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!');
1 change: 0 additions & 1 deletion e2e/ci-e2e/mocks/fixtures/ci-test-repo/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const DEFAULT_CATEGORIES = [
{
slug: 'ts-migration',
title: 'TypeScript migration',
refs: [
{ type: 'audit', plugin: 'ts-migration', slug: 'ts-files', weight: 1 },
],
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { crawlFileSystem } from '@code-pushup/utils';

export default function tsMigrationPlugin(url) {
return {
slug: 'ts-migration',
title: 'TypeScript migration',
icon: 'typescript',
audits: [
{
slug: 'ts-files',
title: 'Source files converted from JavaScript to TypeScript',
},
],
runner: async () => {
const paths = await crawlFileSystem({
directory: fileURLToPath(dirname(url)),
pattern: /\.[jt]s$/,
});
const jsPaths = paths.filter(path => path.endsWith('.js'));
const tsPaths = paths.filter(path => path.endsWith('.ts'));
const jsFileCount = jsPaths.length;
const tsFileCount = tsPaths.length;
const ratio = tsFileCount / (jsFileCount + tsFileCount);
const percentage = Math.round(ratio * 100);
return [
{
slug: 'ts-files',
value: percentage,
score: ratio,
displayValue: `${percentage}% converted`,
details: {
issues: jsPaths.map(file => ({
message: 'Use .ts file extension instead of .js',
severity: 'warning',
source: { file },
})),
},
},
];
},
};
}
42 changes: 42 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/npm-workspaces/package-lock.json

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

6 changes: 6 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/npm-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DEFAULT_CATEGORIES } from '../../code-pushup/categories.js';
import tsMigrationPlugin from '../../code-pushup/ts-migration.plugin.js';

export default {
plugins: [tsMigrationPlugin(import.meta.url)],
categories: DEFAULT_CATEGORIES,
};
10 changes: 10 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@example/cli",
"version": "1.2.3",
"scripts": {
"code-pushup": "code-pushup --no-progress"
},
"dependencies": {
"@example/core": "1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DEFAULT_CATEGORIES } from '../../code-pushup/categories.js';
import tsMigrationPlugin from '../../code-pushup/ts-migration.plugin.js';

export default {
plugins: [tsMigrationPlugin(import.meta.url)],
categories: DEFAULT_CATEGORIES,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@example/core",
"version": "1.2.3",
"scripts": {
"code-pushup": "code-pushup --no-progress"
},
"dependencies": {
"@example/utils": "1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DEFAULT_CATEGORIES } from '../../code-pushup/categories.js';
import tsMigrationPlugin from '../../code-pushup/ts-migration.plugin.js';

export default {
plugins: [tsMigrationPlugin(import.meta.url)],
categories: DEFAULT_CATEGORIES,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@example/utils",
"version": "1.2.3",
"scripts": {
"code-pushup": "code-pushup --no-progress"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resolveConfig } from '../../code-pushup.preset.js';

export default resolveConfig(import.meta.url);
9 changes: 9 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "api",
"projectType": "application",
"targets": {
"code-pushup": {
"command": "npx @code-pushup/cli --no-progress --config=apps/api/code-pushup.config.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resolveConfig } from '../../code-pushup.preset.js';

export default resolveConfig(import.meta.url);
9 changes: 9 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "cms",
"projectType": "application",
"targets": {
"code-pushup": {
"command": "npx @code-pushup/cli --no-progress --config=apps/cms/code-pushup.config.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resolveConfig } from '../../code-pushup.preset.js';

export default resolveConfig(import.meta.url);
9 changes: 9 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "web",
"projectType": "application",
"targets": {
"code-pushup": {
"command": "npx @code-pushup/cli --no-progress --config=apps/web/code-pushup.config.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!');
66 changes: 66 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/code-pushup.preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { crawlFileSystem } from '@code-pushup/utils';

export function resolveConfig(url) {
const directory = fileURLToPath(dirname(url));
return {
persist: {
outputDir: join(directory, '.code-pushup'),
},
plugins: [
{
slug: 'ts-migration',
title: 'TypeScript migration',
icon: 'typescript',
audits: [
{
slug: 'ts-files',
title: 'Source files converted from JavaScript to TypeScript',
},
],
runner: async () => {
const paths = await crawlFileSystem({
directory,
pattern: /\.[jt]s$/,
});
const jsPaths = paths.filter(path => path.endsWith('.js'));
const tsPaths = paths.filter(path => path.endsWith('.ts'));
const jsFileCount = jsPaths.length;
const tsFileCount = tsPaths.length;
const ratio = tsFileCount / (jsFileCount + tsFileCount);
const percentage = Math.round(ratio * 100);
return [
{
slug: 'ts-files',
value: percentage,
score: ratio,
displayValue: `${percentage}% converted`,
details: {
issues: jsPaths.map(file => ({
message: 'Use .ts file extension instead of .js',
severity: 'warning',
source: { file },
})),
},
},
];
},
},
],
categories: [
{
slug: 'ts-migration',
title: 'TypeScript migration',
refs: [
{
type: 'audit',
plugin: 'ts-migration',
slug: 'ts-files',
weight: 1,
},
],
},
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resolveConfig } from '../../code-pushup.preset.js';

export default resolveConfig(import.meta.url);
9 changes: 9 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ui",
"projectType": "library",
"targets": {
"code-pushup": {
"command": "npx @code-pushup/cli --no-progress --config=libs/ui/code-pushup.config.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import assert from 'node:assert';
import test from 'node:test';

test('1984', () => {
assert.equal(2 + 2, 5);
});
1 change: 1 addition & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resolveConfig } from '../../code-pushup.preset.js';

export default resolveConfig(import.meta.url);
9 changes: 9 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "utils",
"projectType": "library",
"targets": {
"code-pushup": {
"command": "npx @code-pushup/cli --no-progress --config=libs/utils/code-pushup.config.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world!');
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import assert from 'node:assert';
import test from 'node:test';

test('1984', () => {
assert.equal(2 + 2, 5);
});
4 changes: 4 additions & 0 deletions e2e/ci-e2e/mocks/fixtures/nx-monorepo/nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "../../../../../node_modules/nx/schemas/nx-schema.json",
"useDaemonProcess": false
}
43 changes: 43 additions & 0 deletions e2e/ci-e2e/mocks/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { cp } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { simpleGit } from 'simple-git';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import { teardownTestFolder } from '@code-pushup/test-setup';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
initGitRepo,
simulateGitFetch,
} from '@code-pushup/test-utils';

export type TestRepo = Awaited<ReturnType<typeof setupTestRepo>>;

export async function setupTestRepo(folder: string) {
const fixturesDir = join(
fileURLToPath(dirname(import.meta.url)),
'fixtures',
folder,
);
const baseDir = join(
process.cwd(),
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
folder,
);

await cp(fixturesDir, baseDir, { recursive: true });

const git = await initGitRepo(simpleGit, { baseDir });
await simulateGitFetch(git);

await git.add('.');
await git.commit('Initial commit');

return {
git,
baseDir,
cleanup: () => teardownTestFolder(baseDir),
};
}
Loading
Loading