Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA][TS migration] Migrate workflow_tests, adjust utils migration #38363

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/types/modules/act.d.ts
Original file line number Diff line number Diff line change
@@ -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<ActStepIdentifier, 'name' | 'id' | 'run' | 'mockWith'>;
}
Comment on lines +3 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the steps are passing additional data and since StepIdentifier is defined under the hood as

export declare type StepIdentifier = StepIdentifierUsingName | StepIdentifierUsingId | StepIdentifierUsingUses | StepIdentifierUsingRun | StepIdentifierUsingIndex | StepIdentifierUsingBefore | StepIdentifierUsingAfter;

those steps had more restrictive subtypes of StepIdentifier assigned to them, so to avoid changing the content I made the type a tiny bit more general on the module level

Original file line number Diff line number Diff line change
@@ -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),
{
Expand All @@ -16,15 +17,15 @@ 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();
});

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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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'});
Expand Down
27 changes: 14 additions & 13 deletions workflow_tests/deploy.test.js → workflow_tests/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -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),
{
Expand All @@ -16,15 +17,15 @@ 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();
});

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,
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
{
Expand All @@ -23,15 +24,15 @@ 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();
});

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,
Expand All @@ -57,14 +58,15 @@ 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',
},
};
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 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, {}, {});
Expand All @@ -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, {}, {});
Expand Down Expand Up @@ -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, {}, {});
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {MockJob} 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),
{
Expand All @@ -16,15 +17,15 @@ 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();
});

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,
Expand All @@ -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(
Expand All @@ -71,7 +72,7 @@ describe('test workflow finishReleaseCycle', () => {
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs = {
const testMockJobs: Record<string, MockJob> = {
createNewPatchVersion: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const testMockJobs: Record<string, MockJob> = {
const testMockJobs: MockJobs = {

steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading
Loading