Skip to content

Commit

Permalink
Merge branch 'main' into history
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/utils/src/index.ts
  • Loading branch information
BioPhoton committed Mar 7, 2024
2 parents d25b857 + dab5822 commit ec997a4
Show file tree
Hide file tree
Showing 43 changed files with 286 additions and 208 deletions.
16 changes: 16 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Testing
*.test.ts @Tlacenka
/e2e/ @Tlacenka
/testing/ @Tlacenka
vite.config*.ts @Tlacenka

# Mocks
mocks/ @Tlacenka
/examples/react-todos-app/ @matejchalk
/testing/test-utils/src/lib/utils/dynamic-mocks/ @matejchalk

# Plugins
/packages/plugin-eslint/ @matejchalk
/packages/plugin-coverage/ @Tlacenka
/packages/plugin-lighthouse/ @BioPhoton
/examples/plugins/ @BioPhoton
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- '**/mocks/**'
- e2e/**
- testing/**
- '**/vitest.config*.ts'
- '**/vite.config*.ts'
- 'vitest.workspace.ts'

🦾 CI/CD:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: PR Title Commitlint Check
name: PR Commitlint

on:
pull_request:
types: [opened, synchronize, edited]

jobs:
check:
name: Check PR title
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
label:
name: Add PR labels
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [0.26.1](https://github.com/code-pushup/cli/compare/v0.26.0...v0.26.1) (2024-03-07)

# [0.26.0](https://github.com/code-pushup/cli/compare/v0.25.7...v0.26.0) (2024-03-06)

### Features

- **cli:** include commit info in report.json ([5965900](https://github.com/code-pushup/cli/commit/596590082c76b0b7915b2b339fa27baee9eaa678))

## [0.25.7](https://github.com/code-pushup/cli/compare/v0.25.6...v0.25.7) (2024-03-06)

## [0.25.6](https://github.com/code-pushup/cli/compare/v0.25.5...v0.25.6) (2024-03-05)

### Bug Fixes
Expand Down
13 changes: 6 additions & 7 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ describe('CLI collect', () => {
duration,
version,
...report
}: Report | PluginReport) => report;
/* eslint-enable @typescript-eslint/no-unused-vars */

const omitVariableReportData = (report: Report) =>
}: Omit<Report, 'commit'> | PluginReport) => report;
const omitVariableReportData = ({ commit, ...report }: Report) =>
omitVariableData({
...report,
plugins: report.plugins.map(omitVariableData) as PluginReport[],
});
/* eslint-enable @typescript-eslint/no-unused-vars */

beforeEach(async () => {
await cleanTestFolder('tmp/e2e');
Expand All @@ -37,7 +36,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/react-todos-app/report.json');
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
Expand Down Expand Up @@ -90,7 +89,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/react-todos-app/report.json');
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
Expand All @@ -106,7 +105,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
expect(stderr).toBe('');

const md = await readTextFile('tmp/react-todos-app/report.md');
const md = await readTextFile('tmp/e2e/react-todos-app/report.md');

expect(md).toContain('# Code PushUp Report');
expect(md).toContain(exampleCategoryTitle);
Expand Down
2 changes: 1 addition & 1 deletion examples/react-todos-app/code-pushup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const eslintAuditRef = (slug, weight) => ({

export default {
persist: {
outputDir: '../../tmp/react-todos-app',
outputDir: '../../tmp/e2e/react-todos-app',
},
plugins: [
await coveragePlugin({
Expand Down
10 changes: 4 additions & 6 deletions global-setup.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { execSync } from 'child_process';
import {
setup as globalSetup,
teardown as globalTeardown,
} from './global-setup';
import { setupTestFolder } from './testing/test-setup/src';
import { setup as globalSetup } from './global-setup';
import { setupTestFolder, teardownTestFolder } from './testing/test-setup/src';
import startLocalRegistry from './tools/scripts/start-local-registry';
import stopLocalRegistry from './tools/scripts/stop-local-registry';

Expand All @@ -21,5 +18,6 @@ export async function teardown() {
execSync('npm uninstall @code-pushup/cli');
execSync('npm uninstall @code-pushup/eslint-plugin');
execSync('npm uninstall @code-pushup/coverage-plugin');
await globalTeardown();
await teardownTestFolder('tmp/e2e');
await teardownTestFolder('tmp/local-registry');
}
6 changes: 0 additions & 6 deletions global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { teardownTestFolder } from './testing/test-setup/src';

export async function setup() {
process.env.TZ = 'UTC';
}

export async function teardown() {
await teardownTestFolder('tmp');
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code-pushup/cli-source",
"version": "0.25.6",
"version": "0.26.1",
"license": "MIT",
"homepage": "https://github.com/code-pushup/cli#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code-pushup/cli",
"version": "0.25.6",
"version": "0.26.1",
"license": "MIT",
"bin": {
"code-pushup": "index.js"
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/lib/autorun/autorun-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
collectAndPersistReports,
upload,
} from '@code-pushup/core';
import { getLatestCommit, validateCommitData } from '@code-pushup/utils';
import { CLI_NAME } from '../constants';
import {
collectSuccessfulLog,
Expand Down Expand Up @@ -50,10 +49,7 @@ export function yargsAutorunCommandObject() {

if (options.upload) {
const { url } = await upload(options);
const commitData = await getLatestCommit();
if (validateCommitData(commitData, { throwError: true })) {
uploadSuccessfulLog(url);
}
uploadSuccessfulLog(url);
} else {
ui().logger.warning('Upload skipped because configuration is not set.');
renderIntegratePortalHint();
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/lib/upload/upload-command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import chalk from 'chalk';
import { ArgumentsCamelCase, CommandModule } from 'yargs';
import { UploadOptions, upload } from '@code-pushup/core';
import { getLatestCommit, validateCommitData } from '@code-pushup/utils';
import { CLI_NAME } from '../constants';
import {
renderIntegratePortalHint,
Expand All @@ -24,11 +23,7 @@ export function yargsUploadCommandObject() {
throw new Error('Upload configuration not set');
}
const { url } = await upload(options);

const commitData = await getLatestCommit();
if (validateCommitData(commitData, { throwError: true })) {
uploadSuccessfulLog(url);
}
uploadSuccessfulLog(url);
},
} satisfies CommandModule;
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code-pushup/core",
"version": "0.25.6",
"version": "0.26.1",
"license": "MIT",
"dependencies": {
"@code-pushup/models": "*",
Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/lib/collect-and-persist.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
MINIMAL_CONFIG_MOCK,
MINIMAL_REPORT_MOCK,
} from '@code-pushup/test-utils';
import { collectAndPersistReports } from './collect-and-persist';
import {
CollectAndPersistReportsOptions,
collectAndPersistReports,
} from './collect-and-persist';
import { collect } from './implementation/collect';
import { logPersistedResults, persistReport } from './implementation/persist';

Expand All @@ -19,7 +22,8 @@ vi.mock('./implementation/persist', () => ({

describe('collectAndPersistReports', () => {
it('should call collect and persistReport with correct parameters in non-verbose mode', async () => {
const nonVerboseConfig = {
const nonVerboseConfig: CollectAndPersistReportsOptions = {
categories: [],
...MINIMAL_CONFIG_MOCK,
persist: {
outputDir: 'output',
Expand All @@ -33,12 +37,15 @@ describe('collectAndPersistReports', () => {

expect(collect).toHaveBeenCalledWith(nonVerboseConfig);

expect(persistReport).toHaveBeenCalledWith(
expect(persistReport).toHaveBeenCalledWith<
Parameters<typeof persistReport>
>(
{
packageName: '@code-pushup/core',
version: '0.0.1',
date: expect.stringMatching(ISO_STRING_REGEXP),
duration: 666,
commit: expect.any(Object),
categories: expect.any(Array),
plugins: expect.any(Array),
},
Expand All @@ -53,7 +60,8 @@ describe('collectAndPersistReports', () => {
});

it('should call collect and persistReport with correct parameters in verbose mode', async () => {
const verboseConfig = {
const verboseConfig: CollectAndPersistReportsOptions = {
categories: [],
...MINIMAL_CONFIG_MOCK,
persist: {
outputDir: 'output',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { vol } from 'memfs';
import { describe, expect, it } from 'vitest';
import { commitSchema } from '@code-pushup/models';
import { MEMFS_VOLUME, MINIMAL_CONFIG_MOCK } from '@code-pushup/test-utils';
import { collect } from './collect';

describe('collect', () => {
it('should execute with valid options', async () => {
vol.fromJSON({}, MEMFS_VOLUME);
const report = await collect({
categories: [],
...MINIMAL_CONFIG_MOCK,
verbose: true,
progress: false,
Expand All @@ -27,5 +29,7 @@ describe('collect', () => {
},
}),
);

expect(() => commitSchema.parse(report.commit)).not.toThrow();
});
});
4 changes: 3 additions & 1 deletion packages/core/src/lib/implementation/collect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CoreConfig, Report } from '@code-pushup/models';
import { calcDuration } from '@code-pushup/utils';
import { calcDuration, getLatestCommit } from '@code-pushup/utils';
import { name, version } from '../../../package.json';
import { GlobalOptions } from '../types';
import { executePlugins } from './execute-plugin';
Expand All @@ -17,8 +17,10 @@ export async function collect(options: CollectOptions): Promise<Report> {
const { plugins, categories } = options;
const date = new Date().toISOString();
const start = performance.now();
const commit = await getLatestCommit();
const pluginOutputs = await executePlugins(plugins, options);
return {
commit,
packageName: name,
version,
date,
Expand Down
34 changes: 14 additions & 20 deletions packages/core/src/lib/implementation/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import {
directoryExists,
generateMdReport,
generateStdoutSummary,
getLatestCommit,
logMultipleFileResults,
scoreReport,
sortReport,
validateCommitData,
} from '@code-pushup/utils';

export class PersistDirError extends Error {
Expand All @@ -35,24 +33,20 @@ export async function persistReport(
console.warn(generateStdoutSummary(sortedScoredReport));

// collect physical format outputs
const results = await Promise.all(
format.map(async reportType => {
switch (reportType) {
case 'json':
return {
format: 'json',
content: JSON.stringify(report, null, 2),
};
case 'md':
const commitData = await getLatestCommit();
validateCommitData(commitData);
return {
format: 'md',
content: generateMdReport(sortedScoredReport, commitData),
};
}
}),
);
const results = format.map(reportType => {
switch (reportType) {
case 'json':
return {
format: 'json',
content: JSON.stringify(report, null, 2),
};
case 'md':
return {
format: 'md',
content: generateMdReport(sortedScoredReport),
};
}
});

if (!(await directoryExists(outputDir))) {
try {
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/lib/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
uploadToPortal,
} from '@code-pushup/portal-client';
import { PersistConfig, Report, UploadConfig } from '@code-pushup/models';
import { getLatestCommit, loadReport } from '@code-pushup/utils';
import { loadReport } from '@code-pushup/utils';
import { reportToGQL } from './implementation/report-to-gql';
import { GlobalOptions } from './types';

Expand All @@ -27,15 +27,14 @@ export async function upload(
...options.persist,
format: 'json',
});
const commitData = await getLatestCommit();
if (!commitData) {
throw new Error('no commit data available');
if (!report.commit) {
throw new Error('Commit must be linked in order to upload report');
}

const data: SaveReportMutationVariables = {
organization,
project,
commit: commitData.hash,
commit: report.commit.hash,
...reportToGQL(report),
};

Expand Down
Loading

0 comments on commit ec997a4

Please sign in to comment.