Skip to content

Commit

Permalink
Add tests for chooseDeployActions/skipDeploy/createNewVersion/updateS…
Browse files Browse the repository at this point in the history
…taging [WiP]

Added the tests checking for which steps get executed based on given set of conditions

See: #13604
  • Loading branch information
radoslawkrzemien committed Jun 30, 2023
1 parent 0467112 commit 50818e6
Show file tree
Hide file tree
Showing 4 changed files with 472 additions and 57 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/preDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ jobs:
needs: confirmPassingBuild
outputs:
MERGED_PR: ${{ steps.getMergedPullRequest.outputs.number }}
IS_AUTOMATED_PR: ${{ steps.isAutomatedPullRequest.outputs.IS_AUTOMATED_PR }}
SHOULD_DEPLOY: ${{ steps.shouldDeploy.outputs.SHOULD_DEPLOY }}
SHOULD_CP: ${{ steps.isStagingDeployLocked.outputs.IS_LOCKED && steps.hasCherryPickLabel.outputs.HAS_CP_LABEL }}
IS_AUTOMATED_PR: ${{ fromJSON(steps.isAutomatedPullRequest.outputs.IS_AUTOMATED_PR) }}
SHOULD_DEPLOY: ${{ fromJSON(steps.shouldDeploy.outputs.SHOULD_DEPLOY) }}
SHOULD_CP: ${{ fromJSON(steps.isStagingDeployLocked.outputs.IS_LOCKED) && fromJSON(steps.hasCherryPickLabel.outputs.HAS_CP_LABEL) }}

steps:
- name: Get merged pull request
Expand Down Expand Up @@ -85,8 +85,11 @@ jobs:
needs: chooseDeployActions
if: ${{ fromJSON(needs.chooseDeployActions.outputs.SHOULD_DEPLOY) }}
secrets: inherit
outputs:
NEW_VERSION: ${{ steps.createNewVersion.outputs.NEW_VERSION }}
steps:
- name: Create new version
id: createNewVersion
uses: Expensify/App/.github/workflows/createNewVersion.yml@main

updateStaging:
Expand Down
89 changes: 60 additions & 29 deletions workflow_tests/assertions/preDeployAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) =>
}
};

const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true) => {
const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true, shouldCp = false) => {
const steps = [
utils.getStepAssertion(
'Run turnstyle',
Expand All @@ -370,19 +370,38 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true) => {
'Running turnstyle',
[{key: 'poll-interval-seconds', value: '10'}, {key: 'GITHUB_TOKEN', value: '***'}],
),
utils.getStepAssertion(
'Cherry-pick PR to staging',
true,
null,
'UPDATE_STAGING',
'Cherry picking',
),
];
if (shouldCp) {
steps.push(
utils.getStepAssertion(
'Cherry-pick PR to staging',
true,
null,
'UPDATE_STAGING',
'Cherry picking',
[{key: 'GITHUB_TOKEN', value: '***'}, {key: 'WORKFLOW', value: 'cherryPick.yml'}, {key: 'INPUTS', value: '{ PULL_REQUEST_NUMBER: 123, NEW_VERSION: 1.2.3 }'}],
),
);
} else {
steps.push(
utils.getStepAssertion(
'Update staging branch from main',
true,
null,
'UPDATE_STAGING',
'Updating staging branch',
[{key: 'TARGET_BRANCH', value: 'staging'}, {key: 'OS_BOTIFY_TOKEN', value: '***'}, {key: 'GPG_PASSPHRASE', value: '***'}],
),
);
}
steps.push(
utils.getStepAssertion(
'Checkout staging',
true,
null,
'UPDATE_STAGING',
'Checking out staging',
[{key: 'ref', value: 'staging'}, {key: 'fetch-depth', value: '0'}],
),
utils.getStepAssertion(
'Tag staging',
Expand All @@ -397,36 +416,48 @@ const assertUpdateStagingJobExecuted = (workflowResult, didExecute = true) => {
null,
'UPDATE_STAGING',
'Updating StagingDeployCash',
[{key: 'GITHUB_TOKEN', value: '***'}, {key: 'NPM_VERSION', value: '1.2.3'}],
),
utils.getStepAssertion(
'Find open StagingDeployCash',
true,
null,
'UPDATE_STAGING',
'Finding open StagingDeployCash',
),
utils.getStepAssertion(
'Comment in StagingDeployCash to alert Applause that a new pull request has been cherry-picked',
true,
null,
'UPDATE_STAGING',
'Commenting in StagingDeployCash',
),
utils.getStepAssertion(
'Wait for staging deploys to finish',
true,
null,
'UPDATE_STAGING',
'Waiting for staging deploy to finish',
),
utils.getStepAssertion(
'Comment in StagingDeployCash to alert Applause that cherry-picked pull request has been deployed.',
true,
null,
'UPDATE_STAGING',
'Commenting in StagingDeployCash',
[{key: 'GITHUB_TOKEN', value: '***'}],
),
];
);
if (shouldCp) {
steps.push(
utils.getStepAssertion(
'Comment in StagingDeployCash to alert Applause that a new pull request has been cherry-picked',
true,
null,
'UPDATE_STAGING',
'Commenting in StagingDeployCash',
null,
[{key: 'GITHUB_TOKEN', value: '***'}],
),
utils.getStepAssertion(
'Wait for staging deploys to finish',
true,
null,
'UPDATE_STAGING',
'Waiting for staging deploy to finish',
[{key: 'GITHUB_TOKEN', value: '***'}, {key: 'TAG', value: '1.2.3'}],
),
utils.getStepAssertion(
'Comment in StagingDeployCash to alert Applause that cherry-picked pull request has been deployed.',
true,
null,
'UPDATE_STAGING',
'Commenting in StagingDeployCash',
null,
[{key: 'GITHUB_TOKEN', value: '***'}],
),
);
}
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
Expand Down
67 changes: 58 additions & 9 deletions workflow_tests/mocks/preDeployMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,59 @@ const CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS = [
];

// choose_deploy_actions
const GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY = utils.getMockStep(
const GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY__CP_LABEL = utils.getMockStep(
'Get merged pull request',
'Getting merged pull request',
'CHOOSE_DEPLOY_ACTIONS',
['github_token'],
null,
{number: '123', labels: '[\'CP Staging\']'},
);
const CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP = utils.getMockStep(
const GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY = utils.getMockStep(
'Get merged pull request',
'Getting merged pull request',
'CHOOSE_DEPLOY_ACTIONS',
['github_token'],
null,
{number: '123', labels: '[]'},
);
const CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__LOCKED = utils.getMockStep(
'Check if StagingDeployCash is locked',
'Checking StagingDeployCash',
'CHOOSE_DEPLOY_ACTIONS',
['GITHUB_TOKEN'],
null,
{IS_LOCKED: 'true'},
{IS_LOCKED: true},
);
const CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS = [
const CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__UNLOCKED = utils.getMockStep(
'Check if StagingDeployCash is locked',
'Checking StagingDeployCash',
'CHOOSE_DEPLOY_ACTIONS',
['GITHUB_TOKEN'],
null,
{IS_LOCKED: false},
);
const CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED = [
GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY,
CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__LOCKED,

// steps 3-5 run normally
];
const CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_LOCKED = [
GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY__CP_LABEL,
CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__LOCKED,

// steps 3-5 run normally
];
const CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED = [
GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY,
CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP,
CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__UNLOCKED,

// steps 3-5 run normally
];
const CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_UNLOCKED = [
GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY__CP_LABEL,
CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__UNLOCKED,

// steps 3-5 run normally
];
Expand All @@ -73,6 +107,9 @@ const CREATE_NEW_VERSION_MOCK_STEP = utils.getMockStep(
'Create new version',
'Creating new version',
'CREATE_NEW_VERSION',
null,
null,
{NEW_VERSION: '1.2.3'},
);
const CREATE_NEW_VERSION_JOB_MOCK_STEPS = [
CREATE_NEW_VERSION_MOCK_STEP,
Expand All @@ -90,16 +127,19 @@ const UPDATE_STAGING_BRANCH_MOCK_STEP = utils.getMockStep(
'Update staging branch from main',
'Updating staging branch',
'UPDATE_STAGING',
['TARGET_BRANCH', 'OS_BOTIFY_TOKEN', 'GPG_PASSPHRASE'],
);
const CHERRYPICK_PR_MOCK_STEP = utils.getMockStep(
'Cherry-pick PR to staging',
'Cherry picking',
'UPDATE_STAGING',
['GITHUB_TOKEN', 'WORKFLOW', 'INPUTS'],
);
const CHECKOUT_STAGING_MOCK_STEP = utils.getMockStep(
'Checkout staging',
'Checking out staging',
'UPDATE_STAGING',
['ref', 'fetch-depth'],
);
const TAG_STAGING_MOCK_STEP = utils.getMockStep(
'Tag staging',
Expand All @@ -110,29 +150,35 @@ const UPDATE_STAGINGDEPLOYCASH_MOCK_STEP = utils.getMockStep(
'Update StagingDeployCash',
'Updating StagingDeployCash',
'UPDATE_STAGING',
['GITHUB_TOKEN', 'NPM_VERSION'],
);
const FIND_OPEN_STAGINGDEPLOYCASH_MOCK_STEP = utils.getMockStep(
'Find open StagingDeployCash',
'Finding open StagingDeployCash',
'UPDATE_STAGING',
null,
null,
['GITHUB_TOKEN'],
{STAGING_DEPLOY_CASH: '1234'},
);
const COMMENT_TO_ALERT_APPLAUSE_CHERRYPICK_MOCK_STEP = utils.getMockStep(
'Comment in StagingDeployCash to alert Applause that a new pull request has been cherry-picked',
'Commenting in StagingDeployCash',
'UPDATE_STAGING',
null,
['GITHUB_TOKEN'],
);
const WAIT_FOR_STAGING_DEPLOYS_MOCK_STEP = utils.getMockStep(
'Wait for staging deploys to finish',
'Waiting for staging deploy to finish',
'UPDATE_STAGING',
['GITHUB_TOKEN', 'TAG'],
);
const COMMENT_TO_ALERT_APPLAUSE_DEPLOY_MOCK_STEP = utils.getMockStep(
'Comment in StagingDeployCash to alert Applause that cherry-picked pull request has been deployed.',
'Commenting in StagingDeployCash',
'UPDATE_STAGING',
null,
['GITHUB_TOKEN'],
);
const ANNOUNCE_FAILED_WORKFLOW_IN_SLACK_MOCK_STEP = utils.getMockStep(
'Announce failed workflow in Slack',
Expand Down Expand Up @@ -168,7 +214,7 @@ const CHECK_TEAM_MEMBERSHIP_MOCK_STEP__TRUE = utils.getMockStep(
'IS_EXPENSIFY_EMPLOYEE',
['GITHUB_TOKEN', 'username', 'team'],
null,
{isTeamMember: 'true'},
{isTeamMember: true},
);
const IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__TRUE = [
GET_MERGED_PULL_REQUEST_MOCK_STEP__IS_EXPENSIFY_EMPLOYEE,
Expand All @@ -180,7 +226,7 @@ const CHECK_TEAM_MEMBERSHIP_MOCK_STEP__FALSE = utils.getMockStep(
'IS_EXPENSIFY_EMPLOYEE',
['GITHUB_TOKEN', 'username', 'team'],
null,
{isTeamMember: 'false'},
{isTeamMember: false},
);
const IS_EXPENSIFY_EMPLOYEE_JOB_MOCK_STEPS__FALSE = [
GET_MERGED_PULL_REQUEST_MOCK_STEP__IS_EXPENSIFY_EMPLOYEE,
Expand Down Expand Up @@ -411,7 +457,10 @@ module.exports = {
LINT_JOB_MOCK_STEPS,
TEST_JOB_MOCK_STEPS,
CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS,
CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS,
CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED,
CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_LOCKED,
CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED,
CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__CP_LABEL__STAGING_UNLOCKED,
SKIP_DEPLOY_JOB_MOCK_STEPS,
CREATE_NEW_VERSION_JOB_MOCK_STEPS,
UPDATE_STAGING_JOB_MOCK_STEPS,
Expand Down
Loading

0 comments on commit 50818e6

Please sign in to comment.