From b5c0c4f651e5656150e7b61f723ba82df1e853b2 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 13 Mar 2024 18:06:21 +0100 Subject: [PATCH 01/13] migrate lint.test, update utils wip --- workflow_tests/lint.test.ts | 178 ++++++++++++++++++++++++++++++++++ workflow_tests/utils/utils.ts | 10 +- 2 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 workflow_tests/lint.test.ts diff --git a/workflow_tests/lint.test.ts b/workflow_tests/lint.test.ts new file mode 100644 index 000000000000..4c2a15cfef43 --- /dev/null +++ b/workflow_tests/lint.test.ts @@ -0,0 +1,178 @@ +import type { MockGithub } from '@kie/mock-github'; +import kieMockGithub 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: MockGithub; + +const FILES_TO_COPY_INTO_TEST_REPO = [ + ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), + { + src: path.resolve(__dirname, '..', '.github', 'workflows', 'lint.yml'), + dest: '.github/workflows/lint.yml', + }, +]; + +describe('test workflow lint', () => { + const githubToken = 'dummy_github_token'; + const actor = 'Dummy Actor'; + + 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(); + }); + + beforeEach(async () => { + // create a local repository and copy required files + mockGithub = new kieMockGithub.MockGithub({ + repo: { + testLintWorkflowRepo: { + files: FILES_TO_COPY_INTO_TEST_REPO, + + // if any branches besides main are need add: pushedBranches: ['staging', 'production'], + }, + }, + }); + + await mockGithub.setup(); + }); + + afterEach(async () => { + await mockGithub.teardown(); + }); + describe('event is workflow_call', () => { + const event = 'workflow_call'; + const eventOptions = {}; + it('runs the lint', async () => { + 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, + }; + + try { + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); + + assertions.assertLintJobExecuted(result); + } catch (error) { + console.error(error); + } + }); + describe('actor is OSBotify', () => { + const testActor = 'OSBotify'; + it('runs the lint', async () => { + 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, + }; + + try { + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor: testActor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); + + assertions.assertLintJobExecuted(result); + } catch (error) { + console.error(error); + } + }); + }); + }); + describe('event is pull_request', () => { + const event = 'pull_request'; + describe('pull_request is opened', () => { + const eventOptions = { + action: 'opened', + }; + it('runs the lint', async () => { + 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, + }; + + try { + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); + + assertions.assertLintJobExecuted(result); + } catch (error) { + console.error(error); + } + }); + describe('actor is OSBotify', () => { + const testActor = 'OSBotify'; + it('does not run the lint', async () => { + 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, + actor: testActor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); + + assertions.assertLintJobExecuted(result, false); + }); + }); + }); + describe('pull_request is synchronized', () => { + const eventOptions = { + action: 'synchronize', + }; + it('runs the lint', async () => { + 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, + }; + + try { + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); + + assertions.assertLintJobExecuted(result); + } catch (error) { + console.error(error); + } + }); + }); + }); +}); \ No newline at end of file diff --git a/workflow_tests/utils/utils.ts b/workflow_tests/utils/utils.ts index 9583ec233e60..a8956daec985 100644 --- a/workflow_tests/utils/utils.ts +++ b/workflow_tests/utils/utils.ts @@ -5,12 +5,12 @@ import type {ExtendedAct} from './ExtendedAct'; import type {MockJobStep} from './JobMocker'; type EventOptions = { - action: string; + action?: string; }; function setUpActParams( act: ExtendedAct, - event = null, + event: string | null = null, eventOptions: EventOptions | null = null, secrets: Record | null = null, githubToken: string | null = null, @@ -165,7 +165,11 @@ function deepCopy(originalObject: TObject): TObject { return JSON.parse(JSON.stringify(originalObject)); } -function getLogFilePath(workflowName: string, testName: string) { +function getLogFilePath(workflowName: string, testName: string | undefined) { + if (!testName) { + throw new Error(); + } + const logsDir = path.resolve(__dirname, '..', 'logs'); if (!fs.existsSync(logsDir)) { fs.mkdirSync(logsDir); From 24045f7771cfb0e4fa49cb800d3c0688dbd61e59 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 13 Mar 2024 18:22:15 +0100 Subject: [PATCH 02/13] update utils --- workflow_tests/utils/utils.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/workflow_tests/utils/utils.ts b/workflow_tests/utils/utils.ts index a8956daec985..f614a514cc47 100644 --- a/workflow_tests/utils/utils.ts +++ b/workflow_tests/utils/utils.ts @@ -1,8 +1,8 @@ +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'; import type {ExtendedAct} from './ExtendedAct'; -import type {MockJobStep} from './JobMocker'; type EventOptions = { action?: string; @@ -65,7 +65,7 @@ function createMockStep( outEnvs: Record | null = null, isSuccessful = true, id = null, -) { +): StepIdentifier { const mockStepName = name; let mockWithCommand = 'echo [MOCK]'; if (jobId) { @@ -95,14 +95,16 @@ function createMockStep( if (!isSuccessful) { mockWithCommand += '\nexit 1'; } - const mockStep: MockJobStep = { + if (id) { + return { + id, + mockWith: mockWithCommand, + }; + } + return { name: mockStepName, mockWith: mockWithCommand, }; - if (id) { - mockStep.id = id; - } - return mockStep; } function createStepAssertion( From 4a12bce4a634cdd82ffa633425f441019fbfaf83 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 13 Mar 2024 21:14:18 +0100 Subject: [PATCH 03/13] migrate lint.test --- workflow_tests/lint.test.js | 154 ------------------------------------ workflow_tests/lint.test.ts | 10 +-- 2 files changed, 4 insertions(+), 160 deletions(-) delete mode 100644 workflow_tests/lint.test.js diff --git a/workflow_tests/lint.test.js b/workflow_tests/lint.test.js deleted file mode 100644 index bc51f31b657c..000000000000 --- a/workflow_tests/lint.test.js +++ /dev/null @@ -1,154 +0,0 @@ -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 eAct = require('./utils/ExtendedAct'); - -jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'lint.yml'), - dest: '.github/workflows/lint.yml', - }, -]; - -describe('test workflow lint', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - - beforeAll(async () => { - // 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(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ - repo: { - testLintWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are need add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('event is workflow_call', () => { - const event = 'workflow_call'; - const eventOptions = {}; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new eAct.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, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - describe('actor is OSBotify', () => { - const testActor = 'OSBotify'; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new eAct.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, - actor: testActor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - }); - }); - describe('event is pull_request', () => { - const event = 'pull_request'; - describe('pull_request is opened', () => { - const eventOptions = { - action: 'opened', - }; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new eAct.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, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - describe('actor is OSBotify', () => { - const testActor = 'OSBotify'; - it('does not run the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new eAct.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, - actor: testActor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result, false); - }); - }); - }); - describe('pull_request is synchronized', () => { - const eventOptions = { - action: 'synchronize', - }; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new eAct.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, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - }); - }); -}); diff --git a/workflow_tests/lint.test.ts b/workflow_tests/lint.test.ts index 4c2a15cfef43..40b545a77749 100644 --- a/workflow_tests/lint.test.ts +++ b/workflow_tests/lint.test.ts @@ -1,12 +1,10 @@ -import type { MockGithub } from '@kie/mock-github'; -import kieMockGithub from '@kie/mock-github'; +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 {ExtendedAct} from './utils/ExtendedAct'; import * as utils from './utils/utils'; - jest.setTimeout(90 * 1000); let mockGithub: MockGithub; @@ -30,7 +28,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, @@ -175,4 +173,4 @@ describe('test workflow lint', () => { }); }); }); -}); \ No newline at end of file +}); From cd33641f5fa636a125541a8c633afaf48a7135b9 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 14 Mar 2024 10:34:08 +0100 Subject: [PATCH 04/13] adjust utils, finishReleaseCycle wip --- workflow_tests/finishReleaseCycle.test.ts | 239 ++++++++++++++++++++++ workflow_tests/utils/utils.ts | 7 +- 2 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 workflow_tests/finishReleaseCycle.test.ts diff --git a/workflow_tests/finishReleaseCycle.test.ts b/workflow_tests/finishReleaseCycle.test.ts new file mode 100644 index 000000000000..e584ae77efb4 --- /dev/null +++ b/workflow_tests/finishReleaseCycle.test.ts @@ -0,0 +1,239 @@ +import type {MockGithub} from '@kie/mock-github'; +import kieMockGithub from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/finishReleaseCycleAssertions'; +import mocks from './mocks/finishReleaseCycleMocks'; +import {ExtendedAct} from './utils/ExtendedAct'; +import * as utils from './utils/utils'; + +jest.setTimeout(90 * 1000); +let mockGithub: MockGithub; +const FILES_TO_COPY_INTO_TEST_REPO = [ + ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), + { + src: path.resolve(__dirname, '..', '.github', 'workflows', 'finishReleaseCycle.yml'), + dest: '.github/workflows/finishReleaseCycle.yml', + }, +]; + +describe('test workflow finishReleaseCycle', () => { + 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(); + }); + + beforeEach(async () => { + // create a local repository and copy required files + mockGithub = new kieMockGithub.MockGithub({ + repo: { + testFinishReleaseCycleWorkflowRepo: { + files: FILES_TO_COPY_INTO_TEST_REPO, + }, + }, + }); + + await mockGithub.setup(); + }); + + afterEach(async () => { + await mockGithub.teardown(); + }); + const secrets = { + OS_BOTIFY_TOKEN: 'dummy_token', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + SLACK_WEBHOOK: 'dummy_slack_webhook', + OS_BOTIFY_APP_ID: 'os_botify_app_id', + OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key', + }; + describe('issue closed', () => { + describe('issue has StagingDeployCash', () => { + describe('actor is a team member', () => { + describe('no deploy blockers', () => { + it('production updated, new version created', async () => { + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); + let act = new ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'issues', + { + action: 'closed', + type: 'closed', + issue: { + labels: [{name: 'StagingDeployCash'}], + number: '1234', + }, + }, + secrets, + ); + const testMockSteps = { + validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, + updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, + updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, + }; + const testMockJobs = { + createNewPatchVersion: { + steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, + outputs: { + // eslint-disable-next-line no-template-curly-in-string + NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', + }, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent('issues', { + workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), + mockSteps: testMockSteps, + actor: 'Dummy Author', + logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + assertions.assertValidateJobExecuted(result, '1234'); + assertions.assertUpdateProductionJobExecuted(result); + assertions.assertCreateNewPatchVersionJobExecuted(result); + assertions.assertUpdateStagingJobExecuted(result); + }); + }); + describe('deploy blockers', () => { + it('production not updated, new version not created, issue reopened', async () => { + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); + let act = new ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'issues', + { + action: 'closed', + type: 'closed', + issue: { + labels: [{name: 'StagingDeployCash'}], + number: '1234', + }, + }, + secrets, + ); + const testMockSteps = { + validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_BLOCKERS__STEP_MOCKS, + updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, + updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, + }; + const testMockJobs = { + createNewPatchVersion: { + steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, + outputs: { + // eslint-disable-next-line no-template-curly-in-string + NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', + }, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent('issues', { + workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), + mockSteps: testMockSteps, + actor: 'Dummy Author', + logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + assertions.assertValidateJobExecuted(result, '1234', true, true, true); + assertions.assertUpdateProductionJobExecuted(result, false); + assertions.assertCreateNewPatchVersionJobExecuted(result, false); + assertions.assertUpdateStagingJobExecuted(result, false); + }); + }); + }); + 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 workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); + let act = new ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'issues', + { + action: 'closed', + type: 'closed', + issue: { + labels: [{name: 'StagingDeployCash'}], + number: '1234', + }, + }, + secrets, + ); + const testMockSteps = { + validate: mocks.FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, + updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, + updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, + }; + const testMockJobs = { + createNewPatchVersion: { + steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, + outputs: { + // eslint-disable-next-line no-template-curly-in-string + NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', + }, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent('issues', { + workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), + mockSteps: testMockSteps, + actor: 'Dummy Author', + logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + assertions.assertValidateJobExecuted(result, '1234', true, false, false); + assertions.assertUpdateProductionJobExecuted(result, false); + assertions.assertCreateNewPatchVersionJobExecuted(result, false); + assertions.assertUpdateStagingJobExecuted(result, false); + }); + }); + }); + describe('issue does not have StagingDeployCash', () => { + it('validate job not run', async () => { + const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); + let act = new ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'issues', + { + action: 'closed', + type: 'closed', + issue: { + labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], + number: '1234', + }, + }, + secrets, + ); + const testMockSteps = { + validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, + updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, + updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, + }; + const testMockJobs = { + createNewPatchVersion: { + steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, + outputs: { + // eslint-disable-next-line no-template-curly-in-string + NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', + }, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent('issues', { + workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), + mockSteps: testMockSteps, + actor: 'Dummy Author', + logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + assertions.assertValidateJobExecuted(result, '1234', false); + assertions.assertUpdateProductionJobExecuted(result, false); + assertions.assertCreateNewPatchVersionJobExecuted(result, false); + assertions.assertUpdateStagingJobExecuted(result, false); + }); + }); + }); +}); diff --git a/workflow_tests/utils/utils.ts b/workflow_tests/utils/utils.ts index 7fc57eed75ad..eafb7cb7a0a3 100644 --- a/workflow_tests/utils/utils.ts +++ b/workflow_tests/utils/utils.ts @@ -1,17 +1,14 @@ +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'; import type {ExtendedAct} from './ExtendedAct'; -type EventOptions = { - action?: string; -}; - 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, From 00ca25a1790e68a44c679cc2bb0beff6d4a237bf Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 15 Mar 2024 00:10:54 +0100 Subject: [PATCH 05/13] add module augmentation, correct types --- src/types/modules/act.d.ts | 14 ++++++++++++++ workflow_tests/finishReleaseCycle.test.ts | 8 ++++---- workflow_tests/lint.test.ts | 3 ++- workflow_tests/utils/JobMocker.ts | 21 ++++++--------------- workflow_tests/utils/preGenerateTest.ts | 5 +++-- workflow_tests/utils/utils.ts | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 src/types/modules/act.d.ts 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/finishReleaseCycle.test.ts b/workflow_tests/finishReleaseCycle.test.ts index e584ae77efb4..38f1fb865ef8 100644 --- a/workflow_tests/finishReleaseCycle.test.ts +++ b/workflow_tests/finishReleaseCycle.test.ts @@ -1,9 +1,9 @@ -import type {MockGithub} from '@kie/mock-github'; -import kieMockGithub from '@kie/mock-github'; +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 {MockJob} from './utils/JobMocker'; import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); @@ -25,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, @@ -72,7 +72,7 @@ describe('test workflow finishReleaseCycle', () => { updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, }; - const testMockJobs = { + const testMockJobs: Record = { createNewPatchVersion: { steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, outputs: { diff --git a/workflow_tests/lint.test.ts b/workflow_tests/lint.test.ts index 40b545a77749..9ad695215c46 100644 --- a/workflow_tests/lint.test.ts +++ b/workflow_tests/lint.test.ts @@ -1,3 +1,4 @@ +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'; @@ -52,7 +53,7 @@ describe('test workflow lint', () => { 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, }; diff --git a/workflow_tests/utils/JobMocker.ts b/workflow_tests/utils/JobMocker.ts index 3bbdaa118e0c..443f5217dee3 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,24 +12,14 @@ type YamlWorkflow = { }; type MockJob = { - steps: MockJobStep[]; + steps: StepIdentifier[]; uses?: string; secrets?: string[]; with?: string; - outputs?: string[]; + outputs?: Record; runsOn: string; }; -type MockJobStep = { - id?: string; - name: string; - run?: string; - mockWith?: string; - with?: string; - envs?: string[]; - inputs?: string[]; -}; - class JobMocker { workflowFile: string; @@ -57,8 +48,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, }; @@ -113,4 +104,4 @@ class JobMocker { // eslint-disable-next-line import/prefer-default-export export {JobMocker}; -export type {MockJob, YamlWorkflow, YamlMockJob, MockJobStep}; +export type {MockJob, YamlWorkflow, YamlMockJob}; diff --git a/workflow_tests/utils/preGenerateTest.ts b/workflow_tests/utils/preGenerateTest.ts index 1bc5a01975e7..816de7ecdf77 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 eafb7cb7a0a3..e82f540a676c 100644 --- a/workflow_tests/utils/utils.ts +++ b/workflow_tests/utils/utils.ts @@ -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'; From 24281bd8a9cea5eb06bf826179fd2d6daa9623d5 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 15 Mar 2024 00:14:50 +0100 Subject: [PATCH 06/13] cleanup --- workflow_tests/finishReleaseCycle.test.js | 238 ---------------------- 1 file changed, 238 deletions(-) delete mode 100644 workflow_tests/finishReleaseCycle.test.js diff --git a/workflow_tests/finishReleaseCycle.test.js b/workflow_tests/finishReleaseCycle.test.js deleted file mode 100644 index 26b4d2f60afc..000000000000 --- a/workflow_tests/finishReleaseCycle.test.js +++ /dev/null @@ -1,238 +0,0 @@ -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 eAct = require('./utils/ExtendedAct'); - -jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'finishReleaseCycle.yml'), - dest: '.github/workflows/finishReleaseCycle.yml', - }, -]; - -describe('test workflow finishReleaseCycle', () => { - beforeAll(async () => { - // 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(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ - repo: { - testFinishReleaseCycleWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - const secrets = { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - OS_BOTIFY_APP_ID: 'os_botify_app_id', - OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key', - }; - describe('issue closed', () => { - describe('issue has StagingDeployCash', () => { - describe('actor is a team member', () => { - describe('no deploy blockers', () => { - it('production updated, new version created', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'StagingDeployCash'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234'); - assertions.assertUpdateProductionJobExecuted(result); - assertions.assertCreateNewPatchVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result); - }); - }); - describe('deploy blockers', () => { - it('production not updated, new version not created, issue reopened', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'StagingDeployCash'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234', true, true, true); - assertions.assertUpdateProductionJobExecuted(result, false); - assertions.assertCreateNewPatchVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - }); - }); - 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 workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'StagingDeployCash'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234', true, false, false); - assertions.assertUpdateProductionJobExecuted(result, false); - assertions.assertCreateNewPatchVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - }); - }); - describe('issue does not have StagingDeployCash', () => { - it('validate job not run', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234', false); - assertions.assertUpdateProductionJobExecuted(result, false); - assertions.assertCreateNewPatchVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - }); - }); -}); From efebcca6e14fb7c713a5078c7bb056854d3fed5d Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 15 Mar 2024 00:18:35 +0100 Subject: [PATCH 07/13] migrate deployBlocker test --- workflow_tests/deployBlocker.test.ts | 161 +++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 workflow_tests/deployBlocker.test.ts diff --git a/workflow_tests/deployBlocker.test.ts b/workflow_tests/deployBlocker.test.ts new file mode 100644 index 000000000000..0e1c85fc1d1f --- /dev/null +++ b/workflow_tests/deployBlocker.test.ts @@ -0,0 +1,161 @@ +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: MockGithub; + +const FILES_TO_COPY_INTO_TEST_REPO = [ + ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), + { + src: path.resolve(__dirname, '..', '.github', 'workflows', 'deployBlocker.yml'), + dest: '.github/workflows/deployBlocker.yml', + }, +]; + +describe('test workflow deployBlocker', () => { + const githubToken = 'dummy_github_token'; + const actor = 'Dummy Author'; + const secrets = { + OS_BOTIFY_TOKEN: 'dummy_osbotify_token', + SLACK_WEBHOOK: 'dummy_slack_webhook', + }; + + 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(); + }); + + beforeEach(async () => { + // create a local repository and copy required files + mockGithub = new MockGithub({ + repo: { + testDeployBlockerWorkflowRepo: { + files: FILES_TO_COPY_INTO_TEST_REPO, + + // if any branches besides main are need add: pushedBranches: ['staging', 'production'], + }, + }, + }); + + await mockGithub.setup(); + }); + + afterEach(async () => { + await mockGithub.teardown(); + }); + describe('issue labeled', () => { + const event = 'issues'; + const eventOptions = { + action: 'labeled', + label: { + name: 'DeployBlockerCash', + }, + issue: { + title: 'Labeled issue title', + number: '1234', + // eslint-disable-next-line @typescript-eslint/naming-convention + html_url: 'http://issue.html.url', + }, + }; + describe('label is DeployBlockerCash', () => { + 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 workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); + let act = new ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); + const testMockSteps = { + deployBlocker: mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS, + }; + const testMockJobs = { + updateChecklist: { + steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + + assertions.assertUpdateChecklistJobExecuted(result); + assertions.assertDeployBlockerJobExecuted(result); + }); + describe('one step fails', () => { + it('announces failure on Slack', async () => { + 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, {}, {}); + const testMockSteps = { + deployBlocker: utils.deepCopy(mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS), + }; + testMockSteps.deployBlocker[1] = utils.createMockStep( + 'Give the issue/PR the Hourly, Engineering labels', + 'Give the issue/PR the Hourly, Engineering labels', + 'DEPLOYBLOCKER', + [], + ['GITHUB_TOKEN'], + null, + null, + false, + ); + const testMockJobs = { + updateChecklist: { + steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + + assertions.assertUpdateChecklistJobExecuted(result); + assertions.assertDeployBlockerJobExecuted(result, true, false, 1); + }); + }); + }); + describe('label is different', () => { + const testEventOptions = utils.deepCopy(eventOptions); + testEventOptions.label = {name: 'Different Label'}; + it('does not run workflow', async () => { + 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, {}, {}); + const testMockSteps = { + deployBlocker: mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS, + }; + const testMockJobs = { + updateChecklist: { + steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, + runsOn: 'ubuntu-latest', + }, + }; + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), + mockJobs: testMockJobs, + }); + + assertions.assertUpdateChecklistJobExecuted(result, false); + assertions.assertDeployBlockerJobExecuted(result, false); + }); + }); + }); +}); From e358e843d7da5c3af2e074f301f49fa006ec2fd7 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 15 Mar 2024 00:18:51 +0100 Subject: [PATCH 08/13] cleanup --- workflow_tests/deployBlocker.test.js | 159 --------------------------- 1 file changed, 159 deletions(-) delete mode 100644 workflow_tests/deployBlocker.test.js diff --git a/workflow_tests/deployBlocker.test.js b/workflow_tests/deployBlocker.test.js deleted file mode 100644 index 2fee3d01915a..000000000000 --- a/workflow_tests/deployBlocker.test.js +++ /dev/null @@ -1,159 +0,0 @@ -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 eAct = require('./utils/ExtendedAct'); - -jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'deployBlocker.yml'), - dest: '.github/workflows/deployBlocker.yml', - }, -]; - -describe('test workflow deployBlocker', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Author'; - const secrets = { - OS_BOTIFY_TOKEN: 'dummy_osbotify_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }; - - beforeAll(async () => { - // 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(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ - repo: { - testDeployBlockerWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are need add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('issue labeled', () => { - const event = 'issues'; - const eventOptions = { - action: 'labeled', - label: { - name: 'DeployBlockerCash', - }, - issue: { - title: 'Labeled issue title', - number: '1234', - html_url: 'http://issue.html.url', - }, - }; - describe('label is DeployBlockerCash', () => { - 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 workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); - const testMockSteps = { - deployBlocker: mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS, - }; - const testMockJobs = { - updateChecklist: { - steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertUpdateChecklistJobExecuted(result); - assertions.assertDeployBlockerJobExecuted(result); - }); - describe('one step fails', () => { - it('announces failure on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); - const testMockSteps = { - deployBlocker: utils.deepCopy(mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS), - }; - testMockSteps.deployBlocker[1] = utils.createMockStep( - 'Give the issue/PR the Hourly, Engineering labels', - 'Give the issue/PR the Hourly, Engineering labels', - 'DEPLOYBLOCKER', - [], - ['GITHUB_TOKEN'], - null, - null, - false, - ); - const testMockJobs = { - updateChecklist: { - steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertUpdateChecklistJobExecuted(result); - assertions.assertDeployBlockerJobExecuted(result, true, false, 1); - }); - }); - }); - describe('label is different', () => { - const testEventOptions = utils.deepCopy(eventOptions); - testEventOptions.label = {name: 'Different Label'}; - it('does not run workflow', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); - const testMockSteps = { - deployBlocker: mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS, - }; - const testMockJobs = { - updateChecklist: { - steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertUpdateChecklistJobExecuted(result, false); - assertions.assertDeployBlockerJobExecuted(result, false); - }); - }); - }); -}); From 711e626995858855fad8d230c04e52934da87b8a Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 15 Mar 2024 00:26:56 +0100 Subject: [PATCH 09/13] migrate deploy test --- .../{deploy.test.js => deploy.test.ts} | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) rename workflow_tests/{deploy.test.js => deploy.test.ts} (89%) diff --git a/workflow_tests/deploy.test.js b/workflow_tests/deploy.test.ts similarity index 89% rename from workflow_tests/deploy.test.js rename to workflow_tests/deploy.test.ts index b15a167d4702..35303122e70b 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 eAct = require('./utils/ExtendedAct'); +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,9 +49,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, 'push', @@ -75,9 +76,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, 'push', @@ -102,9 +103,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams( act, 'push', @@ -130,9 +131,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); const testMockSteps = { deployStaging: mocks.DEPLOY_STAGING_STEP_MOCKS, deployProduction: mocks.DEPLOY_PRODUCTION_STEP_MOCKS, From debaf2f708b903147c6e687667c8555cb8928da4 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 15 Mar 2024 00:38:16 +0100 Subject: [PATCH 10/13] migrate createNewVersion test --- ...rsion.test.js => createNewVersion.test.ts} | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) rename workflow_tests/{createNewVersion.test.js => createNewVersion.test.ts} (89%) diff --git a/workflow_tests/createNewVersion.test.js b/workflow_tests/createNewVersion.test.ts similarity index 89% rename from workflow_tests/createNewVersion.test.js rename to workflow_tests/createNewVersion.test.ts index dca1afbd9a41..1b2ffa101355 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 eAct = require('./utils/ExtendedAct'); +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,9 +57,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); const testMockSteps = { @@ -79,9 +80,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); const testMockSteps = { @@ -102,9 +103,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); const testMockSteps = { @@ -124,16 +125,16 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); const testMockSteps = { 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,9 +147,9 @@ 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 eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, {SEMVER_LEVEL: 'MAJOR'}); act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); const testMockSteps = { From f3ef5c08a085eaba51448454b840995789a9466a Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 20 Mar 2024 17:11:48 +0100 Subject: [PATCH 11/13] review fixes --- workflow_tests/lint.test.ts | 72 +++++++++++++++---------------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/workflow_tests/lint.test.ts b/workflow_tests/lint.test.ts index 121824fd733b..f6ede86c5fd3 100644 --- a/workflow_tests/lint.test.ts +++ b/workflow_tests/lint.test.ts @@ -57,18 +57,14 @@ describe('test workflow lint', () => { lint: mocks.LINT__LINT__STEP_MOCKS, }; - try { - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); - assertions.assertLintJobExecuted(result); - } catch (error) { - console.error(error); - } + assertions.assertLintJobExecuted(result); }); describe('actor is OSBotify', () => { const testActor = 'OSBotify'; @@ -81,18 +77,14 @@ describe('test workflow lint', () => { lint: mocks.LINT__LINT__STEP_MOCKS, }; - try { - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor: testActor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor: testActor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); - assertions.assertLintJobExecuted(result); - } catch (error) { - console.error(error); - } + assertions.assertLintJobExecuted(result); }); }); }); @@ -111,18 +103,14 @@ describe('test workflow lint', () => { lint: mocks.LINT__LINT__STEP_MOCKS, }; - try { - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); - assertions.assertLintJobExecuted(result); - } catch (error) { - console.error(error); - } + assertions.assertLintJobExecuted(result); }); describe('actor is OSBotify', () => { const testActor = 'OSBotify'; @@ -159,18 +147,14 @@ describe('test workflow lint', () => { lint: mocks.LINT__LINT__STEP_MOCKS, }; - try { - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), + mockSteps: testMockSteps, + actor, + logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), + }); - assertions.assertLintJobExecuted(result); - } catch (error) { - console.error(error); - } + assertions.assertLintJobExecuted(result); }); }); }); From ae1e35958e1c32e5b3b646463f8d8a063b12ce76 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 21 Mar 2024 10:22:38 +0100 Subject: [PATCH 12/13] review fixes --- workflow_tests/finishReleaseCycle.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow_tests/finishReleaseCycle.test.ts b/workflow_tests/finishReleaseCycle.test.ts index 8de38c1090ae..4f7ad5f1f9e2 100644 --- a/workflow_tests/finishReleaseCycle.test.ts +++ b/workflow_tests/finishReleaseCycle.test.ts @@ -3,7 +3,7 @@ import path from 'path'; import assertions from './assertions/finishReleaseCycleAssertions'; import mocks from './mocks/finishReleaseCycleMocks'; import ExtendedAct from './utils/ExtendedAct'; -import type {MockJob} from './utils/JobMocker'; +import type {MockJob, MockJobs} from './utils/JobMocker'; import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); @@ -72,7 +72,7 @@ describe('test workflow finishReleaseCycle', () => { updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, }; - const testMockJobs: Record = { + const testMockJobs: MockJobs = { createNewPatchVersion: { steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, outputs: { From 448af1fa3566607521bd34bc0a338bd14baad90b Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 21 Mar 2024 10:32:37 +0100 Subject: [PATCH 13/13] cleanup --- workflow_tests/finishReleaseCycle.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow_tests/finishReleaseCycle.test.ts b/workflow_tests/finishReleaseCycle.test.ts index 4f7ad5f1f9e2..44f9c57ab9da 100644 --- a/workflow_tests/finishReleaseCycle.test.ts +++ b/workflow_tests/finishReleaseCycle.test.ts @@ -3,7 +3,7 @@ import path from 'path'; import assertions from './assertions/finishReleaseCycleAssertions'; import mocks from './mocks/finishReleaseCycleMocks'; import ExtendedAct from './utils/ExtendedAct'; -import type {MockJob, MockJobs} from './utils/JobMocker'; +import type {MockJobs} from './utils/JobMocker'; import * as utils from './utils/utils'; jest.setTimeout(90 * 1000);