From d51407dd953b17214c313311d42cf92474264ed1 Mon Sep 17 00:00:00 2001 From: Radoslaw Krzemien Date: Tue, 28 Feb 2023 13:39:30 +0100 Subject: [PATCH] Add test for Slack announcement [WiP] Added the test checking if the failed workflow gets announced on Slack See: https://github.com/Expensify/App/issues/13604 --- .github/workflows/preDeploy.yml | 2 +- .../assertions/preDeployAssertions.js | 19 + workflow_tests/mocks/preDeployMocks.js | 3 +- workflow_tests/preDeploy.test.js | 618 ++++++++++-------- 4 files changed, 371 insertions(+), 271 deletions(-) diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index 5c1257b85f41..78df8370a3ef 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -173,7 +173,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - name: Announce failed workflow in Slack - if: ${{ failure() }} + if: failure() uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main with: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} diff --git a/workflow_tests/assertions/preDeployAssertions.js b/workflow_tests/assertions/preDeployAssertions.js index 4ba684d0982c..a37e9cebc397 100644 --- a/workflow_tests/assertions/preDeployAssertions.js +++ b/workflow_tests/assertions/preDeployAssertions.js @@ -465,6 +465,24 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true, shoul } }; +const assertUpdateStagingJobFailed = (workflowResult, didFail = false) => { + const steps = [ + utils.getStepAssertion( + 'Announce failed workflow in Slack', + true, + null, + 'UPDATE_STAGING', + 'Announcing failed workflow in Slack', + [{key: 'SLACK_WEBHOOK', value: '***'}], + ), + ]; + if (didFail) { + expect(workflowResult).toEqual(expect.arrayContaining(steps)); + } else { + expect(workflowResult).not.toEqual(steps); + } +}; + module.exports = { assertLintJobExecuted, assertTestJobExecuted, @@ -475,4 +493,5 @@ module.exports = { assertSkipDeployJobExecuted, assertCreateNewVersionJobExecuted, assertUpdateStagingJobExecuted, + assertUpdateStagingJobFailed, }; diff --git a/workflow_tests/mocks/preDeployMocks.js b/workflow_tests/mocks/preDeployMocks.js index 1c42607523cf..ed8691defc2f 100644 --- a/workflow_tests/mocks/preDeployMocks.js +++ b/workflow_tests/mocks/preDeployMocks.js @@ -182,8 +182,9 @@ const COMMENT_TO_ALERT_APPLAUSE_DEPLOY_MOCK_STEP = utils.getMockStep( ); const ANNOUNCE_FAILED_WORKFLOW_IN_SLACK_MOCK_STEP = utils.getMockStep( 'Announce failed workflow in Slack', - 'Announcing failed workflow in slack', + 'Announcing failed workflow in Slack', 'UPDATE_STAGING', + ['SLACK_WEBHOOK'], ); const UPDATE_STAGING_JOB_MOCK_STEPS = [ RUN_TURNSTYLE_MOCK_STEP, diff --git a/workflow_tests/preDeploy.test.js b/workflow_tests/preDeploy.test.js index 760e738bc1e3..b9f7dd0c0117 100644 --- a/workflow_tests/preDeploy.test.js +++ b/workflow_tests/preDeploy.test.js @@ -564,281 +564,360 @@ describe('test workflow preDeploy', () => { }); describe('choose deploy actions', () => { - test('no CP label, staging locked, not automated PR - deploy skipped and comment left', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - {OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'Dummy Tester', SLACK_WEBHOOK: 'dummy_slack_webhook'}, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false, false); - }, 60000); + describe('no CP label', () => { + describe('staging locked', () => { + test('not automated PR - deploy skipped and comment left', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + {OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'Dummy Tester', SLACK_WEBHOOK: 'dummy_slack_webhook'}, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result); + assertions.assertCreateNewVersionJobExecuted(result, false); + assertions.assertUpdateStagingJobExecuted(result, false, false); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); - test('no CP label, staging locked, automated PR - deploy skipped, but no comment left', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - {OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'OSBotify', SLACK_WEBHOOK: 'dummy_slack_webhook'}, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false, false); - }, 60000); + test('automated PR - deploy skipped, but no comment left', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + {OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'OSBotify', SLACK_WEBHOOK: 'dummy_slack_webhook'}, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result, false); + assertions.assertUpdateStagingJobExecuted(result, false, false); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); + }); - test('no CP label, staging not locked, not automated PR - proceed with deploy', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - { - OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'Dummy Tester', SLACK_WEBHOOK: 'dummy_slack_webhook', LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result, true, false); - }, 60000); + describe('staging not locked', () => { + test('not automated PR - proceed with deploy', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + { + OS_BOTIFY_TOKEN: 'dummy_token', + GITHUB_ACTOR: 'Dummy Tester', + SLACK_WEBHOOK: 'dummy_slack_webhook', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + }, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result); + assertions.assertUpdateStagingJobExecuted(result, true, false); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); - test('no CP label, staging not locked, automated PR - deploy skipped, but no comment left', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - {OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'OSBotify', SLACK_WEBHOOK: 'dummy_slack_webhook'}, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false, false); - }, 60000); + test('automated PR - deploy skipped, but no comment left', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + { + OS_BOTIFY_TOKEN: 'dummy_token', + GITHUB_ACTOR: 'OSBotify', + SLACK_WEBHOOK: 'dummy_slack_webhook', + }, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result, false); + assertions.assertUpdateStagingJobExecuted(result, false, false); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); + }); + }); - test('CP label, staging locked, not automated PR - proceed with deploy', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - { - OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'Dummy Tester', SLACK_WEBHOOK: 'dummy_slack_webhook', LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_LOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result, true, true); - }, 60000); + describe('CP label', () => { + describe('staging locked', () => { + test('not automated PR - proceed with deploy', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + { + OS_BOTIFY_TOKEN: 'dummy_token', + GITHUB_ACTOR: 'Dummy Tester', + SLACK_WEBHOOK: 'dummy_slack_webhook', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + }, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_LOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result); + assertions.assertUpdateStagingJobExecuted(result, true, true); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); - test('CP label, staging locked, automated PR - proceed with deploy', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - { - OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'OSBotify', SLACK_WEBHOOK: 'dummy_slack_webhook', LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_LOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result, true, true); - }, 60000); + test('automated PR - proceed with deploy', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + { + OS_BOTIFY_TOKEN: 'dummy_token', + GITHUB_ACTOR: 'OSBotify', + SLACK_WEBHOOK: 'dummy_slack_webhook', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + }, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_LOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result); + assertions.assertUpdateStagingJobExecuted(result, true, true); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); + }); - test('CP label, staging not locked, not automated PR - proceed with deploy', async () => { - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new kieActJs.Act(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {head: {ref: 'main'}}, - { - OS_BOTIFY_TOKEN: 'dummy_token', GITHUB_ACTOR: 'Dummy Tester', SLACK_WEBHOOK: 'dummy_slack_webhook', LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps = { - lint: mocks.LINT_JOB_MOCK_STEPS, - test: mocks.TEST_JOB_MOCK_STEPS, - confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_UNLOCKED, - skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, - createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, - newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, - 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, - }; - const result = await act - .runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertIsExpensifyEmployeeJobExecuted(result); - assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result, true, false); - }, 60000); + describe('staging not locked', () => { + test('not automated PR - proceed with deploy', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + { + OS_BOTIFY_TOKEN: 'dummy_token', + GITHUB_ACTOR: 'Dummy Tester', + SLACK_WEBHOOK: 'dummy_slack_webhook', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + }, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_UNLOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result); + assertions.assertUpdateStagingJobExecuted(result, true, false); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); + + test('automated PR - proceed with deploy', async () => { + const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); + let act = new kieActJs.Act(repoPath, workflowPath); + act = utils.setUpActParams( + act, + 'push', + {head: {ref: 'main'}}, + { + OS_BOTIFY_TOKEN: 'dummy_token', + GITHUB_ACTOR: 'OSBotify', + SLACK_WEBHOOK: 'dummy_slack_webhook', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + }, + 'dummy_github_token', + ); + const testMockSteps = { + lint: mocks.LINT_JOB_MOCK_STEPS, + test: mocks.TEST_JOB_MOCK_STEPS, + confirmPassingBuild: mocks.CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, + chooseDeployActions: mocks.CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_UNLOCKED, + skipDeploy: mocks.SKIP_DEPLOY_JOB_MOCK_STEPS, + createNewVersion: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, + updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, + isExpensifyEmployee: mocks.IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE, + newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, + 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, + }; + const result = await act + .runEvent('push', { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + }); + assertions.assertLintJobExecuted(result); + assertions.assertTestJobExecuted(result); + assertions.assertIsExpensifyEmployeeJobExecuted(result); + assertions.assertE2ETestsJobExecuted(result, false); // Act does not support ubuntu-20.04-64core runner and omits the job + assertions.assertChooseDeployActionsJobExecuted(result); + assertions.assertSkipDeployJobExecuted(result, false); + assertions.assertCreateNewVersionJobExecuted(result); + assertions.assertUpdateStagingJobExecuted(result, true, false); + assertions.assertUpdateStagingJobFailed(result, false); + }, 60000); + }); + }); - test('CP label, staging not locked, automated PR - proceed with deploy', async () => { + test('one of updateStaging steps failed - failure announced in Slack', async () => { const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); let act = new kieActJs.Act(repoPath, workflowPath); @@ -863,6 +942,7 @@ describe('test workflow preDeploy', () => { newContributorWelcomeMessage: mocks.NEW_CONTRIBUTOR_WELCOME_MESSAGE_JOB_MOCK_STEPS__MANY_PRS, 'e2e-tests': mocks.E2E_TESTS_JOB_MOCK_STEPS, }; + testMockSteps.updateStaging[3].mockWith = 'exit 1'; const result = await act .runEvent('push', { workflowFile: path.join(repoPath, '.github', 'workflows'), @@ -875,7 +955,7 @@ describe('test workflow preDeploy', () => { assertions.assertChooseDeployActionsJobExecuted(result); assertions.assertSkipDeployJobExecuted(result, false); assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result, true, false); + assertions.assertUpdateStagingJobFailed(result, true); }, 60000); }); });