diff --git a/.github/workflows/authorChecklist.yml b/.github/workflows/authorChecklist.yml index 907b1e7be6ca..2bc94cffefd8 100644 --- a/.github/workflows/authorChecklist.yml +++ b/.github/workflows/authorChecklist.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: authorChecklist.js + - name: authorChecklist.ts uses: ./.github/actions/javascript/authorChecklist with: GITHUB_TOKEN: ${{ github.token }} diff --git a/workflow_tests/assertions/authorChecklistAssertions.js b/workflow_tests/assertions/authorChecklistAssertions.js deleted file mode 100644 index 256a3534951b..000000000000 --- a/workflow_tests/assertions/authorChecklistAssertions.js +++ /dev/null @@ -1,20 +0,0 @@ -const utils = require('../utils/utils'); - -const assertChecklistJobExecuted = (workflowResult, didExecute = true) => { - const steps = [ - utils.createStepAssertion('Checkout', true, null, 'CHECKLIST', 'Checkout'), - utils.createStepAssertion('authorChecklist.js', true, null, 'CHECKLIST', 'Running authorChecklist.js', [{key: 'GITHUB_TOKEN', value: '***'}], []), - ]; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -}; - -module.exports = { - assertChecklistJobExecuted, -}; diff --git a/workflow_tests/assertions/authorChecklistAssertions.ts b/workflow_tests/assertions/authorChecklistAssertions.ts new file mode 100644 index 000000000000..997eac2d3ea9 --- /dev/null +++ b/workflow_tests/assertions/authorChecklistAssertions.ts @@ -0,0 +1,19 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertChecklistJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [ + createStepAssertion('Checkout', true, null, 'CHECKLIST', 'Checkout'), + createStepAssertion('authorChecklist.ts', true, null, 'CHECKLIST', 'Running authorChecklist.ts', [{key: 'GITHUB_TOKEN', value: '***'}], []), + ] as const; + + steps.forEach((expectedStep) => { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + }); +} + +export default {assertChecklistJobExecuted}; diff --git a/workflow_tests/assertions/cherryPickAssertions.js b/workflow_tests/assertions/cherryPickAssertions.ts similarity index 58% rename from workflow_tests/assertions/cherryPickAssertions.js rename to workflow_tests/assertions/cherryPickAssertions.ts index 1fe1194cf7b6..8cf5dbd56d54 100644 --- a/workflow_tests/assertions/cherryPickAssertions.js +++ b/workflow_tests/assertions/cherryPickAssertions.ts @@ -1,7 +1,8 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Check if user is deployer', true, null, 'VALIDATEACTOR', 'Checking if user is a deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])]; +function assertValidateActorJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Check if user is deployer', true, null, 'VALIDATEACTOR', 'Checking if user is a deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -10,10 +11,10 @@ const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Create new version', true, null, 'CREATENEWVERSION', 'Creating new version', [], [])]; +function assertCreateNewVersionJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Create new version', true, null, 'CREATENEWVERSION', 'Creating new version', [], [])] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -22,11 +23,11 @@ const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) => expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pullRequestNumber = '1234', didExecute = true, hasConflicts = false, isSuccessful = true) => { +function assertCherryPickJobExecuted(workflowResult: Step[], user = 'Dummy Author', pullRequestNumber = '1234', didExecute = true, hasConflicts = false, isSuccessful = true) { const steps = [ - utils.createStepAssertion( + createStepAssertion( 'Checkout staging branch', true, null, @@ -38,11 +39,11 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull ], [], ), - utils.createStepAssertion('Set up git for OSBotify', true, null, 'CHERRYPICK', 'Setting up git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), - utils.createStepAssertion('Get previous app version', true, null, 'CHERRYPICK', 'Get previous app version', [{key: 'SEMVER_LEVEL', value: 'PATCH'}]), - utils.createStepAssertion('Fetch history of relevant refs', true, null, 'CHERRYPICK', 'Fetch history of relevant refs'), - utils.createStepAssertion('Get version bump commit', true, null, 'CHERRYPICK', 'Get version bump commit', [], []), - utils.createStepAssertion( + createStepAssertion('Set up git for OSBotify', true, null, 'CHERRYPICK', 'Setting up git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), + createStepAssertion('Get previous app version', true, null, 'CHERRYPICK', 'Get previous app version', [{key: 'SEMVER_LEVEL', value: 'PATCH'}]), + createStepAssertion('Fetch history of relevant refs', true, null, 'CHERRYPICK', 'Fetch history of relevant refs'), + createStepAssertion('Get version bump commit', true, null, 'CHERRYPICK', 'Get version bump commit', [], []), + createStepAssertion( 'Get merge commit for pull request to CP', true, null, @@ -55,10 +56,10 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull ], [], ), - utils.createStepAssertion('Cherry-pick the version-bump to staging', true, null, 'CHERRYPICK', 'Cherry-picking the version-bump to staging', [], []), - utils.createStepAssertion('Cherry-pick the merge commit of target PR', true, null, 'CHERRYPICK', 'Cherry-picking the merge commit of target PR', [], []), - utils.createStepAssertion('Push changes', true, null, 'CHERRYPICK', 'Pushing changes', [], []), - ]; + createStepAssertion('Cherry-pick the version-bump to staging', true, null, 'CHERRYPICK', 'Cherry-picking the version-bump to staging', [], []), + createStepAssertion('Cherry-pick the merge commit of target PR', true, null, 'CHERRYPICK', 'Cherry-picking the merge commit of target PR', [], []), + createStepAssertion('Push changes', true, null, 'CHERRYPICK', 'Pushing changes', [], []), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -69,7 +70,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull }); const conflictSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Create Pull Request to manually finish CP', true, null, @@ -78,7 +79,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull [], [{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}], ), - ]; + ] as const; conflictSteps.forEach((step) => { if (didExecute && hasConflicts) { @@ -89,7 +90,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull }); const failedSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Announces a CP failure in the #announce Slack room', true, null, @@ -101,7 +102,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull {key: 'SLACK_WEBHOOK_URL', value: '***'}, ], ), - ]; + ] as const; failedSteps.forEach((step) => { if (didExecute && !isSuccessful) { @@ -110,10 +111,6 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull expect(workflowResult).not.toEqual(expect.arrayContaining([step])); } }); -}; +} -module.exports = { - assertValidateActorJobExecuted, - assertCreateNewVersionJobExecuted, - assertCherryPickJobExecuted, -}; +export default {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted, assertCherryPickJobExecuted}; diff --git a/workflow_tests/assertions/claAssertions.js b/workflow_tests/assertions/claAssertions.ts similarity index 82% rename from workflow_tests/assertions/claAssertions.js rename to workflow_tests/assertions/claAssertions.ts index b85eb263d838..401e094923dc 100644 --- a/workflow_tests/assertions/claAssertions.js +++ b/workflow_tests/assertions/claAssertions.ts @@ -1,8 +1,9 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository = '', didExecute = true, runAssistant = true) => { +function assertCLAJobExecuted(workflowResult: Step[], commentBody = '', githubRepository = '', didExecute = true, runAssistant = true) { const steps = [ - utils.createStepAssertion( + createStepAssertion( 'CLA comment check', true, null, @@ -14,7 +15,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository ], [], ), - utils.createStepAssertion( + createStepAssertion( 'CLA comment re-check', true, null, @@ -26,7 +27,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository ], [], ), - ]; + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -37,7 +38,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository }); const assistantSteps = [ - utils.createStepAssertion( + createStepAssertion( 'CLA Assistant', true, null, @@ -57,7 +58,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository {key: 'PERSONAL_ACCESS_TOKEN', value: '***'}, ], ), - ]; + ] as const; assistantSteps.forEach((step) => { if (didExecute && runAssistant) { @@ -66,8 +67,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository expect(workflowResult).not.toEqual(expect.arrayContaining([step])); } }); -}; +} -module.exports = { - assertCLAJobExecuted, -}; +// eslint-disable-next-line import/prefer-default-export +export {assertCLAJobExecuted}; diff --git a/workflow_tests/assertions/createNewVersionAssertions.js b/workflow_tests/assertions/createNewVersionAssertions.ts similarity index 51% rename from workflow_tests/assertions/createNewVersionAssertions.js rename to workflow_tests/assertions/createNewVersionAssertions.ts index e4526ae59be2..814fe33d2842 100644 --- a/workflow_tests/assertions/createNewVersionAssertions.js +++ b/workflow_tests/assertions/createNewVersionAssertions.ts @@ -1,7 +1,8 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Get user permissions', true, null, 'VALIDATEACTOR', 'Get user permissions', [], [{key: 'GITHUB_TOKEN', value: '***'}])]; +function assertValidateActorJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Get user permissions', true, null, 'VALIDATEACTOR', 'Get user permissions', [], [{key: 'GITHUB_TOKEN', value: '***'}])] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -10,11 +11,12 @@ const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD', didExecute = true, isSuccessful = true) => { +} + +function assertCreateNewVersionJobExecuted(workflowResult: Step[], semverLevel = 'BUILD', didExecute = true, isSuccessful = true) { const steps = [ - utils.createStepAssertion('Run turnstyle', true, null, 'CREATENEWVERSION', 'Run turnstyle', [{key: 'poll-interval-seconds', value: '10'}], [{key: 'GITHUB_TOKEN', value: '***'}]), - utils.createStepAssertion( + createStepAssertion('Run turnstyle', true, null, 'CREATENEWVERSION', 'Run turnstyle', [{key: 'poll-interval-seconds', value: '10'}], [{key: 'GITHUB_TOKEN', value: '***'}]), + createStepAssertion( 'Check out', true, null, @@ -26,8 +28,8 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD' ], [], ), - utils.createStepAssertion('Setup git for OSBotify', true, null, 'CREATENEWVERSION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), - utils.createStepAssertion( + createStepAssertion('Setup git for OSBotify', true, null, 'CREATENEWVERSION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), + createStepAssertion( 'Generate version', true, null, @@ -39,9 +41,9 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD' ], [], ), - utils.createStepAssertion('Commit new version', true, null, 'CREATENEWVERSION', 'Commit new version', [], []), - utils.createStepAssertion('Update main branch', true, null, 'CREATENEWVERSION', 'Update main branch', [], []), - ]; + createStepAssertion('Commit new version', true, null, 'CREATENEWVERSION', 'Commit new version', [], []), + createStepAssertion('Update main branch', true, null, 'CREATENEWVERSION', 'Update main branch', [], []), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -54,8 +56,8 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD' }); const failedSteps = [ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'CREATENEWVERSION', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Announce failed workflow in Slack', true, null, 'CREATENEWVERSION', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; failedSteps.forEach((step) => { if (didExecute && !isSuccessful) { @@ -64,9 +66,6 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD' expect(workflowResult).not.toEqual(expect.arrayContaining([step])); } }); -}; +} -module.exports = { - assertValidateActorJobExecuted, - assertCreateNewVersionJobExecuted, -}; +export {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted}; diff --git a/workflow_tests/assertions/deployAssertions.js b/workflow_tests/assertions/deployAssertions.ts similarity index 53% rename from workflow_tests/assertions/deployAssertions.js rename to workflow_tests/assertions/deployAssertions.ts index ce0907e84be8..0338d777c61b 100644 --- a/workflow_tests/assertions/deployAssertions.js +++ b/workflow_tests/assertions/deployAssertions.ts @@ -1,19 +1,20 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => { +function assertDeployStagingJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Checkout staging branch', true, null, 'DEPLOY_STAGING', 'Checking out staging branch', [ + createStepAssertion('Checkout staging branch', true, null, 'DEPLOY_STAGING', 'Checking out staging branch', [ {key: 'ref', value: 'staging'}, {key: 'token', value: '***'}, ]), - utils.createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_STAGING', 'Setting up git for OSBotify', [ + createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_STAGING', 'Setting up git for OSBotify', [ {key: 'GPG_PASSPHRASE', value: '***'}, {key: 'OS_BOTIFY_APP_ID', value: '***'}, {key: 'OS_BOTIFY_PRIVATE_KEY', value: '***'}, ]), - utils.createStepAssertion('Tag version', true, null, 'DEPLOY_STAGING', 'Tagging new version'), - utils.createStepAssertion('🚀 Push tags to trigger staging deploy 🚀', true, null, 'DEPLOY_STAGING', 'Pushing tag to trigger staging deploy'), - ]; + createStepAssertion('Tag version', true, null, 'DEPLOY_STAGING', 'Tagging new version'), + createStepAssertion('🚀 Push tags to trigger staging deploy 🚀', true, null, 'DEPLOY_STAGING', 'Pushing tag to trigger staging deploy'), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -22,27 +23,27 @@ const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) => { +function assertDeployProductionJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'DEPLOY_PRODUCTION', 'Checking out', [ + createStepAssertion('Checkout', true, null, 'DEPLOY_PRODUCTION', 'Checking out', [ {key: 'ref', value: 'production'}, {key: 'token', value: '***'}, ]), - utils.createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_PRODUCTION', 'Setting up git for OSBotify', [ + createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_PRODUCTION', 'Setting up git for OSBotify', [ {key: 'GPG_PASSPHRASE', value: '***'}, {key: 'OS_BOTIFY_APP_ID', value: '***'}, {key: 'OS_BOTIFY_PRIVATE_KEY', value: '***'}, ]), - utils.createStepAssertion('Get current app version', true, null, 'DEPLOY_PRODUCTION', 'Getting current app version'), - utils.createStepAssertion('Get Release Pull Request List', true, null, 'DEPLOY_PRODUCTION', 'Getting release PR list', [ + createStepAssertion('Get current app version', true, null, 'DEPLOY_PRODUCTION', 'Getting current app version'), + createStepAssertion('Get Release Pull Request List', true, null, 'DEPLOY_PRODUCTION', 'Getting release PR list', [ {key: 'TAG', value: '1.2.3'}, {key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}, {key: 'IS_PRODUCTION_DEPLOY', value: 'true'}, ]), - utils.createStepAssertion('Generate Release Body', true, null, 'DEPLOY_PRODUCTION', 'Generating release body', [{key: 'PR_LIST', value: '[1.2.1, 1.2.2]'}]), - utils.createStepAssertion( + createStepAssertion('Generate Release Body', true, null, 'DEPLOY_PRODUCTION', 'Generating release body', [{key: 'PR_LIST', value: '[1.2.1, 1.2.2]'}]), + createStepAssertion( '🚀 Create release to trigger production deploy 🚀', true, null, @@ -54,7 +55,7 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) => ], [{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}], ), - ]; + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -63,9 +64,6 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) => expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -module.exports = { - assertDeployStagingJobExecuted, - assertDeployProductionJobExecuted, -}; +export {assertDeployStagingJobExecuted, assertDeployProductionJobExecuted}; diff --git a/workflow_tests/assertions/deployBlockerAssertions.js b/workflow_tests/assertions/deployBlockerAssertions.ts similarity index 68% rename from workflow_tests/assertions/deployBlockerAssertions.js rename to workflow_tests/assertions/deployBlockerAssertions.ts index 78a3fea116b4..bd517658e8c0 100644 --- a/workflow_tests/assertions/deployBlockerAssertions.js +++ b/workflow_tests/assertions/deployBlockerAssertions.ts @@ -1,7 +1,8 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertUpdateChecklistJobExecuted = (workflowResult, didExecute = true, isSuccessful = true) => { - const steps = [utils.createStepAssertion('updateChecklist', true, null, 'UPDATECHECKLIST', 'Run updateChecklist')]; +function assertUpdateChecklistJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { + const steps = [createStepAssertion('updateChecklist', true, null, 'UPDATECHECKLIST', 'Run updateChecklist')] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -12,12 +13,12 @@ const assertUpdateChecklistJobExecuted = (workflowResult, didExecute = true, isS expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuccessful = true, failsAt = -1) => { +function assertDeployBlockerJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true, failsAt = -1) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'DEPLOYBLOCKER', 'Checkout'), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'DEPLOYBLOCKER', 'Checkout'), + createStepAssertion( 'Give the issue/PR the Hourly, Engineering labels', true, null, @@ -26,8 +27,8 @@ const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuc [], [{key: 'GITHUB_TOKEN', value: '***'}], ), - utils.createStepAssertion('Comment on deploy blocker', true, null, 'DEPLOYBLOCKER', 'Comment on deploy blocker', [], [{key: 'GITHUB_TOKEN', value: '***'}]), - ]; + createStepAssertion('Comment on deploy blocker', true, null, 'DEPLOYBLOCKER', 'Comment on deploy blocker', [], [{key: 'GITHUB_TOKEN', value: '***'}]), + ] as const; steps.forEach((expectedStep, i) => { if (didExecute) { @@ -45,7 +46,7 @@ const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuc }); const successSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Post the issue in the #expensify-open-source slack room', true, null, @@ -57,7 +58,7 @@ const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuc {key: 'SLACK_WEBHOOK_URL', value: '***'}, ], ), - ]; + ] as const; successSteps.forEach((step) => { if (didExecute && isSuccessful) { @@ -68,8 +69,8 @@ const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuc }); const failedSteps = [ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'DEPLOYBLOCKER', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Announce failed workflow in Slack', true, null, 'DEPLOYBLOCKER', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; failedSteps.forEach((step) => { if (didExecute && !isSuccessful) { @@ -78,9 +79,6 @@ const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuc expect(workflowResult).not.toEqual(expect.arrayContaining([step])); } }); -}; +} -module.exports = { - assertUpdateChecklistJobExecuted, - assertDeployBlockerJobExecuted, -}; +export {assertUpdateChecklistJobExecuted, assertDeployBlockerJobExecuted}; diff --git a/workflow_tests/assertions/failureNotifierAssertions.js b/workflow_tests/assertions/failureNotifierAssertions.js deleted file mode 100644 index 2491c4fa8469..000000000000 --- a/workflow_tests/assertions/failureNotifierAssertions.js +++ /dev/null @@ -1,20 +0,0 @@ -const utils = require('../utils/utils'); - -const assertNotifyFailureJobExecuted = (workflowResult, didExecute = true) => { - const steps = [ - utils.createStepAssertion('Fetch Workflow Run Jobs', true, null, 'NOTIFYFAILURE', 'Fetch Workflow Run Jobs', [], []), - utils.createStepAssertion('Process Each Failed Job', true, null, 'NOTIFYFAILURE', 'Process Each Failed Job', [], []), - ]; - - for (const expectedStep of steps) { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - } -}; - -module.exports = { - assertNotifyFailureJobExecuted, -}; diff --git a/workflow_tests/assertions/failureNotifierAssertions.ts b/workflow_tests/assertions/failureNotifierAssertions.ts new file mode 100644 index 000000000000..37be4e872d32 --- /dev/null +++ b/workflow_tests/assertions/failureNotifierAssertions.ts @@ -0,0 +1,19 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertNotifyFailureJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [ + createStepAssertion('Fetch Workflow Run Jobs', true, null, 'NOTIFYFAILURE', 'Fetch Workflow Run Jobs', [], []), + createStepAssertion('Process Each Failed Job', true, null, 'NOTIFYFAILURE', 'Process Each Failed Job', [], []), + ] as const; + + for (const expectedStep of steps) { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +} + +export default {assertNotifyFailureJobExecuted}; diff --git a/workflow_tests/assertions/finishReleaseCycleAssertions.js b/workflow_tests/assertions/finishReleaseCycleAssertions.ts similarity index 65% rename from workflow_tests/assertions/finishReleaseCycleAssertions.js rename to workflow_tests/assertions/finishReleaseCycleAssertions.ts index 16db65b4afe7..e36ce9a6b84d 100644 --- a/workflow_tests/assertions/finishReleaseCycleAssertions.js +++ b/workflow_tests/assertions/finishReleaseCycleAssertions.ts @@ -1,21 +1,23 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute = true, isTeamMember = true, hasBlockers = false, isSuccessful = true) => { +function assertValidateJobExecuted(workflowResult: Step[], issueNumber = '', didExecute = true, isTeamMember = true, hasBlockers = false, isSuccessful = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'VALIDATE', 'Checkout', [ + createStepAssertion('Checkout', true, null, 'VALIDATE', 'Checkout', [ {key: 'ref', value: 'main'}, {key: 'token', value: '***'}, ]), - utils.createStepAssertion('Setup git for OSBotify', true, null, 'VALIDATE', 'Setup git for OSBotify', [ + createStepAssertion('Setup git for OSBotify', true, null, 'VALIDATE', 'Setup git for OSBotify', [ {key: 'GPG_PASSPHRASE', value: '***'}, {key: 'OS_BOTIFY_APP_ID', value: '***'}, {key: 'OS_BOTIFY_PRIVATE_KEY', value: '***'}, ]), - utils.createStepAssertion('Validate actor is deployer', true, null, 'VALIDATE', 'Validating if actor is deployer', [], [{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}]), + createStepAssertion('Validate actor is deployer', true, null, 'VALIDATE', 'Validating if actor is deployer', [], [{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}]), ]; + if (isTeamMember) { steps.push( - utils.createStepAssertion( + createStepAssertion( 'Check for any deploy blockers', true, null, @@ -40,7 +42,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute // eslint-disable-next-line rulesdir/no-negated-variables const notTeamMemberSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Reopen and comment on issue (not a team member)', true, null, @@ -53,7 +55,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute ], [], ), - ]; + ] as const; notTeamMemberSteps.forEach((expectedStep) => { if (didExecute && !isTeamMember) { @@ -64,7 +66,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute }); const blockerSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Reopen and comment on issue (has blockers)', true, null, @@ -76,7 +78,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute ], [], ), - ]; + ] as const; blockerSteps.forEach((expectedStep) => { if (didExecute && hasBlockers) { @@ -87,8 +89,8 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute }); const failedSteps = [ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'VALIDATE', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Announce failed workflow in Slack', true, null, 'VALIDATE', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; failedSteps.forEach((expectedStep) => { if (didExecute && !isSuccessful) { @@ -97,11 +99,11 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertUpdateProductionJobExecuted = (workflowResult, didExecute = true, isSuccessful = true) => { +function assertUpdateProductionJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { const steps = [ - utils.createStepAssertion( + createStepAssertion( 'Checkout', true, null, @@ -113,9 +115,9 @@ const assertUpdateProductionJobExecuted = (workflowResult, didExecute = true, is ], [], ), - utils.createStepAssertion('Setup git for OSBotify', true, null, 'UPDATEPRODUCTION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), - utils.createStepAssertion('Update production branch', true, null, 'UPDATEPRODUCTION', 'Updating production branch', [], []), - ]; + createStepAssertion('Setup git for OSBotify', true, null, 'UPDATEPRODUCTION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), + createStepAssertion('Update production branch', true, null, 'UPDATEPRODUCTION', 'Updating production branch', [], []), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -126,8 +128,8 @@ const assertUpdateProductionJobExecuted = (workflowResult, didExecute = true, is }); const failedSteps = [ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'UPDATEPRODUCTION', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Announce failed workflow in Slack', true, null, 'UPDATEPRODUCTION', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; failedSteps.forEach((expectedStep) => { if (didExecute && !isSuccessful) { @@ -136,10 +138,10 @@ const assertUpdateProductionJobExecuted = (workflowResult, didExecute = true, is expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertCreateNewPatchVersionJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Create new version', true, null, 'CREATENEWPATCHVERSION', 'Creating new version', [{key: 'SEMVER_LEVEL', value: 'PATCH'}], [])]; +function assertCreateNewPatchVersionJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Create new version', true, null, 'CREATENEWPATCHVERSION', 'Creating new version', [{key: 'SEMVER_LEVEL', value: 'PATCH'}], [])] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -148,11 +150,11 @@ const assertCreateNewPatchVersionJobExecuted = (workflowResult, didExecute = tru expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true, isSuccessful = true) => { +function assertUpdateStagingJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { const steps = [ - utils.createStepAssertion( + createStepAssertion( 'Checkout', true, null, @@ -164,9 +166,9 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true, isSuc ], [], ), - utils.createStepAssertion('Setup git for OSBotify', true, null, 'UPDATESTAGING', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), - utils.createStepAssertion('Update staging branch to trigger staging deploy', true, null, 'UPDATESTAGING', 'Updating staging branch', [], []), - ]; + createStepAssertion('Setup git for OSBotify', true, null, 'UPDATESTAGING', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), + createStepAssertion('Update staging branch to trigger staging deploy', true, null, 'UPDATESTAGING', 'Updating staging branch', [], []), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -177,8 +179,8 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true, isSuc }); const failedSteps = [ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'UPDATESTAGING', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Announce failed workflow in Slack', true, null, 'UPDATESTAGING', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; failedSteps.forEach((expectedStep) => { if (didExecute && !isSuccessful) { @@ -187,11 +189,6 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true, isSuc expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; - -module.exports = { - assertValidateJobExecuted, - assertUpdateProductionJobExecuted, - assertCreateNewPatchVersionJobExecuted, - assertUpdateStagingJobExecuted, -}; +} + +export {assertValidateJobExecuted, assertUpdateProductionJobExecuted, assertCreateNewPatchVersionJobExecuted, assertUpdateStagingJobExecuted}; diff --git a/workflow_tests/assertions/lintAssertions.js b/workflow_tests/assertions/lintAssertions.js deleted file mode 100644 index 1253bae2e258..000000000000 --- a/workflow_tests/assertions/lintAssertions.js +++ /dev/null @@ -1,23 +0,0 @@ -const utils = require('../utils/utils'); - -const assertLintJobExecuted = (workflowResult, didExecute = true) => { - const steps = [ - utils.createStepAssertion('Checkout', true, null, 'LINT', 'Checkout', [], []), - utils.createStepAssertion('Setup Node', true, null, 'LINT', 'Setup Node', [], []), - utils.createStepAssertion('Lint JavaScript and Typescript with ESLint', true, null, 'LINT', 'Lint JavaScript with ESLint', [], [{key: 'CI', value: 'true'}]), - utils.createStepAssertion("Verify there's no Prettier diff", true, null, 'LINT', 'Verify theres no Prettier diff', [], []), - utils.createStepAssertion('Run unused style searcher', true, null, 'LINT', 'Run unused style searcher', [], []), - ]; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -}; - -module.exports = { - assertLintJobExecuted, -}; diff --git a/workflow_tests/assertions/lintAssertions.ts b/workflow_tests/assertions/lintAssertions.ts new file mode 100644 index 000000000000..97804267a798 --- /dev/null +++ b/workflow_tests/assertions/lintAssertions.ts @@ -0,0 +1,23 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertLintJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [ + createStepAssertion('Checkout', true, null, 'LINT', 'Checkout', [], []), + createStepAssertion('Setup Node', true, null, 'LINT', 'Setup Node', [], []), + createStepAssertion('Lint JavaScript and Typescript with ESLint', true, null, 'LINT', 'Lint JavaScript with ESLint', [], [{key: 'CI', value: 'true'}]), + createStepAssertion("Verify there's no Prettier diff", true, null, 'LINT', 'Verify theres no Prettier diff', [], []), + createStepAssertion('Run unused style searcher', true, null, 'LINT', 'Run unused style searcher', [], []), + ] as const; + + steps.forEach((expectedStep) => { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + }); +} + +// eslint-disable-next-line import/prefer-default-export +export {assertLintJobExecuted}; diff --git a/workflow_tests/assertions/lockDeploysAssertions.js b/workflow_tests/assertions/lockDeploysAssertions.ts similarity index 54% rename from workflow_tests/assertions/lockDeploysAssertions.js rename to workflow_tests/assertions/lockDeploysAssertions.ts index 874076dc3a28..278d413fb972 100644 --- a/workflow_tests/assertions/lockDeploysAssertions.js +++ b/workflow_tests/assertions/lockDeploysAssertions.ts @@ -1,8 +1,9 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertlockStagingDeploysJobExecuted = (workflowResult, didExecute = true, isSuccessful = true) => { +function assertlockStagingDeploysJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { const steps = [ - utils.createStepAssertion( + createStepAssertion( 'Checkout', true, null, @@ -14,8 +15,8 @@ const assertlockStagingDeploysJobExecuted = (workflowResult, didExecute = true, ], [], ), - utils.createStepAssertion('Wait for staging deploys to finish', true, null, 'LOCKSTAGINGDEPLOYS', 'Waiting for staging deploys to finish', [{key: 'GITHUB_TOKEN', value: '***'}], []), - utils.createStepAssertion( + createStepAssertion('Wait for staging deploys to finish', true, null, 'LOCKSTAGINGDEPLOYS', 'Waiting for staging deploys to finish', [{key: 'GITHUB_TOKEN', value: '***'}], []), + createStepAssertion( 'Comment in StagingDeployCash to give Applause the 🟢 to begin QA', true, null, @@ -24,7 +25,7 @@ const assertlockStagingDeploysJobExecuted = (workflowResult, didExecute = true, [], [{key: 'GITHUB_TOKEN', value: '***'}], ), - ]; + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -35,8 +36,8 @@ const assertlockStagingDeploysJobExecuted = (workflowResult, didExecute = true, }); const failProdSteps = [ - utils.createStepAssertion('Announce failed workflow', true, null, 'LOCKSTAGINGDEPLOYS', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Announce failed workflow', true, null, 'LOCKSTAGINGDEPLOYS', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; failProdSteps.forEach((expectedStep) => { if (didExecute && !isSuccessful) { @@ -45,11 +46,11 @@ const assertlockStagingDeploysJobExecuted = (workflowResult, didExecute = true, expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertlockStagingDeploysJobFailedAfterFirstStep = (workflowResult) => { +function assertlockStagingDeploysJobFailedAfterFirstStep(workflowResult: Step[]) { const steps = [ - utils.createStepAssertion( + createStepAssertion( 'Checkout', true, null, @@ -61,24 +62,13 @@ const assertlockStagingDeploysJobFailedAfterFirstStep = (workflowResult) => { ], [], ), - utils.createStepAssertion( - 'Wait for staging deploys to finish', - false, - null, - 'LOCKSTAGINGDEPLOYS', - 'Waiting for staging deploys to finish', - [{key: 'GITHUB_TOKEN', value: '***'}], - [], - ), - utils.createStepAssertion('Announce failed workflow', true, null, 'LOCKSTAGINGDEPLOYS', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ]; + createStepAssertion('Wait for staging deploys to finish', false, null, 'LOCKSTAGINGDEPLOYS', 'Waiting for staging deploys to finish', [{key: 'GITHUB_TOKEN', value: '***'}], []), + createStepAssertion('Announce failed workflow', true, null, 'LOCKSTAGINGDEPLOYS', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), + ] as const; steps.forEach((expectedStep) => { expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); }); -}; +} -module.exports = { - assertlockStagingDeploysJobExecuted, - assertlockStagingDeploysJobFailedAfterFirstStep, -}; +export {assertlockStagingDeploysJobExecuted, assertlockStagingDeploysJobFailedAfterFirstStep}; diff --git a/workflow_tests/assertions/platformDeployAssertions.js b/workflow_tests/assertions/platformDeployAssertions.ts similarity index 53% rename from workflow_tests/assertions/platformDeployAssertions.js rename to workflow_tests/assertions/platformDeployAssertions.ts index a4c597621577..b164cd269b4c 100644 --- a/workflow_tests/assertions/platformDeployAssertions.js +++ b/workflow_tests/assertions/platformDeployAssertions.ts @@ -1,7 +1,8 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertVerifyActorJobExecuted = (workflowResult, username, didExecute = true) => { - const steps = [utils.createStepAssertion('Check if user is deployer', true, null, 'VALIDATE_ACTOR', 'Checking if the user is a deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])]; +function assertVerifyActorJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Check if user is deployer', true, null, 'VALIDATE_ACTOR', 'Checking if the user is a deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -10,10 +11,10 @@ const assertVerifyActorJobExecuted = (workflowResult, username, didExecute = tru expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertDeployChecklistJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('deployChecklist', true, null, 'DEPLOY_CHECKLIST', 'Run deployChecklist')]; +function assertDeployChecklistJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('deployChecklist', true, null, 'DEPLOY_CHECKLIST', 'Run deployChecklist')] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -22,14 +23,14 @@ const assertDeployChecklistJobExecuted = (workflowResult, didExecute = true) => expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProduction = true, isSuccessful = true) => { +function assertAndroidJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true, isSuccessful = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'ANDROID', 'Checking out'), - utils.createStepAssertion('Configure MapBox SDK', true, null, 'ANDROID', 'Configure MapBox SDK'), - utils.createStepAssertion('Setup Node', true, null, 'ANDROID', 'Setting up Node'), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'ANDROID', 'Checking out'), + createStepAssertion('Configure MapBox SDK', true, null, 'ANDROID', 'Configure MapBox SDK'), + createStepAssertion('Setup Node', true, null, 'ANDROID', 'Setting up Node'), + createStepAssertion( 'Setup Java', true, null, @@ -41,39 +42,38 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio ], [], ), - utils.createStepAssertion('Setup Ruby', true, null, 'ANDROID', 'Setting up Ruby', [ + createStepAssertion('Setup Ruby', true, null, 'ANDROID', 'Setting up Ruby', [ {key: 'ruby-version', value: '2.7'}, {key: 'bundler-cache', value: 'true'}, ]), - utils.createStepAssertion('Decrypt keystore', true, null, 'ANDROID', 'Decrypting keystore', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Decrypt json key', true, null, 'ANDROID', 'Decrypting JSON key', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Set version in ENV', true, null, 'ANDROID', 'Setting version in ENV'), + createStepAssertion('Decrypt keystore', true, null, 'ANDROID', 'Decrypting keystore', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Decrypt json key', true, null, 'ANDROID', 'Decrypting JSON key', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Set version in ENV', true, null, 'ANDROID', 'Setting version in ENV'), ]; + if (!isProduction) { steps.push( - utils.createStepAssertion('Run Fastlane beta', true, null, 'ANDROID', 'Running Fastlane beta', null, [ + createStepAssertion('Run Fastlane beta', true, null, 'ANDROID', 'Running Fastlane beta', null, [ {key: 'MYAPP_UPLOAD_STORE_PASSWORD', value: '***'}, {key: 'MYAPP_UPLOAD_KEY_PASSWORD', value: '***'}, ]), ); } else { - steps.push(utils.createStepAssertion('Run Fastlane production', true, null, 'ANDROID', 'Running Fastlane production', null, [{key: 'VERSION', value: '1.2.3'}])); + steps.push(createStepAssertion('Run Fastlane production', true, null, 'ANDROID', 'Running Fastlane production', null, [{key: 'VERSION', value: '1.2.3'}])); } steps.push( - utils.createStepAssertion('Archive Android sourcemaps', true, null, 'ANDROID', 'Archiving Android sourcemaps', [ + createStepAssertion('Archive Android sourcemaps', true, null, 'ANDROID', 'Archiving Android sourcemaps', [ {key: 'name', value: 'android-sourcemap'}, {key: 'path', value: 'android/app/build/generated/sourcemaps/react/release/*.map'}, ]), ); if (!isProduction) { steps.push( - utils.createStepAssertion('Upload Android version to GitHub artifacts', true, null, 'ANDROID', 'Upload Android version to GitHub artifacts', [ + createStepAssertion('Upload Android version to GitHub artifacts', true, null, 'ANDROID', 'Upload Android version to GitHub artifacts', [ {key: 'name', value: 'app-production-release.aab'}, {key: 'path', value: 'android/app/build/outputs/bundle/productionRelease/app-production-release.aab'}, ]), - utils.createStepAssertion('Upload Android version to Browser Stack', true, null, 'ANDROID', 'Uploading Android version to Browser Stack', null, [ - {key: 'BROWSERSTACK', value: '***'}, - ]), + createStepAssertion('Upload Android version to Browser Stack', true, null, 'ANDROID', 'Uploading Android version to Browser Stack', null, [{key: 'BROWSERSTACK', value: '***'}]), ); } @@ -86,7 +86,7 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio }); const failProdSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Warn deployers if Android production deploy failed', true, null, @@ -98,7 +98,7 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio {key: 'SLACK_WEBHOOK_URL', value: '***'}, ], ), - ]; + ] as const; failProdSteps.forEach((expectedStep) => { if (didExecute && isProduction && !isSuccessful) { @@ -107,19 +107,18 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertDesktopJobExecuted = (workflowResult, didExecute = true, isProduction = true) => { +function assertDesktopJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'DESKTOP', 'Checking out'), - utils.createStepAssertion('Setup Node', true, null, 'DESKTOP', 'Setting up Node'), - utils.createStepAssertion('Decrypt Developer ID Certificate', true, null, 'DESKTOP', 'Decrypting developer id certificate', null, [ - {key: 'DEVELOPER_ID_SECRET_PASSPHRASE', value: '***'}, - ]), + createStepAssertion('Checkout', true, null, 'DESKTOP', 'Checking out'), + createStepAssertion('Setup Node', true, null, 'DESKTOP', 'Setting up Node'), + createStepAssertion('Decrypt Developer ID Certificate', true, null, 'DESKTOP', 'Decrypting developer id certificate', null, [{key: 'DEVELOPER_ID_SECRET_PASSPHRASE', value: '***'}]), ]; + if (isProduction) { steps.push( - utils.createStepAssertion('Build production desktop app', true, null, 'DESKTOP', 'Building production desktop app', null, [ + createStepAssertion('Build production desktop app', true, null, 'DESKTOP', 'Building production desktop app', null, [ {key: 'CSC_LINK', value: '***'}, {key: 'CSC_KEY_PASSWORD', value: '***'}, {key: 'APPLE_ID', value: '***'}, @@ -130,7 +129,7 @@ const assertDesktopJobExecuted = (workflowResult, didExecute = true, isProductio ); } else { steps.push( - utils.createStepAssertion('Build staging desktop app', true, null, 'DESKTOP', 'Building staging desktop app', null, [ + createStepAssertion('Build staging desktop app', true, null, 'DESKTOP', 'Building staging desktop app', null, [ {key: 'CSC_LINK', value: '***'}, {key: 'CSC_KEY_PASSWORD', value: '***'}, {key: 'APPLE_ID', value: '***'}, @@ -148,36 +147,37 @@ const assertDesktopJobExecuted = (workflowResult, didExecute = true, isProductio expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction = true, isSuccessful = true) => { +function assertIOSJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true, isSuccessful = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'IOS', 'Checking out'), - utils.createStepAssertion('Configure MapBox SDK', true, null, 'IOS', 'Configure MapBox SDK'), - utils.createStepAssertion('Setup Node', true, null, 'IOS', 'Setting up Node'), - utils.createStepAssertion('Setup Ruby', true, null, 'IOS', 'Setting up Ruby', [ + createStepAssertion('Checkout', true, null, 'IOS', 'Checking out'), + createStepAssertion('Configure MapBox SDK', true, null, 'IOS', 'Configure MapBox SDK'), + createStepAssertion('Setup Node', true, null, 'IOS', 'Setting up Node'), + createStepAssertion('Setup Ruby', true, null, 'IOS', 'Setting up Ruby', [ {key: 'ruby-version', value: '2.7'}, {key: 'bundler-cache', value: 'true'}, ]), - utils.createStepAssertion('Cache Pod dependencies', true, null, 'IOS', 'Cache Pod dependencies', [ + createStepAssertion('Cache Pod dependencies', true, null, 'IOS', 'Cache Pod dependencies', [ {key: 'path', value: 'ios/Pods'}, {key: 'key', value: 'Linux-pods-cache-'}, {key: 'restore-keys', value: 'Linux-pods-cache-'}, ]), - utils.createStepAssertion('Compare Podfile.lock and Manifest.lock', true, null, 'IOS', 'Compare Podfile.lock and Manifest.lock'), - utils.createStepAssertion('Install cocoapods', true, null, 'IOS', 'Installing cocoapods', [ + createStepAssertion('Compare Podfile.lock and Manifest.lock', true, null, 'IOS', 'Compare Podfile.lock and Manifest.lock'), + createStepAssertion('Install cocoapods', true, null, 'IOS', 'Installing cocoapods', [ {key: 'timeout_minutes', value: '10'}, {key: 'max_attempts', value: '5'}, {key: 'command', value: 'cd ios && bundle exec pod install'}, ]), - utils.createStepAssertion('Decrypt AppStore profile', true, null, 'IOS', 'Decrypting profile', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Decrypt AppStore Notification Service profile', true, null, 'IOS', 'Decrypting profile', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Decrypt certificate', true, null, 'IOS', 'Decrypting certificate', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Decrypt App Store Connect API key', true, null, 'IOS', 'Decrypting App Store API key', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Decrypt AppStore profile', true, null, 'IOS', 'Decrypting profile', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Decrypt AppStore Notification Service profile', true, null, 'IOS', 'Decrypting profile', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Decrypt certificate', true, null, 'IOS', 'Decrypting certificate', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Decrypt App Store Connect API key', true, null, 'IOS', 'Decrypting App Store API key', null, [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), ]; + if (!isProduction) { steps.push( - utils.createStepAssertion('Run Fastlane', true, null, 'IOS', 'Running Fastlane', null, [ + createStepAssertion('Run Fastlane', true, null, 'IOS', 'Running Fastlane', null, [ {key: 'APPLE_CONTACT_EMAIL', value: '***'}, {key: 'APPLE_CONTACT_PHONE', value: '***'}, {key: 'APPLE_DEMO_EMAIL', value: '***'}, @@ -186,23 +186,23 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction = ); } steps.push( - utils.createStepAssertion('Archive iOS sourcemaps', true, null, 'IOS', 'Archiving sourcemaps', [ + createStepAssertion('Archive iOS sourcemaps', true, null, 'IOS', 'Archiving sourcemaps', [ {key: 'name', value: 'ios-sourcemap'}, {key: 'path', value: 'main.jsbundle.map'}, ]), ); if (!isProduction) { steps.push( - utils.createStepAssertion('Upload iOS version to GitHub artifacts', true, null, 'IOS', 'Upload iOS version to GitHub artifacts', [ + createStepAssertion('Upload iOS version to GitHub artifacts', true, null, 'IOS', 'Upload iOS version to GitHub artifacts', [ {key: 'name', value: 'New Expensify.ipa'}, {key: 'path', value: '/Users/runner/work/App/App/New Expensify.ipa'}, ]), - utils.createStepAssertion('Upload iOS version to Browser Stack', true, null, 'IOS', 'Uploading version to Browser Stack', null, [{key: 'BROWSERSTACK', value: '***'}]), + createStepAssertion('Upload iOS version to Browser Stack', true, null, 'IOS', 'Uploading version to Browser Stack', null, [{key: 'BROWSERSTACK', value: '***'}]), ); } else { steps.push( - utils.createStepAssertion('Set iOS version in ENV', true, null, 'IOS', 'Setting iOS version'), - utils.createStepAssertion('Run Fastlane for App Store release', true, null, 'IOS', 'Running Fastlane for release', null, [{key: 'VERSION', value: '1.2.3'}]), + createStepAssertion('Set iOS version in ENV', true, null, 'IOS', 'Setting iOS version'), + createStepAssertion('Run Fastlane for App Store release', true, null, 'IOS', 'Running Fastlane for release', null, [{key: 'VERSION', value: '1.2.3'}]), ); } @@ -215,7 +215,7 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction = }); const failProdSteps = [ - utils.createStepAssertion( + createStepAssertion( 'Warn deployers if iOS production deploy failed', true, null, @@ -227,7 +227,7 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction = {key: 'SLACK_WEBHOOK_URL', value: '***'}, ], ), - ]; + ] as const; failProdSteps.forEach((expectedStep) => { if (didExecute && isProduction && !isSuccessful) { @@ -236,32 +236,33 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction = expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertWebJobExecuted = (workflowResult, didExecute = true, isProduction = true) => { +function assertWebJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'WEB', 'Checking out'), - utils.createStepAssertion('Setup Node', true, null, 'WEB', 'Setting up Node'), - utils.createStepAssertion('Setup Cloudflare CLI', true, null, 'WEB', 'Setting up Cloudflare CLI'), - utils.createStepAssertion('Configure AWS Credentials', true, null, 'WEB', 'Configuring AWS credentials', [ + createStepAssertion('Checkout', true, null, 'WEB', 'Checking out'), + createStepAssertion('Setup Node', true, null, 'WEB', 'Setting up Node'), + createStepAssertion('Setup Cloudflare CLI', true, null, 'WEB', 'Setting up Cloudflare CLI'), + createStepAssertion('Configure AWS Credentials', true, null, 'WEB', 'Configuring AWS credentials', [ {key: 'aws-access-key-id', value: '***'}, {key: 'aws-secret-access-key', value: '***'}, {key: 'aws-region', value: 'us-east-1'}, ]), ]; + if (isProduction) { steps.push( - utils.createStepAssertion('Build web for production', true, null, 'WEB', 'Building web for production'), - utils.createStepAssertion('Build storybook docs for production', true, null, 'WEB', 'Build storybook docs for production'), - utils.createStepAssertion('Deploy production to S3', true, null, 'WEB', 'Deploying production to S3'), - utils.createStepAssertion('Purge production Cloudflare cache', true, null, 'WEB', 'Purging production Cloudflare cache', null, [{key: 'CF_API_KEY', value: '***'}]), + createStepAssertion('Build web for production', true, null, 'WEB', 'Building web for production'), + createStepAssertion('Build storybook docs for production', true, null, 'WEB', 'Build storybook docs for production'), + createStepAssertion('Deploy production to S3', true, null, 'WEB', 'Deploying production to S3'), + createStepAssertion('Purge production Cloudflare cache', true, null, 'WEB', 'Purging production Cloudflare cache', null, [{key: 'CF_API_KEY', value: '***'}]), ); } else { steps.push( - utils.createStepAssertion('Build web for staging', true, null, 'WEB', 'Building web for staging'), - utils.createStepAssertion('Build storybook docs for staging', true, null, 'WEB', 'Build storybook docs for staging'), - utils.createStepAssertion('Deploy staging to S3', true, null, 'WEB', 'Deploying staging to S3'), - utils.createStepAssertion('Purge staging Cloudflare cache', true, null, 'WEB', 'Purging staging Cloudflare cache', null, [{key: 'CF_API_KEY', value: '***'}]), + createStepAssertion('Build web for staging', true, null, 'WEB', 'Building web for staging'), + createStepAssertion('Build storybook docs for staging', true, null, 'WEB', 'Build storybook docs for staging'), + createStepAssertion('Deploy staging to S3', true, null, 'WEB', 'Deploying staging to S3'), + createStepAssertion('Purge staging Cloudflare cache', true, null, 'WEB', 'Purging staging Cloudflare cache', null, [{key: 'CF_API_KEY', value: '***'}]), ); } @@ -272,12 +273,12 @@ const assertWebJobExecuted = (workflowResult, didExecute = true, isProduction = expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertPostSlackOnFailureJobExecuted = (workflowResult, didExecute = true) => { +function assertPostSlackOnFailureJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Post Slack message on failure', true, null, 'POST_SLACK_FAIL', 'Posting Slack message on platform deploy failure', [{key: 'SLACK_WEBHOOK', value: '***'}]), - ]; + createStepAssertion('Post Slack message on failure', true, null, 'POST_SLACK_FAIL', 'Posting Slack message on platform deploy failure', [{key: 'SLACK_WEBHOOK', value: '***'}]), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -286,13 +287,13 @@ const assertPostSlackOnFailureJobExecuted = (workflowResult, didExecute = true) expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertPostSlackOnSuccessJobExecuted = (workflowResult, didExecute = true, isProduction = true) => { +function assertPostSlackOnSuccessJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'POST_SLACK_SUCCESS', 'Checking out'), - utils.createStepAssertion('Set version', true, null, 'POST_SLACK_SUCCESS', 'Setting version'), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'POST_SLACK_SUCCESS', 'Checking out'), + createStepAssertion('Set version', true, null, 'POST_SLACK_SUCCESS', 'Setting version'), + createStepAssertion( 'Announces the deploy in the #announce Slack room', true, null, @@ -304,7 +305,7 @@ const assertPostSlackOnSuccessJobExecuted = (workflowResult, didExecute = true, {key: 'SLACK_WEBHOOK_URL', value: '***'}, ], ), - utils.createStepAssertion( + createStepAssertion( 'Announces the deploy in the #deployer Slack room', true, null, @@ -317,9 +318,10 @@ const assertPostSlackOnSuccessJobExecuted = (workflowResult, didExecute = true, ], ), ]; + if (isProduction) { steps.push( - utils.createStepAssertion( + createStepAssertion( 'Announces the deploy in the #expensify-open-source Slack room', true, null, @@ -341,19 +343,19 @@ const assertPostSlackOnSuccessJobExecuted = (workflowResult, didExecute = true, expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertPostGithubCommentJobExecuted = (workflowResult, didExecute = true, isProduction = true, didDeploy = true) => { +function assertPostGithubCommentJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true, didDeploy = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'POST_GITHUB_COMMENT', 'Checking out'), - utils.createStepAssertion('Setup Node', true, null, 'POST_GITHUB_COMMENT', 'Setting up Node'), - utils.createStepAssertion('Set version', true, null, 'POST_GITHUB_COMMENT', 'Setting version'), - utils.createStepAssertion('Get Release Pull Request List', true, null, 'POST_GITHUB_COMMENT', 'Getting release pull request list', [ + createStepAssertion('Checkout', true, null, 'POST_GITHUB_COMMENT', 'Checking out'), + createStepAssertion('Setup Node', true, null, 'POST_GITHUB_COMMENT', 'Setting up Node'), + createStepAssertion('Set version', true, null, 'POST_GITHUB_COMMENT', 'Setting version'), + createStepAssertion('Get Release Pull Request List', true, null, 'POST_GITHUB_COMMENT', 'Getting release pull request list', [ {key: 'TAG', value: '1.2.3'}, {key: 'GITHUB_TOKEN', value: '***'}, {key: 'IS_PRODUCTION_DEPLOY', value: isProduction ? 'true' : 'false'}, ]), - utils.createStepAssertion('Comment on issues', true, null, 'POST_GITHUB_COMMENT', 'Commenting on issues', [ + createStepAssertion('Comment on issues', true, null, 'POST_GITHUB_COMMENT', 'Commenting on issues', [ {key: 'PR_LIST', value: '[1.2.1, 1.2.2]'}, {key: 'IS_PRODUCTION_DEPLOY', value: isProduction ? 'true' : 'false'}, {key: 'DEPLOY_VERSION', value: '1.2.3'}, @@ -363,7 +365,7 @@ const assertPostGithubCommentJobExecuted = (workflowResult, didExecute = true, i {key: 'IOS', value: didDeploy ? 'success' : ''}, {key: 'WEB', value: didDeploy ? 'success' : ''}, ]), - ]; + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -372,9 +374,9 @@ const assertPostGithubCommentJobExecuted = (workflowResult, didExecute = true, i expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -module.exports = { +export { assertVerifyActorJobExecuted, assertDeployChecklistJobExecuted, assertAndroidJobExecuted, diff --git a/workflow_tests/assertions/preDeployAssertions.js b/workflow_tests/assertions/preDeployAssertions.ts similarity index 53% rename from workflow_tests/assertions/preDeployAssertions.js rename to workflow_tests/assertions/preDeployAssertions.ts index 1ed7d52bd53f..8a89d2377606 100644 --- a/workflow_tests/assertions/preDeployAssertions.js +++ b/workflow_tests/assertions/preDeployAssertions.ts @@ -1,7 +1,8 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertTypecheckJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Run typecheck workflow', true, null, 'TYPECHECK', 'Running typecheck workflow')]; +function assertTypecheckJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Run typecheck workflow', true, null, 'TYPECHECK', 'Running typecheck workflow')] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -10,10 +11,10 @@ const assertTypecheckJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertLintJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Run lint workflow', true, null, 'LINT', 'Running lint workflow')]; +function assertLintJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Run lint workflow', true, null, 'LINT', 'Running lint workflow')] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -22,10 +23,10 @@ const assertLintJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertTestJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Run test workflow', true, null, 'TEST', 'Running test workflow')]; +function assertTestJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Run test workflow', true, null, 'TEST', 'Running test workflow')] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -34,14 +35,14 @@ const assertTestJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertChooseDeployActionsJobExecuted = (workflowResult, didExecute = true) => { +function assertChooseDeployActionsJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Get merged pull request', true, null, 'CHOOSE_DEPLOY_ACTIONS', 'Getting merged pull request', [{key: 'github_token', value: '***'}]), - utils.createStepAssertion('Check if StagingDeployCash is locked', true, null, 'CHOOSE_DEPLOY_ACTIONS', 'Checking StagingDeployCash', [{key: 'GITHUB_TOKEN', value: '***'}]), - utils.createStepAssertion('Check if merged pull request should trigger a deploy', true, ''), - ]; + createStepAssertion('Get merged pull request', true, null, 'CHOOSE_DEPLOY_ACTIONS', 'Getting merged pull request', [{key: 'github_token', value: '***'}]), + createStepAssertion('Check if StagingDeployCash is locked', true, null, 'CHOOSE_DEPLOY_ACTIONS', 'Checking StagingDeployCash', [{key: 'GITHUB_TOKEN', value: '***'}]), + createStepAssertion('Check if merged pull request should trigger a deploy', true, ''), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -50,17 +51,17 @@ const assertChooseDeployActionsJobExecuted = (workflowResult, didExecute = true) expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertSkipDeployJobExecuted = (workflowResult, didExecute = true) => { - const body = ':hand: This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.'; +function assertSkipDeployJobExecuted(workflowResult: Step[], didExecute = true) { + const body = ':hand: This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.' as const; const steps = [ - utils.createStepAssertion('Comment on deferred PR', true, null, 'SKIP_DEPLOY', 'Skipping deploy', [ + createStepAssertion('Comment on deferred PR', true, null, 'SKIP_DEPLOY', 'Skipping deploy', [ {key: 'github_token', value: '***'}, {key: 'number', value: '123'}, {key: 'body', value: body}, ]), - ]; + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -69,10 +70,10 @@ const assertSkipDeployJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Create new version', true, null, 'CREATE_NEW_VERSION', 'Creating new version')]; +function assertCreateNewVersionJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Create new version', true, null, 'CREATE_NEW_VERSION', 'Creating new version')] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -81,21 +82,21 @@ const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) => expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true) => { +function assertUpdateStagingJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Run turnstyle', true, null, 'UPDATE_STAGING', 'Running turnstyle', [ + createStepAssertion('Run turnstyle', true, null, 'UPDATE_STAGING', 'Running turnstyle', [ {key: 'poll-interval-seconds', value: '10'}, {key: 'GITHUB_TOKEN', value: '***'}, ]), - utils.createStepAssertion('Checkout main', true, null, 'UPDATE_STAGING', 'Checkout main', [ + createStepAssertion('Checkout main', true, null, 'UPDATE_STAGING', 'Checkout main', [ {key: 'ref', value: 'main'}, {key: 'token', value: '***'}, ]), - utils.createStepAssertion('Setup Git for OSBotify', true, null, 'UPDATE_STAGING', 'Setup Git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Update staging branch from main', true, null, 'UPDATE_STAGING', 'Update staging branch from main'), - ]; + createStepAssertion('Setup Git for OSBotify', true, null, 'UPDATE_STAGING', 'Setup Git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}]), + createStepAssertion('Update staging branch from main', true, null, 'UPDATE_STAGING', 'Update staging branch from main'), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -104,12 +105,12 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertUpdateStagingJobFailed = (workflowResult, didFail = false) => { +function assertUpdateStagingJobFailed(workflowResult: Step[], didFail = false) { const steps = [ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'UPDATE_STAGING', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}]), - ]; + createStepAssertion('Announce failed workflow in Slack', true, null, 'UPDATE_STAGING', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}]), + ] as const; steps.forEach((expectedStep) => { if (didFail) { @@ -118,9 +119,9 @@ const assertUpdateStagingJobFailed = (workflowResult, didFail = false) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -module.exports = { +export default { assertTypecheckJobExecuted, assertLintJobExecuted, assertTestJobExecuted, diff --git a/workflow_tests/assertions/reviewerChecklistAssertions.js b/workflow_tests/assertions/reviewerChecklistAssertions.js deleted file mode 100644 index 6154b1cd28ca..000000000000 --- a/workflow_tests/assertions/reviewerChecklistAssertions.js +++ /dev/null @@ -1,17 +0,0 @@ -const utils = require('../utils/utils'); - -const assertChecklistJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('reviewerChecklist.js', true, null, 'CHECKLIST', 'reviewerChecklist.js', [{key: 'GITHUB_TOKEN', value: '***'}], [])]; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -}; - -module.exports = { - assertChecklistJobExecuted, -}; diff --git a/workflow_tests/assertions/reviewerChecklistAssertions.ts b/workflow_tests/assertions/reviewerChecklistAssertions.ts new file mode 100644 index 000000000000..6d74e27df1a0 --- /dev/null +++ b/workflow_tests/assertions/reviewerChecklistAssertions.ts @@ -0,0 +1,17 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertChecklistJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('reviewerChecklist.js', true, null, 'CHECKLIST', 'reviewerChecklist.js', [{key: 'GITHUB_TOKEN', value: '***'}], [])] as const; + + steps.forEach((expectedStep) => { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + }); +} + +// eslint-disable-next-line import/prefer-default-export +export {assertChecklistJobExecuted}; diff --git a/workflow_tests/assertions/testAssertions.js b/workflow_tests/assertions/testAssertions.ts similarity index 55% rename from workflow_tests/assertions/testAssertions.js rename to workflow_tests/assertions/testAssertions.ts index cee379ad5903..e0d1d6b37022 100644 --- a/workflow_tests/assertions/testAssertions.js +++ b/workflow_tests/assertions/testAssertions.ts @@ -1,11 +1,12 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertJestJobExecuted = (workflowResult, didExecute = true, timesExecuted = 3) => { +function assertJestJobExecuted(workflowResult: Step[], didExecute = true, timesExecuted = 3) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'JEST', 'Checkout', [], []), - utils.createStepAssertion('Setup Node', true, null, 'JEST', 'Setup Node', [], []), - utils.createStepAssertion('Get number of CPU cores', true, null, 'JEST', 'Get number of CPU cores', [], []), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'JEST', 'Checkout', [], []), + createStepAssertion('Setup Node', true, null, 'JEST', 'Setup Node', [], []), + createStepAssertion('Get number of CPU cores', true, null, 'JEST', 'Get number of CPU cores', [], []), + createStepAssertion( 'Cache Jest cache', true, null, @@ -17,8 +18,8 @@ const assertJestJobExecuted = (workflowResult, didExecute = true, timesExecuted ], [], ), - utils.createStepAssertion('Jest tests', true, null, 'JEST', 'Jest tests', [], []), - ]; + createStepAssertion('Jest tests', true, null, 'JEST', 'Jest tests', [], []), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -35,13 +36,14 @@ const assertJestJobExecuted = (workflowResult, didExecute = true, timesExecuted expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertShellTestsJobExecuted = (workflowResult, didExecute = true) => { +} + +function assertShellTestsJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'SHELLTESTS', 'Checkout', [], []), - utils.createStepAssertion('Setup Node', true, null, 'SHELLTESTS', 'Setup Node', [], []), - utils.createStepAssertion('Test CI git logic', true, null, 'SHELLTESTS', 'Test CI git logic', [], []), - ]; + createStepAssertion('Checkout', true, null, 'SHELLTESTS', 'Checkout', [], []), + createStepAssertion('Setup Node', true, null, 'SHELLTESTS', 'Setup Node', [], []), + createStepAssertion('Test CI git logic', true, null, 'SHELLTESTS', 'Test CI git logic', [], []), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -50,9 +52,6 @@ const assertShellTestsJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -module.exports = { - assertJestJobExecuted, - assertShellTestsJobExecuted, -}; +export {assertJestJobExecuted, assertShellTestsJobExecuted}; diff --git a/workflow_tests/assertions/testBuildAssertions.js b/workflow_tests/assertions/testBuildAssertions.ts similarity index 65% rename from workflow_tests/assertions/testBuildAssertions.js rename to workflow_tests/assertions/testBuildAssertions.ts index 3fe963f3aa35..02e64fb83889 100644 --- a/workflow_tests/assertions/testBuildAssertions.js +++ b/workflow_tests/assertions/testBuildAssertions.ts @@ -1,9 +1,10 @@ -const utils = require('../utils/utils'); +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; -const assertValidateActorJobExecuted = (workflowResult, pullRequestNumber = '1234', didExecute = true) => { +function assertValidateActorJobExecuted(workflowResult: Step[], pullRequestNumber = '1234', didExecute = true) { const steps = [ - utils.createStepAssertion('Is Expensify employee', true, null, 'VALIDATEACTOR', 'Is Expensify employee', [], [{key: 'GITHUB_TOKEN', value: '***'}]), - utils.createStepAssertion( + createStepAssertion('Is Expensify employee', true, null, 'VALIDATEACTOR', 'Is Expensify employee', [], [{key: 'GITHUB_TOKEN', value: '***'}]), + createStepAssertion( 'Set HAS_READY_TO_BUILD_LABEL flag', true, null, @@ -15,7 +16,7 @@ const assertValidateActorJobExecuted = (workflowResult, pullRequestNumber = '123 {key: 'GITHUB_TOKEN', value: '***'}, ], ), - ]; + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -24,20 +25,13 @@ const assertValidateActorJobExecuted = (workflowResult, pullRequestNumber = '123 expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertGetBranchRefJobExecuted = (workflowResult, didExecute = true) => { +} + +function assertGetBranchRefJobExecuted(workflowResult: Step[], didExecute = true) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'GETBRANCHREF', 'Checkout', [], []), - utils.createStepAssertion( - 'Check if pull request number is correct', - true, - null, - 'GETBRANCHREF', - 'Check if pull request number is correct', - [], - [{key: 'GITHUB_TOKEN', value: '***'}], - ), - ]; + createStepAssertion('Checkout', true, null, 'GETBRANCHREF', 'Checkout', [], []), + createStepAssertion('Check if pull request number is correct', true, null, 'GETBRANCHREF', 'Check if pull request number is correct', [], [{key: 'GITHUB_TOKEN', value: '***'}]), + ] as const; steps.forEach((expectedStep) => { if (didExecute) { @@ -46,21 +40,14 @@ const assertGetBranchRefJobExecuted = (workflowResult, didExecute = true) => { expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { +} + +function assertAndroidJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'ANDROID', 'Checkout', [{key: 'ref', value: ref}], []), - utils.createStepAssertion( - 'Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', - true, - null, - 'ANDROID', - 'Creating .env.adhoc file based on staging', - [], - [], - ), - utils.createStepAssertion('Setup Node', true, null, 'ANDROID', 'Setup Node', [], []), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'ANDROID', 'Checkout', [{key: 'ref', value: ref}], []), + createStepAssertion('Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', true, null, 'ANDROID', 'Creating .env.adhoc file based on staging', [], []), + createStepAssertion('Setup Node', true, null, 'ANDROID', 'Setup Node', [], []), + createStepAssertion( 'Setup Java', true, null, @@ -72,7 +59,7 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f ], [], ), - utils.createStepAssertion( + createStepAssertion( 'Setup Ruby', true, null, @@ -84,9 +71,9 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f ], [], ), - utils.createStepAssertion('Decrypt keystore', true, null, 'ANDROID', 'Decrypt keystore', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion('Decrypt json key', true, null, 'ANDROID', 'Decrypt json key', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion( + createStepAssertion('Decrypt keystore', true, null, 'ANDROID', 'Decrypt keystore', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion('Decrypt json key', true, null, 'ANDROID', 'Decrypt json key', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion( 'Configure AWS Credentials', true, null, @@ -99,8 +86,8 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f ], [], ), - utils.createStepAssertion('Configure MapBox SDK', true, null, 'ANDROID', 'Configure MapBox SDK'), - utils.createStepAssertion( + createStepAssertion('Configure MapBox SDK', true, null, 'ANDROID', 'Configure MapBox SDK'), + createStepAssertion( 'Run Fastlane beta test', true, null, @@ -116,7 +103,7 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f {key: 'MYAPP_UPLOAD_KEY_PASSWORD', value: '***'}, ], ), - utils.createStepAssertion( + createStepAssertion( 'Upload Artifact', true, null, @@ -128,7 +115,7 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f ], [], ), - ]; + ] as const; steps.forEach((expectedStep, i) => { if (didExecute) { @@ -147,15 +134,16 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { +} + +function assertIOSJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'IOS', 'Checkout', [{key: 'ref', value: ref}], []), - utils.createStepAssertion('Configure MapBox SDK', true, null, 'IOS', 'Configure MapBox SDK'), - utils.createStepAssertion('Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', true, null, 'IOS', 'Creating .env.adhoc file based on staging', [], []), - utils.createStepAssertion('Setup Node', true, null, 'IOS', 'Setup Node', [], []), - utils.createStepAssertion('Setup XCode', true, null, 'IOS', 'Setup XCode', [], []), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'IOS', 'Checkout', [{key: 'ref', value: ref}], []), + createStepAssertion('Configure MapBox SDK', true, null, 'IOS', 'Configure MapBox SDK'), + createStepAssertion('Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', true, null, 'IOS', 'Creating .env.adhoc file based on staging', [], []), + createStepAssertion('Setup Node', true, null, 'IOS', 'Setup Node', [], []), + createStepAssertion('Setup XCode', true, null, 'IOS', 'Setup XCode', [], []), + createStepAssertion( 'Setup Ruby', true, null, @@ -167,13 +155,13 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails ], [], ), - utils.createStepAssertion('Cache Pod dependencies', true, null, 'IOS', 'Cache Pod dependencies', [ + createStepAssertion('Cache Pod dependencies', true, null, 'IOS', 'Cache Pod dependencies', [ {key: 'path', value: 'ios/Pods'}, {key: 'key', value: 'Linux-pods-cache-'}, {key: 'restore-keys', value: 'Linux-pods-cache-'}, ]), - utils.createStepAssertion('Compare Podfile.lock and Manifest.lock', true, null, 'IOS', 'Compare Podfile.lock and Manifest.lock'), - utils.createStepAssertion( + createStepAssertion('Compare Podfile.lock and Manifest.lock', true, null, 'IOS', 'Compare Podfile.lock and Manifest.lock'), + createStepAssertion( 'Install cocoapods', true, null, @@ -186,8 +174,8 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails ], [], ), - utils.createStepAssertion('Decrypt AdHoc profile', true, null, 'IOS', 'Decrypt AdHoc profile', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion( + createStepAssertion('Decrypt AdHoc profile', true, null, 'IOS', 'Decrypt AdHoc profile', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion( 'Decrypt AdHoc Notification Service profile', true, null, @@ -196,8 +184,8 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}], ), - utils.createStepAssertion('Decrypt certificate', true, null, 'IOS', 'Decrypt certificate', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion( + createStepAssertion('Decrypt certificate', true, null, 'IOS', 'Decrypt certificate', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion( 'Configure AWS Credentials', true, null, @@ -210,7 +198,7 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails ], [], ), - utils.createStepAssertion( + createStepAssertion( 'Run Fastlane', true, null, @@ -224,7 +212,7 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails {key: 'S3_REGION', value: 'us-east-1'}, ], ), - utils.createStepAssertion( + createStepAssertion( 'Upload Artifact', true, null, @@ -236,7 +224,7 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails ], [], ), - ]; + ] as const; steps.forEach((expectedStep, i) => { if (didExecute) { @@ -255,22 +243,15 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertDesktopJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { +} + +function assertDesktopJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'DESKTOP', 'Checkout', [{key: 'ref', value: ref}], []), - utils.createStepAssertion( - 'Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', - true, - null, - 'DESKTOP', - 'Creating .env.adhoc file based on staging', - [], - [], - ), - utils.createStepAssertion('Setup Node', true, null, 'DESKTOP', 'Setup Node', [], []), - utils.createStepAssertion('Decrypt Developer ID Certificate', true, null, 'DESKTOP', 'Decrypt Developer ID Certificate', [], [{key: 'DEVELOPER_ID_SECRET_PASSPHRASE', value: '***'}]), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'DESKTOP', 'Checkout', [{key: 'ref', value: ref}], []), + createStepAssertion('Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', true, null, 'DESKTOP', 'Creating .env.adhoc file based on staging', [], []), + createStepAssertion('Setup Node', true, null, 'DESKTOP', 'Setup Node', [], []), + createStepAssertion('Decrypt Developer ID Certificate', true, null, 'DESKTOP', 'Decrypt Developer ID Certificate', [], [{key: 'DEVELOPER_ID_SECRET_PASSPHRASE', value: '***'}]), + createStepAssertion( 'Configure AWS Credentials', true, null, @@ -283,7 +264,7 @@ const assertDesktopJobExecuted = (workflowResult, ref = '', didExecute = true, f ], [], ), - utils.createStepAssertion( + createStepAssertion( 'Build desktop app for testing', true, null, @@ -299,7 +280,7 @@ const assertDesktopJobExecuted = (workflowResult, ref = '', didExecute = true, f {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, ], ), - ]; + ] as const; steps.forEach((expectedStep, i) => { if (didExecute) { @@ -318,13 +299,14 @@ const assertDesktopJobExecuted = (workflowResult, ref = '', didExecute = true, f expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; -const assertWebJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { +} + +function assertWebJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'WEB', 'Checkout', [{key: 'ref', value: ref}], []), - utils.createStepAssertion('Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', true, null, 'WEB', 'Creating .env.adhoc file based on staging', [], []), - utils.createStepAssertion('Setup Node', true, null, 'WEB', 'Setup Node', [], []), - utils.createStepAssertion( + createStepAssertion('Checkout', true, null, 'WEB', 'Checkout', [{key: 'ref', value: ref}], []), + createStepAssertion('Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', true, null, 'WEB', 'Creating .env.adhoc file based on staging', [], []), + createStepAssertion('Setup Node', true, null, 'WEB', 'Setup Node', [], []), + createStepAssertion( 'Configure AWS Credentials', true, null, @@ -337,10 +319,10 @@ const assertWebJobExecuted = (workflowResult, ref = '', didExecute = true, fails ], [], ), - utils.createStepAssertion('Build web for testing', true, null, 'WEB', 'Build web for testing', [], []), - utils.createStepAssertion('Build docs', true, null, 'WEB', 'Build docs', [], []), - utils.createStepAssertion('Deploy to S3 for internal testing', true, null, 'WEB', 'Deploy to S3 for internal testing', [], []), - ]; + createStepAssertion('Build web for testing', true, null, 'WEB', 'Build web for testing', [], []), + createStepAssertion('Build docs', true, null, 'WEB', 'Build docs', [], []), + createStepAssertion('Deploy to S3 for internal testing', true, null, 'WEB', 'Deploy to S3 for internal testing', [], []), + ] as const; steps.forEach((expectedStep, i) => { if (didExecute) { @@ -359,10 +341,10 @@ const assertWebJobExecuted = (workflowResult, ref = '', didExecute = true, fails expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -const assertPostGithubCommentJobExecuted = ( - workflowResult, +function assertPostGithubCommentJobExecuted( + workflowResult: Step[], ref = '', pullRequestNumber = '1234', didExecute = true, @@ -370,19 +352,21 @@ const assertPostGithubCommentJobExecuted = ( iOSStatus = 'success', desktopStatus = 'success', webStatus = 'success', -) => { +) { const steps = [ - utils.createStepAssertion('Checkout', true, null, 'POSTGITHUBCOMMENT', 'Checkout', [{key: 'ref', value: ref}], []), - utils.createStepAssertion('Download Artifact', true, null, 'POSTGITHUBCOMMENT', 'Download Artifact', [], []), + createStepAssertion('Checkout', true, null, 'POSTGITHUBCOMMENT', 'Checkout', [{key: 'ref', value: ref}], []), + createStepAssertion('Download Artifact', true, null, 'POSTGITHUBCOMMENT', 'Download Artifact', [], []), ]; + if (androidStatus === 'success') { - steps.push(utils.createStepAssertion('Read JSONs with android paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with android paths', [], [])); + steps.push(createStepAssertion('Read JSONs with android paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with android paths', [], [])); } if (iOSStatus === 'success') { - steps.push(utils.createStepAssertion('Read JSONs with iOS paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with iOS paths', [], [])); + steps.push(createStepAssertion('Read JSONs with iOS paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with iOS paths', [], [])); } + steps.push( - utils.createStepAssertion( + createStepAssertion( 'Publish links to apps for download', true, null, @@ -411,9 +395,9 @@ const assertPostGithubCommentJobExecuted = ( expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); } }); -}; +} -module.exports = { +export { assertValidateActorJobExecuted, assertGetBranchRefJobExecuted, assertAndroidJobExecuted, diff --git a/workflow_tests/assertions/validateGithubActionsAssertions.js b/workflow_tests/assertions/validateGithubActionsAssertions.js deleted file mode 100644 index fb5f58d2b5ed..000000000000 --- a/workflow_tests/assertions/validateGithubActionsAssertions.js +++ /dev/null @@ -1,22 +0,0 @@ -const utils = require('../utils/utils'); - -const assertVerifyJobExecuted = (workflowResult, didExecute = true) => { - const steps = [ - utils.createStepAssertion('Checkout', true, null, 'VERIFY', 'Checkout'), - utils.createStepAssertion('Setup Node', true, null, 'VERIFY', 'Setup Node', [], []), - utils.createStepAssertion('Verify Javascript Action Builds', true, null, 'VERIFY', 'Verify Javascript Action Builds', [], []), - utils.createStepAssertion('Validate actions and workflows', true, null, 'VERIFY', 'Validate actions and workflows', [], []), - ]; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -}; - -module.exports = { - assertVerifyJobExecuted, -}; diff --git a/workflow_tests/assertions/validateGithubActionsAssertions.ts b/workflow_tests/assertions/validateGithubActionsAssertions.ts new file mode 100644 index 000000000000..34d694111b1e --- /dev/null +++ b/workflow_tests/assertions/validateGithubActionsAssertions.ts @@ -0,0 +1,22 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertVerifyJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [ + createStepAssertion('Checkout', true, null, 'VERIFY', 'Checkout'), + createStepAssertion('Setup Node', true, null, 'VERIFY', 'Setup Node', [], []), + createStepAssertion('Verify Javascript Action Builds', true, null, 'VERIFY', 'Verify Javascript Action Builds', [], []), + createStepAssertion('Validate actions and workflows', true, null, 'VERIFY', 'Validate actions and workflows', [], []), + ] as const; + + steps.forEach((expectedStep) => { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + }); +} + +// eslint-disable-next-line import/prefer-default-export +export {assertVerifyJobExecuted}; diff --git a/workflow_tests/assertions/verifyPodfileAssertions.js b/workflow_tests/assertions/verifyPodfileAssertions.js deleted file mode 100644 index e0cc50570fec..000000000000 --- a/workflow_tests/assertions/verifyPodfileAssertions.js +++ /dev/null @@ -1,21 +0,0 @@ -const utils = require('../utils/utils'); - -const assertVerifyJobExecuted = (workflowResult, didExecute = true) => { - const steps = [ - utils.createStepAssertion('Checkout', true, null, 'VERIFY', 'Checkout'), - utils.createStepAssertion('Setup Node', true, null, 'VERIFY', 'Setup Node', [], []), - utils.createStepAssertion('Verify podfile', true, null, 'VERIFY', 'Verify podfile', [], []), - ]; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -}; - -module.exports = { - assertVerifyJobExecuted, -}; diff --git a/workflow_tests/assertions/verifyPodfileAssertions.ts b/workflow_tests/assertions/verifyPodfileAssertions.ts new file mode 100644 index 000000000000..c2e4a1d8f30e --- /dev/null +++ b/workflow_tests/assertions/verifyPodfileAssertions.ts @@ -0,0 +1,21 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertVerifyJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [ + createStepAssertion('Checkout', true, null, 'VERIFY', 'Checkout'), + createStepAssertion('Setup Node', true, null, 'VERIFY', 'Setup Node', [], []), + createStepAssertion('Verify podfile', true, null, 'VERIFY', 'Verify podfile', [], []), + ] as const; + + steps.forEach((expectedStep) => { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + }); +} + +// eslint-disable-next-line import/prefer-default-export +export {assertVerifyJobExecuted}; diff --git a/workflow_tests/assertions/verifySignedCommitsAssertions.js b/workflow_tests/assertions/verifySignedCommitsAssertions.js deleted file mode 100644 index 458bc684363f..000000000000 --- a/workflow_tests/assertions/verifySignedCommitsAssertions.js +++ /dev/null @@ -1,17 +0,0 @@ -const utils = require('../utils/utils'); - -const assertVerifySignedCommitsJobExecuted = (workflowResult, didExecute = true) => { - const steps = [utils.createStepAssertion('Verify signed commits', true, null, 'VERIFYSIGNEDCOMMITS', 'Verify signed commits', [{key: 'GITHUB_TOKEN', value: '***'}], [])]; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -}; - -module.exports = { - assertVerifySignedCommitsJobExecuted, -}; diff --git a/workflow_tests/assertions/verifySignedCommitsAssertions.ts b/workflow_tests/assertions/verifySignedCommitsAssertions.ts new file mode 100644 index 000000000000..99b2e28eb582 --- /dev/null +++ b/workflow_tests/assertions/verifySignedCommitsAssertions.ts @@ -0,0 +1,17 @@ +import type {Step} from '@kie/act-js'; +import {createStepAssertion} from '../utils/utils'; + +function assertVerifySignedCommitsJobExecuted(workflowResult: Step[], didExecute = true) { + const steps = [createStepAssertion('Verify signed commits', true, null, 'VERIFYSIGNEDCOMMITS', 'Verify signed commits', [{key: 'GITHUB_TOKEN', value: '***'}], [])] as const; + + steps.forEach((expectedStep) => { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + }); +} + +// eslint-disable-next-line import/prefer-default-export +export {assertVerifySignedCommitsJobExecuted}; diff --git a/workflow_tests/finishReleaseCycle.test.js b/workflow_tests/finishReleaseCycle.test.js index 20ab66471d91..94aa4a7be22e 100644 --- a/workflow_tests/finishReleaseCycle.test.js +++ b/workflow_tests/finishReleaseCycle.test.js @@ -2,7 +2,7 @@ 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 mocks = require('./mocks/finishReleaseCycleMocks').default; const ExtendedAct = require('./utils/ExtendedAct').default; jest.setTimeout(90 * 1000); diff --git a/workflow_tests/mocks/authorChecklistMocks.ts b/workflow_tests/mocks/authorChecklistMocks.ts index 3a7f49783111..50e90ddae799 100644 --- a/workflow_tests/mocks/authorChecklistMocks.ts +++ b/workflow_tests/mocks/authorChecklistMocks.ts @@ -1,10 +1,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import type {StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; import {createMockStep} from '../utils/utils'; // checklist const AUTHORCHECKLIST__CHECKLIST__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'CHECKLIST'); -const AUTHORCHECKLIST__CHECKLIST__AUTHORCHECKLIST_JS__STEP_MOCK = createMockStep('authorChecklist.js', 'Running authorChecklist.js', 'CHECKLIST', ['GITHUB_TOKEN'], []); -const AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS = [AUTHORCHECKLIST__CHECKLIST__CHECKOUT__STEP_MOCK, AUTHORCHECKLIST__CHECKLIST__AUTHORCHECKLIST_JS__STEP_MOCK]; +const AUTHORCHECKLIST__CHECKLIST__AUTHORCHECKLIST_JS__STEP_MOCK = createMockStep('authorChecklist.ts', 'Running authorChecklist.ts', 'CHECKLIST', ['GITHUB_TOKEN'], []); +const AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS = [ + AUTHORCHECKLIST__CHECKLIST__CHECKOUT__STEP_MOCK, + AUTHORCHECKLIST__CHECKLIST__AUTHORCHECKLIST_JS__STEP_MOCK, +] as const satisfies StepIdentifier[]; export default { AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, diff --git a/workflow_tests/mocks/finishReleaseCycleMocks.ts b/workflow_tests/mocks/finishReleaseCycleMocks.ts index 86493fb077c9..50382f8470d5 100644 --- a/workflow_tests/mocks/finishReleaseCycleMocks.ts +++ b/workflow_tests/mocks/finishReleaseCycleMocks.ts @@ -166,7 +166,7 @@ const FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS = [ FINISHRELEASECYCLE__UPDATESTAGING__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, ]; -export { +export default { FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_BLOCKERS__STEP_MOCKS, FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, diff --git a/workflow_tests/platformDeploy.test.ts b/workflow_tests/platformDeploy.test.ts index 57e4bcf1d26d..82903b3bbe14 100644 --- a/workflow_tests/platformDeploy.test.ts +++ b/workflow_tests/platformDeploy.test.ts @@ -119,7 +119,7 @@ describe('test workflow platformDeploy', () => { mockJobs: testMockJobs, }); - assertions.assertVerifyActorJobExecuted(result, 'Dummy Author'); + assertions.assertVerifyActorJobExecuted(result); assertions.assertDeployChecklistJobExecuted(result, true); assertions.assertAndroidJobExecuted(result, true, false, true); assertions.assertDesktopJobExecuted(result, true, false); @@ -203,7 +203,7 @@ describe('test workflow platformDeploy', () => { mockJobs: testMockJobs, }); - assertions.assertVerifyActorJobExecuted(result, 'OSBotify'); + assertions.assertVerifyActorJobExecuted(result); assertions.assertDeployChecklistJobExecuted(result, true); assertions.assertAndroidJobExecuted(result, true, false, true); assertions.assertDesktopJobExecuted(result, true, false); @@ -287,7 +287,7 @@ describe('test workflow platformDeploy', () => { mockJobs: testMockJobs, }); - assertions.assertVerifyActorJobExecuted(result, 'Dummy Author'); + assertions.assertVerifyActorJobExecuted(result); assertions.assertDeployChecklistJobExecuted(result, true); assertions.assertAndroidJobExecuted(result, false); assertions.assertDesktopJobExecuted(result, false); diff --git a/workflow_tests/utils/preGenerateTest.ts b/workflow_tests/utils/preGenerateTest.ts index c5e54d9a11c0..25bdb8f00ae3 100644 --- a/workflow_tests/utils/preGenerateTest.ts +++ b/workflow_tests/utils/preGenerateTest.ts @@ -19,10 +19,14 @@ const mockFileTemplate = (mockSteps: string, exports: string) => `const utils = ${mockSteps} ${exports} `; -const assertionFileTemplate = (jobAssertions: string, exports: string) => `const utils = require('../utils/utils'); + +const assertionFileTemplate = (jobAssertions: string, exports: string) => `import type {Step} from '@kie/act-js'; +import * as utils from 'workflow_tests/utils/utils'; + ${jobAssertions} ${exports} `; + const testFileTemplate = (workflowName: string) => `const path = require('path'); const kieMockGithub = require('@kie/mock-github'); const utils = require('./utils/utils'); @@ -33,18 +37,7 @@ const ExtendedAct = require('./utils/ExtendedAct').default; jest.setTimeout(90 * 1000); let mockGithub; const FILES_TO_COPY_INTO_TEST_REPO = [ - { - src: path.resolve(__dirname, '..', '.github', 'actions'), - dest: '.github/actions', - }, - { - src: path.resolve(__dirname, '..', '.github', 'libs'), - dest: '.github/libs', - }, - { - src: path.resolve(__dirname, '..', '.github', 'scripts'), - dest: '.github/scripts', - }, + ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), { src: path.resolve(__dirname, '..', '.github', 'workflows', '${workflowName}.yml'), dest: '.github/workflows/${workflowName}.yml', @@ -54,6 +47,7 @@ const FILES_TO_COPY_INTO_TEST_REPO = [ describe('test workflow ${workflowName}', () => { const githubToken = 'dummy_github_token'; const actor = 'Dummy Actor'; + beforeEach(async () => { // create a local repository and copy required files mockGithub = new kieMockGithub.MockGithub({ @@ -88,7 +82,7 @@ describe('test workflow ${workflowName}', () => { }; const result = await act .runEvent('[EVENT]', { - workflowFile: path.join(repoPath, '.github', 'workflows'), + workflowFile: path.join(repoPath, '.github', 'workflows', '${workflowName}.yml'), mockSteps: testMockSteps, actor, }); @@ -131,7 +125,7 @@ const jobMocksTemplate = (jobMocksName: string, stepMocks: string[]): string => }; const jobAssertionTemplate = (jobAssertionName: string, stepAssertionsContent: string) => ` -const ${jobAssertionName} = (workflowResult, didExecute = true) => { +function ${jobAssertionName}(workflowResult: Step[], didExecute = true) { const steps = [\n${stepAssertionsContent}\n]; for (const expectedStep of steps) { @@ -144,15 +138,17 @@ const ${jobAssertionName} = (workflowResult, didExecute = true) => { };`; const mocksExportsTemplate = (jobMocks: string[]): string => { - const jobMocksString = jobMocks.map((jobMock) => ` ${jobMock}: ${jobMock}`).join(',\n'); + const jobMocksString = jobMocks.map((jobMock) => ` ${jobMock}`).join(',\n'); - return `module.exports = {\n${jobMocksString}\n};\n`; + return `\nmodule.exports = {\n${jobMocksString}\n};\n`; }; const assertionsExportsTemplate = (jobAssertions: string[]): string => { - const assertionsString = jobAssertions.map((assertion) => ` ${assertion}: ${assertion}`).join(',\n'); + const assertionsString = jobAssertions.join(',\n'); + // There are other pre-generated files using imports from here, so to keep the interface uniform it's better to just disable it + const eslintDisable = jobAssertions.length === 1 ? '// eslint-disable-next-line import/prefer-default-export\n' : ''; - return `module.exports = {\n${assertionsString}\n};\n`; + return `\n${eslintDisable}export default {\n${assertionsString}\n};\n`; }; const checkArguments = (args: string[]) => { @@ -226,10 +222,13 @@ const getMockFileContent = (workflowName: string, jobs: Record): string => { let content = ''; const jobAssertions: string[] = []; + Object.entries(jobs).forEach(([jobId, job]) => { let stepAssertionsContent = ''; job.steps.forEach((step) => { @@ -249,8 +250,10 @@ const getAssertionsFileContent = (jobs: Record): string => jobAssertions.push(jobAssertionName); content += jobAssertionTemplate(jobAssertionName, stepAssertionsContent); }); + return assertionFileTemplate(content, assertionsExportsTemplate(jobAssertions)); }; + const getTestFileContent = (workflowName: string): string => testFileTemplate(workflowName); const callArgs = process.argv.slice(2); @@ -269,7 +272,7 @@ checkIfTestFileExists(workflowTestsDirectory, workflowTestFileName); const workflowTestMocksFileName = `${workflowName}Mocks.js`; checkIfMocksFileExists(workflowTestMocksDirectory, workflowTestMocksFileName); -const workflowTestAssertionsFileName = `${workflowName}Assertions.js`; +const workflowTestAssertionsFileName = `${workflowName}Assertions.ts`; checkIfAssertionsFileExists(workflowTestAssertionsDirectory, workflowTestAssertionsFileName); const workflow = yaml.parse(fs.readFileSync(workflowFilePath, 'utf8')); diff --git a/workflow_tests/utils/utils.ts b/workflow_tests/utils/utils.ts index 143294b0745d..b70a88c24c7a 100644 --- a/workflow_tests/utils/utils.ts +++ b/workflow_tests/utils/utils.ts @@ -5,7 +5,7 @@ import path from 'path'; import yaml from 'yaml'; import type ExtendedAct from './ExtendedAct'; -type StepAssertionInputEntry = {key: string; value: string}; +type StepAssertionInputEntry = {key: string; value: string | boolean}; type StepAssertion = { name: string;