Skip to content

Commit

Permalink
Fix @kie/act-js types
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Jun 17, 2024
1 parent ba0b925 commit c708fe4
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 52 deletions.
17 changes: 17 additions & 0 deletions src/types/modules/act.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type {MockStep as ActMockStep, StepIdentifier as ActStepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';

declare module '@kie/act-js' {
type StepIdentifier = ActStepIdentifier & {
id?: string;
name: string;
run?: string;
mockWith?: string;
with?: string;
envs?: string[];
inputs?: string[];
};

type MockStep = ActMockStep;

export type {StepIdentifier, MockStep};
}
2 changes: 1 addition & 1 deletion workflow_tests/authorChecklist.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/cherryPick.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/failureNotifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/lockDeploys.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/authorChecklistMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

// checklist
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/cherryPickMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

// validateactor
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/createNewVersionMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

// validateactor
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/deployBlockerMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

// updateChecklist
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/deployMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

const DEPLOY_STAGING__CHECKOUT__STEP_MOCK = createMockStep('Checkout staging branch', 'Checking out staging branch', 'DEPLOY_STAGING', ['ref', 'token']);
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/finishReleaseCycleMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

// validate
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/mocks/lintMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import {createMockStep} from '../utils/utils';

// lint
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/platformDeploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/preDeploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/reviewerChecklist.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/test.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {MockStep} from '@kie/act-js';
import {MockGithub} from '@kie/mock-github';
import type {CreateRepositoryFile} from '@kie/mock-github';
import path from 'path';
Expand Down
16 changes: 7 additions & 9 deletions workflow_tests/utils/JobMocker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import type {PathOrFileDescriptor} from 'fs';
import fs from 'fs';
import path from 'path';
import yaml from 'yaml';
import type CustemStepIdentifier from './types';

// eslint-disable-next-line @typescript-eslint/naming-convention
type YamlMockJob = Omit<MockJob, 'runsOn'> & {'runs-on'?: string};
Expand All @@ -13,7 +12,7 @@ type YamlWorkflow = {
};

type MockJob = {
steps: Array<CustemStepIdentifier | StepIdentifier>;
steps: StepIdentifier[];
uses?: string;
secrets?: string[];
with?: string;
Expand Down Expand Up @@ -52,13 +51,12 @@ class JobMocker {
delete job.with;
}
job.steps = mockJob.steps.map((step) => {
const customStep = step as CustemStepIdentifier;
const mockStep: CustemStepIdentifier = {
name: customStep.name,
const mockStep = {
name: step.name,
run: step.mockWith,
};
if (customStep.id) {
mockStep.id = customStep.id;
} as StepIdentifier;
if (step.id) {
mockStep.id = step.id;
}
if (jobWith) {
mockStep.with = jobWith;
Expand Down
24 changes: 10 additions & 14 deletions workflow_tests/utils/preGenerateTest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint no-console: ["error", { allow: ["warn", "log"] }] */
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {StepIdentifier} from '@kie/act-js';
import type {PathLike} from 'fs';
import fs from 'fs';
import path from 'path';
import {exit} from 'process';
import yaml from 'yaml';
import type {YamlMockJob, YamlWorkflow} from './JobMocker';
import type CustemStepIdentifier from './types';

const workflowsDirectory = path.resolve(__dirname, '..', '..', '.github', 'workflows');
const workflowTestsDirectory = path.resolve(__dirname, '..');
Expand Down Expand Up @@ -93,7 +92,7 @@ describe('test workflow ${workflowName}', () => {
});
`;

const mockStepTemplate = (stepMockName: string, step: CustemStepIdentifier, jobId: string | undefined) => `
const mockStepTemplate = (stepMockName: string, step: StepIdentifier, jobId: string | undefined) => `
const ${stepMockName} = utils.createMockStep(
'${step.name ?? ''}',
'${step.name ?? ''}',
Expand Down Expand Up @@ -201,12 +200,11 @@ const parseWorkflowFile = (workflow: YamlWorkflow) => {
steps: [],
};
job.steps.forEach((step) => {
const step2 = step as CustemStepIdentifier;
const workflowStep = {
name: step2.name ?? '',
inputs: Object.keys(step2.with ?? {}),
envs: step2.envs ?? [],
};
name: step.name ?? '',
inputs: Object.keys(step.with ?? {}),
envs: step.envs ?? [],
} as StepIdentifier;
workflowJobs[jobId].steps.push(workflowStep);
});
});
Expand All @@ -219,8 +217,7 @@ const getMockFileContent = (workflowName: string, jobs: Record<string, YamlMockJ
let mockStepsContent = `\n// ${jobId.toLowerCase()}`;
const stepMocks: string[] = [];
job.steps.forEach((step) => {
const customStep = step as CustemStepIdentifier;
const stepMockName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__${customStep.name
const stepMockName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__${step.name
.replaceAll(' ', '_')
.replaceAll('-', '_')
.replaceAll(',', '')
Expand All @@ -229,7 +226,7 @@ const getMockFileContent = (workflowName: string, jobs: Record<string, YamlMockJ
.replaceAll('.js', '')
.toUpperCase()}__STEP_MOCK`;
stepMocks.push(stepMockName);
mockStepsContent += mockStepTemplate(stepMockName, customStep, jobId);
mockStepsContent += mockStepTemplate(stepMockName, step, jobId);
});

const jobMocksName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__STEP_MOCKS`;
Expand All @@ -246,9 +243,8 @@ const getAssertionsFileContent = (jobs: Record<string, YamlMockJob>): string =>

Object.entries(jobs).forEach(([jobId, job]) => {
let stepAssertionsContent = '';
job.steps.forEach((step: CustemStepIdentifier | StepIdentifier) => {
const customStep = step as CustemStepIdentifier;
stepAssertionsContent += stepAssertionTemplate(customStep.name, jobId.toUpperCase(), customStep.name, customStep.inputs, customStep.envs);
job.steps.forEach((step: StepIdentifier) => {
stepAssertionsContent += stepAssertionTemplate(step.name, jobId.toUpperCase(), step.name, step.inputs, step.envs);
});
const jobAssertionName = `assert${jobId.charAt(0).toUpperCase() + jobId.slice(1)}JobExecuted`;
jobAssertions.push(jobAssertionName);
Expand Down
13 changes: 0 additions & 13 deletions workflow_tests/utils/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion workflow_tests/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StepIdentifier} from '@kie/act-js';
import type {EventJSON} from '@kie/act-js/build/src/action-event/action-event.types';
import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import fs from 'fs';
import path from 'path';
import yaml from 'yaml';
Expand Down

0 comments on commit c708fe4

Please sign in to comment.