Skip to content

Commit

Permalink
Merge pull request #30975 from radoslawkrzemien/@radoslawkrzemien/136…
Browse files Browse the repository at this point in the history
…04-run-workflow-tests-on-pr

[13604] Run GHA workflow tests on each PR
  • Loading branch information
AndrewGable authored Nov 27, 2023
2 parents 60aa8a9 + 1dab7e7 commit 74f552c
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 688 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/authorChecklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
runs-on: ubuntu-latest
if: github.actor != 'OSBotify' && github.actor != 'imgbot[bot]'
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: authorChecklist.js
uses: ./.github/actions/javascript/authorChecklist
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
with:
ref: staging
token: ${{ secrets.OS_BOTIFY_TOKEN }}

- uses: ./.github/actions/composite/setupGitForOSBotifyApp

- name: Setup git for OSBotify
uses: ./.github/actions/composite/setupGitForOSBotifyApp
id: setupGitForOSBotify
with:
GPG_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
Expand All @@ -38,7 +39,8 @@ jobs:
ref: production
token: ${{ secrets.OS_BOTIFY_TOKEN }}

- uses: ./.github/actions/composite/setupGitForOSBotifyApp
- name: Setup git for OSBotify
uses: ./.github/actions/composite/setupGitForOSBotifyApp
id: setupGitForOSBotify
with:
GPG_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/finishReleaseCycle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
ref: main
token: ${{ secrets.OS_BOTIFY_TOKEN }}

- uses: ./.github/actions/composite/setupGitForOSBotifyApp
- name: Setup git for OSBotify
uses: ./.github/actions/composite/setupGitForOSBotifyApp
id: setupGitForOSBotify
with:
GPG_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
Expand Down Expand Up @@ -82,7 +83,7 @@ jobs:
ref: staging
token: ${{ secrets.OS_BOTIFY_TOKEN }}

- name: Setup Git for OSBotify
- name: Setup git for OSBotify
id: setupGitForOSBotify
uses: ./.github/actions/composite/setupGitForOSBotifyApp
with:
Expand Down Expand Up @@ -124,7 +125,7 @@ jobs:
ref: main
token: ${{ secrets.OS_BOTIFY_TOKEN }}

- name: Setup Git for OSBotify
- name: Setup git for OSBotify
uses: ./.github/actions/composite/setupGitForOSBotifyApp
with:
GPG_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/testGithubActionsWorkflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test GitHub Actions workflows

on:
workflow_dispatch:
workflow_call:
pull_request:
types: [opened, reopened, edited, synchronize]
branches-ignore: [staging, production]
paths: ['.github/**']

jobs:
testGHWorkflows:
if: ${{ github.actor != 'OSBotify' && github.actor != 'imgbot[bot]' || github.event_name == 'workflow_call' }}
runs-on: ubuntu-latest
env:
CI: true
name: test GitHub Workflows
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: Expensify/App/.github/actions/composite/setupNode@main

- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Install Act
run: brew install act

- name: Set ACT_BINARY
run: echo "ACT_BINARY=$(which act)" >> "$GITHUB_ENV"

- name: Run tests
run: npm run workflow-test
5 changes: 4 additions & 1 deletion workflow_tests/assertions/authorChecklistAssertions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const utils = require('../utils/utils');

const assertChecklistJobExecuted = (workflowResult, didExecute = true) => {
const steps = [utils.createStepAssertion('authorChecklist.js', true, null, 'CHECKLIST', 'Running authorChecklist.js', [{key: 'GITHUB_TOKEN', value: '***'}], [])];
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) {
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/assertions/cherryPickAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
'CHERRYPICK',
'Creating Pull Request to manually finish CP',
[],
[{key: 'GITHUB_TOKEN', value: '***'}],
[{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}],
),
];

Expand Down
16 changes: 14 additions & 2 deletions workflow_tests/assertions/createNewVersionAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,27 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD'
],
[],
),
utils.createStepAssertion('Setup git for OSBotify', true, null, 'CREATENEWVERSION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []),
utils.createStepAssertion(
'Setup git for OSBotify',
true,
null,
'CREATENEWVERSION',
'Setup git for OSBotify',
[
{key: 'GPG_PASSPHRASE', value: '***'},
{key: 'OS_BOTIFY_APP_ID', value: '***'},
{key: 'OS_BOTIFY_PRIVATE_KEY', value: '***'},
],
[],
),
utils.createStepAssertion(
'Generate version',
true,
null,
'CREATENEWVERSION',
'Generate version',
[
{key: 'GITHUB_TOKEN', value: '***'},
{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'},
{key: 'SEMVER_LEVEL', value: semverLevel},
],
[],
Expand Down
16 changes: 12 additions & 4 deletions workflow_tests/assertions/deployAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => {
{key: 'ref', value: 'staging'},
{key: 'token', value: '***'},
]),
utils.createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_STAGING', 'Setting up git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}]),
utils.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'),
];
Expand All @@ -26,11 +30,15 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) =>
{key: 'ref', value: 'production'},
{key: 'token', value: '***'},
]),
utils.createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_PRODUCTION', 'Setting up git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}]),
utils.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', [
{key: 'TAG', value: '1.2.3'},
{key: 'GITHUB_TOKEN', value: '***'},
{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]'}]),
Expand All @@ -44,7 +52,7 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) =>
{key: 'tag_name', value: '1.2.3'},
{key: 'body', value: 'Release body'},
],
[{key: 'GITHUB_TOKEN', value: '***'}],
[{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}],
),
];

Expand Down
64 changes: 26 additions & 38 deletions workflow_tests/assertions/deployBlockerAssertions.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
const utils = require('../utils/utils');

const assertDeployBlockerJobExecuted = (workflowResult, issueTitle, issueNumber, didExecute = true, isSuccessful = true) => {
const assertUpdateChecklistJobExecuted = (workflowResult, didExecute = true, isSuccessful = true) => {
const steps = [utils.createStepAssertion('updateChecklist', true, null, 'UPDATECHECKLIST', 'Run updateChecklist')];

steps.forEach((expectedStep) => {
if (didExecute) {
if (isSuccessful) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
}
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
};

const assertDeployBlockerJobExecuted = (workflowResult, didExecute = true, isSuccessful = true, failsAt = -1) => {
const steps = [
utils.createStepAssertion('Checkout', true, null, 'DEPLOYBLOCKER', 'Checkout', [{key: 'token', value: '***'}], []),
utils.createStepAssertion(
'Get URL, title, & number of new deploy blocker (issue)',
true,
null,
'DEPLOYBLOCKER',
'Get URL, title and number of new deploy blocker - issue',
[],
[{key: 'TITLE', value: issueTitle}],
),
utils.createStepAssertion(
'Update StagingDeployCash with new deploy blocker',
true,
null,
'DEPLOYBLOCKER',
'Update StagingDeployCash with new deploy blocker',
[{key: 'GITHUB_TOKEN', value: '***'}],
[],
),
utils.createStepAssertion('Checkout', true, null, 'DEPLOYBLOCKER', 'Checkout'),
utils.createStepAssertion(
'Give the issue/PR the Hourly, Engineering labels',
true,
null,
'DEPLOYBLOCKER',
'Give the issue/PR the Hourly, Engineering labels',
[
{key: 'add-labels', value: 'Hourly, Engineering'},
{key: 'remove-labels', value: 'Daily, Weekly, Monthly'},
],
[],
),
utils.createStepAssertion(
'Comment on deferred PR',
true,
null,
'DEPLOYBLOCKER',
'Comment on deferred PR',
[
{key: 'github_token', value: '***'},
{key: 'number', value: issueNumber},
],
[],
[{key: 'GITHUB_TOKEN', value: '***'}],
),
utils.createStepAssertion('Comment on deploy blocker', true, null, 'DEPLOYBLOCKER', 'Comment on deploy blocker', [], [{key: 'GITHUB_TOKEN', value: '***'}]),
];

steps.forEach((expectedStep) => {
steps.forEach((expectedStep, i) => {
if (didExecute) {
if (isSuccessful) {
if (failsAt === -1 || i < failsAt) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else if (i === failsAt) {
steps[i].status = 1;
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
Expand Down Expand Up @@ -94,5 +81,6 @@ const assertDeployBlockerJobExecuted = (workflowResult, issueTitle, issueNumber,
};

module.exports = {
assertUpdateChecklistJobExecuted,
assertDeployBlockerJobExecuted,
};
23 changes: 17 additions & 6 deletions workflow_tests/assertions/finishReleaseCycleAssertions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const utils = require('../utils/utils');

const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute = true, isTeamMember = true, hasBlockers = false, isSuccessful = true) => {
const steps = [utils.createStepAssertion('Validate actor is deployer', true, null, 'VALIDATE', 'Validating if actor is deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])];
const steps = [
utils.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', [
{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'}]),
];
if (isTeamMember) {
steps.push(
utils.createStepAssertion(
Expand All @@ -11,7 +22,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute
'VALIDATE',
'Checking for deploy blockers',
[
{key: 'GITHUB_TOKEN', value: '***'},
{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'},
{key: 'ISSUE_NUMBER', value: issueNumber},
],
[],
Expand All @@ -36,7 +47,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute
'VALIDATE',
'Reopening issue - not a team member',
[
{key: 'GITHUB_TOKEN', value: '***'},
{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'},
{key: 'ISSUE_NUMBER', value: issueNumber},
{key: 'COMMENT', value: 'Sorry, only members of @Expensify/Mobile-Deployers can close deploy checklists.\nReopening!'},
],
Expand All @@ -60,7 +71,7 @@ const assertValidateJobExecuted = (workflowResult, issueNumber = '', didExecute
'VALIDATE',
'Reopening issue - blockers',
[
{key: 'GITHUB_TOKEN', value: '***'},
{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'},
{key: 'ISSUE_NUMBER', value: issueNumber},
],
[],
Expand Down Expand Up @@ -102,7 +113,7 @@ 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('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', [], []),
];

Expand Down Expand Up @@ -153,7 +164,7 @@ 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('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', [], []),
];

Expand Down
3 changes: 2 additions & 1 deletion workflow_tests/assertions/lintAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const assertLintJobExecuted = (workflowResult, didExecute = true) => {
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('Lint shell scripts with ShellCheck', true, null, 'LINT', 'Lint shell scripts with ShellCheck', [], []),
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) => {
Expand Down
22 changes: 12 additions & 10 deletions workflow_tests/assertions/platformDeployAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ const assertVerifyActorJobExecuted = (workflowResult, username, didExecute = tru
};

const assertDeployChecklistJobExecuted = (workflowResult, didExecute = true) => {
const steps = [
utils.createStepAssertion('Checkout', true, null, 'DEPLOY_CHECKLIST', 'Checkout'),
utils.createStepAssertion('Setup Node', true, null, 'DEPLOY_CHECKLIST', 'Setup Node'),
utils.createStepAssertion('Set version', true, null, 'DEPLOY_CHECKLIST', 'Set version'),
utils.createStepAssertion('Create or update staging deploy', true, null, 'DEPLOY_CHECKLIST', 'Create or update staging deploy', [
{key: 'GITHUB_TOKEN', value: '***'},
{key: 'NPM_VERSION', value: '1.2.3'},
]),
];
const steps = [utils.createStepAssertion('deployChecklist', true, null, 'DEPLOY_CHECKLIST', 'Run deployChecklist')];

steps.forEach((expectedStep) => {
if (didExecute) {
Expand Down Expand Up @@ -63,6 +55,10 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio
);
if (!isProduction) {
steps.push(
utils.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: '***'},
]),
Expand Down Expand Up @@ -183,7 +179,13 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction =
]),
);
if (!isProduction) {
steps.push(utils.createStepAssertion('Upload iOS version to Browser Stack', true, null, 'IOS', 'Uploading version to Browser Stack', null, [{key: 'BROWSERSTACK', value: '***'}]));
steps.push(
utils.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: '***'}]),
);
} else {
steps.push(
utils.createStepAssertion('Set iOS version in ENV', true, null, 'IOS', 'Setting iOS version'),
Expand Down
Loading

0 comments on commit 74f552c

Please sign in to comment.