diff --git a/src/types/modules/act.d.ts b/src/types/modules/act.d.ts new file mode 100644 index 000000000000..5fe00ec479cf --- /dev/null +++ b/src/types/modules/act.d.ts @@ -0,0 +1,14 @@ +import type {StepIdentifier as ActStepIdentifier} from '@kie/act-js'; + +declare module '@kie/act-js' { + // eslint-disable-next-line rulesdir/no-inline-named-export + export declare type StepIdentifier = { + id?: string; + name: string; + run?: string; + mockWith?: string; + with?: string; + envs?: string[]; + inputs?: string[]; + } & Omit; +} diff --git a/workflow_tests/createNewVersion.test.js b/workflow_tests/createNewVersion.test.ts similarity index 93% rename from workflow_tests/createNewVersion.test.js rename to workflow_tests/createNewVersion.test.ts index 08ac63ba9948..05dcc2b10073 100644 --- a/workflow_tests/createNewVersion.test.js +++ b/workflow_tests/createNewVersion.test.ts @@ -1,12 +1,13 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/createNewVersionAssertions'); -const mocks = require('./mocks/createNewVersionMocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; +import {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/createNewVersionAssertions'; +import mocks from './mocks/createNewVersionMocks'; +import ExtendedAct from './utils/ExtendedAct'; +import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); // 90 sec -let mockGithub; +let mockGithub: MockGithub; + const FILES_TO_COPY_INTO_TEST_REPO = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { @@ -16,7 +17,7 @@ const FILES_TO_COPY_INTO_TEST_REPO = [ ]; describe('test workflow createNewVersion', () => { - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -24,7 +25,7 @@ describe('test workflow createNewVersion', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testCreateNewVersionWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, @@ -56,7 +57,7 @@ describe('test workflow createNewVersion', () => { describe('actor is admin', () => { const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS; it('executes full workflow', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -79,7 +80,7 @@ describe('test workflow createNewVersion', () => { describe('actor is writer', () => { const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS; it('executes full workflow', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -102,7 +103,7 @@ describe('test workflow createNewVersion', () => { describe('actor is reader', () => { const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS; it('stops after validation', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -124,7 +125,7 @@ describe('test workflow createNewVersion', () => { describe('one step fails', () => { it('announces failure on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -133,7 +134,7 @@ describe('test workflow createNewVersion', () => { validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS, createNewVersion: utils.deepCopy(mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS), }; - testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], [], [], false); + testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], {}, {}, false); const result = await act.runEvent(event, { workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'), mockSteps: testMockSteps, @@ -146,7 +147,7 @@ describe('test workflow createNewVersion', () => { }); it('chooses source branch depending on the SEMVER_LEVEL', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, {SEMVER_LEVEL: 'MAJOR'}); diff --git a/workflow_tests/deploy.test.js b/workflow_tests/deploy.test.ts similarity index 93% rename from workflow_tests/deploy.test.js rename to workflow_tests/deploy.test.ts index cf5b658d3ffb..4edb3b252d38 100644 --- a/workflow_tests/deploy.test.js +++ b/workflow_tests/deploy.test.ts @@ -1,12 +1,13 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/deployAssertions'); -const mocks = require('./mocks/deployMocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; +import {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/deployAssertions'; +import mocks from './mocks/deployMocks'; +import ExtendedAct from './utils/ExtendedAct'; +import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; +let mockGithub: MockGithub; + const FILES_TO_COPY_INTO_TEST_REPO = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { @@ -16,7 +17,7 @@ const FILES_TO_COPY_INTO_TEST_REPO = [ ]; describe('test workflow deploy', () => { - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -24,7 +25,7 @@ describe('test workflow deploy', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testDeployWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, @@ -48,7 +49,7 @@ describe('test workflow deploy', () => { }; describe('push', () => { it('to main - nothing triggered', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( @@ -75,7 +76,7 @@ describe('test workflow deploy', () => { }); it('to staging - deployStaging triggered', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( @@ -102,7 +103,7 @@ describe('test workflow deploy', () => { }); it('to production - deployProduction triggered', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( @@ -130,7 +131,7 @@ describe('test workflow deploy', () => { }); it('different event than push - workflow does not execute', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); let act = new ExtendedAct(repoPath, workflowPath); const testMockSteps = { diff --git a/workflow_tests/deployBlocker.test.js b/workflow_tests/deployBlocker.test.ts similarity index 92% rename from workflow_tests/deployBlocker.test.js rename to workflow_tests/deployBlocker.test.ts index 42c4f9e741f7..d6ee67f97f2c 100644 --- a/workflow_tests/deployBlocker.test.js +++ b/workflow_tests/deployBlocker.test.ts @@ -1,12 +1,13 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/deployBlockerAssertions'); -const mocks = require('./mocks/deployBlockerMocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; +import {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/deployBlockerAssertions'; +import mocks from './mocks/deployBlockerMocks'; +import ExtendedAct from './utils/ExtendedAct'; +import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; +let mockGithub: MockGithub; + const FILES_TO_COPY_INTO_TEST_REPO = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { @@ -23,7 +24,7 @@ describe('test workflow deployBlocker', () => { SLACK_WEBHOOK: 'dummy_slack_webhook', }; - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -31,7 +32,7 @@ describe('test workflow deployBlocker', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testDeployBlockerWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, @@ -57,6 +58,7 @@ describe('test workflow deployBlocker', () => { issue: { title: 'Labeled issue title', number: '1234', + // eslint-disable-next-line @typescript-eslint/naming-convention html_url: 'http://issue.html.url', }, }; @@ -64,7 +66,7 @@ describe('test workflow deployBlocker', () => { const testEventOptions = utils.deepCopy(eventOptions); testEventOptions.label = {name: 'DeployBlockerCash'}; it('runs the workflow and announces success on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); @@ -90,7 +92,7 @@ describe('test workflow deployBlocker', () => { }); describe('one step fails', () => { it('announces failure on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); @@ -130,7 +132,7 @@ describe('test workflow deployBlocker', () => { const testEventOptions = utils.deepCopy(eventOptions); testEventOptions.label = {name: 'Different Label'}; it('does not run workflow', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); diff --git a/workflow_tests/finishReleaseCycle.test.js b/workflow_tests/finishReleaseCycle.test.ts similarity index 94% rename from workflow_tests/finishReleaseCycle.test.js rename to workflow_tests/finishReleaseCycle.test.ts index 20ab66471d91..44f9c57ab9da 100644 --- a/workflow_tests/finishReleaseCycle.test.js +++ b/workflow_tests/finishReleaseCycle.test.ts @@ -1,12 +1,13 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/finishReleaseCycleAssertions'); -const mocks = require('./mocks/finishReleaseCycleMocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; +import {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/finishReleaseCycleAssertions'; +import mocks from './mocks/finishReleaseCycleMocks'; +import ExtendedAct from './utils/ExtendedAct'; +import type {MockJobs} from './utils/JobMocker'; +import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; +let mockGithub: MockGithub; const FILES_TO_COPY_INTO_TEST_REPO = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { @@ -16,7 +17,7 @@ const FILES_TO_COPY_INTO_TEST_REPO = [ ]; describe('test workflow finishReleaseCycle', () => { - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -24,7 +25,7 @@ describe('test workflow finishReleaseCycle', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testFinishReleaseCycleWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, @@ -50,7 +51,7 @@ describe('test workflow finishReleaseCycle', () => { describe('actor is a team member', () => { describe('no deploy blockers', () => { it('production updated, new version created', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( @@ -71,7 +72,7 @@ describe('test workflow finishReleaseCycle', () => { updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, }; - const testMockJobs = { + const testMockJobs: MockJobs = { createNewPatchVersion: { steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, outputs: { @@ -96,7 +97,7 @@ describe('test workflow finishReleaseCycle', () => { }); describe('deploy blockers', () => { it('production not updated, new version not created, issue reopened', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( @@ -143,7 +144,7 @@ describe('test workflow finishReleaseCycle', () => { }); describe('actor is not a team member', () => { it('production not updated, new version not created, issue reopened', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( @@ -190,7 +191,7 @@ describe('test workflow finishReleaseCycle', () => { }); describe('issue does not have StagingDeployCash', () => { it('validate job not run', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( diff --git a/workflow_tests/lint.test.js b/workflow_tests/lint.test.ts similarity index 91% rename from workflow_tests/lint.test.js rename to workflow_tests/lint.test.ts index b13b4c1c3564..f6ede86c5fd3 100644 --- a/workflow_tests/lint.test.js +++ b/workflow_tests/lint.test.ts @@ -1,12 +1,14 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/lintAssertions'); -const mocks = require('./mocks/lintMocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; +import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; +import {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/lintAssertions'; +import mocks from './mocks/lintMocks'; +import ExtendedAct from './utils/ExtendedAct'; +import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); -let mockGithub; +let mockGithub: MockGithub; + const FILES_TO_COPY_INTO_TEST_REPO = [ ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { @@ -19,7 +21,7 @@ describe('test workflow lint', () => { const githubToken = 'dummy_github_token'; const actor = 'Dummy Actor'; - beforeAll(async () => { + beforeAll(() => { // in case of the tests being interrupted without cleanup the mock repo directory may be left behind // which breaks the next test run, this removes any possible leftovers utils.removeMockRepoDir(); @@ -27,7 +29,7 @@ describe('test workflow lint', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testLintWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, @@ -47,13 +49,14 @@ describe('test workflow lint', () => { const event = 'workflow_call'; const eventOptions = {}; it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { + const testMockSteps: MockStep = { lint: mocks.LINT__LINT__STEP_MOCKS, }; + const result = await act.runEvent(event, { workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), mockSteps: testMockSteps, @@ -66,13 +69,14 @@ describe('test workflow lint', () => { describe('actor is OSBotify', () => { const testActor = 'OSBotify'; it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { lint: mocks.LINT__LINT__STEP_MOCKS, }; + const result = await act.runEvent(event, { workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), mockSteps: testMockSteps, @@ -91,13 +95,14 @@ describe('test workflow lint', () => { action: 'opened', }; it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { lint: mocks.LINT__LINT__STEP_MOCKS, }; + const result = await act.runEvent(event, { workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), mockSteps: testMockSteps, @@ -110,13 +115,14 @@ describe('test workflow lint', () => { describe('actor is OSBotify', () => { const testActor = 'OSBotify'; it('does not run the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { lint: mocks.LINT__LINT__STEP_MOCKS, }; + const result = await act.runEvent(event, { workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), mockSteps: testMockSteps, @@ -133,13 +139,14 @@ describe('test workflow lint', () => { action: 'synchronize', }; it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { lint: mocks.LINT__LINT__STEP_MOCKS, }; + const result = await act.runEvent(event, { workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), mockSteps: testMockSteps, diff --git a/workflow_tests/utils/JobMocker.ts b/workflow_tests/utils/JobMocker.ts index b6dc99771dd2..171d625b2fe1 100644 --- a/workflow_tests/utils/JobMocker.ts +++ b/workflow_tests/utils/JobMocker.ts @@ -1,3 +1,4 @@ +import type {StepIdentifier} from '@kie/act-js'; import type {PathOrFileDescriptor} from 'fs'; import fs from 'fs'; import path from 'path'; @@ -11,12 +12,12 @@ type YamlWorkflow = { }; type MockJob = { - steps: MockJobStep[]; + steps: StepIdentifier[]; uses?: string; secrets?: string[]; with?: string; - outputs?: string[]; - runsOn?: string; + outputs?: Record; + runsOn: string; }; type MockJobs = Record; @@ -59,8 +60,8 @@ class JobMocker { jobWith = job.with; delete job.with; } - job.steps = mockJob.steps.map((step) => { - const mockStep: MockJobStep = { + job.steps = mockJob.steps.map((step): StepIdentifier => { + const mockStep: StepIdentifier = { name: step.name, run: step.mockWith, }; diff --git a/workflow_tests/utils/preGenerateTest.ts b/workflow_tests/utils/preGenerateTest.ts index 7698e618432d..c5e54d9a11c0 100644 --- a/workflow_tests/utils/preGenerateTest.ts +++ b/workflow_tests/utils/preGenerateTest.ts @@ -1,10 +1,11 @@ /* eslint no-console: ["error", { allow: ["warn", "log"] }] */ +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 {MockJobStep, YamlMockJob, YamlWorkflow} from './JobMocker'; +import type {YamlMockJob, YamlWorkflow} from './JobMocker'; const workflowsDirectory = path.resolve(__dirname, '..', '..', '.github', 'workflows'); const workflowTestsDirectory = path.resolve(__dirname, '..'); @@ -97,7 +98,7 @@ describe('test workflow ${workflowName}', () => { }); `; -const mockStepTemplate = (stepMockName: string, step: MockJobStep, jobId: string | undefined) => ` +const mockStepTemplate = (stepMockName: string, step: StepIdentifier, jobId: string | undefined) => ` const ${stepMockName} = utils.createMockStep( '${step.name ?? ''}', '${step.name ?? ''}', diff --git a/workflow_tests/utils/utils.ts b/workflow_tests/utils/utils.ts index df4cc0468963..2b4036c8b826 100644 --- a/workflow_tests/utils/utils.ts +++ b/workflow_tests/utils/utils.ts @@ -1,13 +1,10 @@ -import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; +import type {StepIdentifier} from '@kie/act-js'; +import type {EventJSON} from '@kie/act-js/build/src/action-event/action-event.types'; import fs from 'fs'; import path from 'path'; import yaml from 'yaml'; import type ExtendedAct from './ExtendedAct'; -type EventOptions = { - action?: string; -}; - type StepAssertionInputEntry = {key: string; value: string}; type StepAssertion = { @@ -19,7 +16,7 @@ type StepAssertion = { function setUpActParams( act: ExtendedAct, event: string | null = null, - eventOptions: EventOptions | null = null, + eventOptions: EventJSON | null = null, secrets: Record | null = null, githubToken: string | null = null, envVars: Record | null = null,