From 341aba5370e25ac3b02195732b89939844afe67d Mon Sep 17 00:00:00 2001 From: Github Date: Wed, 7 Aug 2024 17:42:52 -0600 Subject: [PATCH] Delete workflow tests --- .github/workflows/preDeploy.yml | 2 +- .../workflows/reassurePerformanceTests.yml | 2 +- .github/workflows/sendReassurePerfData.yml | 4 +- .../workflows/testGithubActionsWorkflows.yml | 42 - .github/workflows/typecheck.yml | 2 +- .gitignore | 4 - package.json | 2 - tsconfig.json | 2 +- workflow_tests/.eslintrc.js | 7 - workflow_tests/README.md | 422 --------- .../assertions/authorChecklistAssertions.ts | 19 - .../assertions/cherryPickAssertions.ts | 116 --- workflow_tests/assertions/claAssertions.ts | 73 -- .../assertions/createNewVersionAssertions.ts | 71 -- workflow_tests/assertions/deployAssertions.ts | 60 -- .../assertions/deployBlockerAssertions.ts | 84 -- .../assertions/failureNotifierAssertions.ts | 19 - .../finishReleaseCycleAssertions.ts | 194 ----- workflow_tests/assertions/lintAssertions.ts | 22 - .../assertions/lockDeploysAssertions.ts | 74 -- .../assertions/platformDeployAssertions.ts | 379 --------- .../assertions/preDeployAssertions.ts | 133 --- .../assertions/reviewerChecklistAssertions.ts | 16 - workflow_tests/assertions/testAssertions.ts | 41 - .../assertions/testBuildAssertions.ts | 407 --------- .../validateGithubActionsAssertions.ts | 21 - .../assertions/verifyPodfileAssertions.ts | 20 - .../verifySignedCommitsAssertions.ts | 17 - workflow_tests/authorChecklist.test.ts | 179 ---- workflow_tests/cherryPick.test.ts | 396 --------- workflow_tests/cla.test.ts | 213 ----- workflow_tests/createNewVersion.test.ts | 169 ---- workflow_tests/deploy.test.ts | 164 ---- workflow_tests/deployBlocker.test.ts | 161 ---- workflow_tests/failureNotifier.test.ts | 64 -- workflow_tests/finishReleaseCycle.test.ts | 240 ------ workflow_tests/jest.config.ts | 13 - workflow_tests/lint.test.ts | 155 ---- workflow_tests/lockDeploys.test.ts | 462 ---------- workflow_tests/mocks/authorChecklistMocks.ts | 15 - workflow_tests/mocks/cherryPickMocks.ts | 113 --- workflow_tests/mocks/claMocks.ts | 22 - workflow_tests/mocks/createNewVersionMocks.ts | 48 -- workflow_tests/mocks/deployBlockerMocks.ts | 41 - workflow_tests/mocks/deployMocks.ts | 50 -- workflow_tests/mocks/failureNotifierMocks.ts | 27 - .../mocks/finishReleaseCycleMocks.ts | 178 ---- workflow_tests/mocks/lintMocks.ts | 19 - workflow_tests/mocks/lockDeploysMocks.ts | 36 - workflow_tests/mocks/platformDeployMocks.ts | 286 ------- workflow_tests/mocks/preDeployMocks.ts | 94 -- .../mocks/reviewerChecklistMocks.ts | 10 - workflow_tests/mocks/testBuildMocks.ts | 261 ------ workflow_tests/mocks/testMocks.ts | 18 - .../mocks/validateGithubActionsMocks.ts | 18 - workflow_tests/mocks/verifyPodfileMocks.ts | 12 - .../mocks/verifySignedCommitsMocks.ts | 16 - workflow_tests/platformDeploy.test.ts | 303 ------- workflow_tests/preDeploy.test.ts | 800 ------------------ workflow_tests/reviewerChecklist.test.ts | 88 -- workflow_tests/scripts/runWorkflowTests.sh | 63 -- workflow_tests/test.test.ts | 176 ---- workflow_tests/testBuild.test.ts | 754 ----------------- workflow_tests/utils/ExtendedAct.ts | 63 -- workflow_tests/utils/JobMocker.ts | 106 --- workflow_tests/utils/preGenerateTest.ts | 297 ------- workflow_tests/utils/utils.ts | 225 ----- workflow_tests/validateGithubActions.test.ts | 90 -- workflow_tests/verifyPodfile.test.ts | 134 --- workflow_tests/verifySignedCommits.test.ts | 91 -- 70 files changed, 6 insertions(+), 8919 deletions(-) delete mode 100644 .github/workflows/testGithubActionsWorkflows.yml delete mode 100644 workflow_tests/.eslintrc.js delete mode 100644 workflow_tests/README.md delete mode 100644 workflow_tests/assertions/authorChecklistAssertions.ts delete mode 100644 workflow_tests/assertions/cherryPickAssertions.ts delete mode 100644 workflow_tests/assertions/claAssertions.ts delete mode 100644 workflow_tests/assertions/createNewVersionAssertions.ts delete mode 100644 workflow_tests/assertions/deployAssertions.ts delete mode 100644 workflow_tests/assertions/deployBlockerAssertions.ts delete mode 100644 workflow_tests/assertions/failureNotifierAssertions.ts delete mode 100644 workflow_tests/assertions/finishReleaseCycleAssertions.ts delete mode 100644 workflow_tests/assertions/lintAssertions.ts delete mode 100644 workflow_tests/assertions/lockDeploysAssertions.ts delete mode 100644 workflow_tests/assertions/platformDeployAssertions.ts delete mode 100644 workflow_tests/assertions/preDeployAssertions.ts delete mode 100644 workflow_tests/assertions/reviewerChecklistAssertions.ts delete mode 100644 workflow_tests/assertions/testAssertions.ts delete mode 100644 workflow_tests/assertions/testBuildAssertions.ts delete mode 100644 workflow_tests/assertions/validateGithubActionsAssertions.ts delete mode 100644 workflow_tests/assertions/verifyPodfileAssertions.ts delete mode 100644 workflow_tests/assertions/verifySignedCommitsAssertions.ts delete mode 100644 workflow_tests/authorChecklist.test.ts delete mode 100644 workflow_tests/cherryPick.test.ts delete mode 100644 workflow_tests/cla.test.ts delete mode 100644 workflow_tests/createNewVersion.test.ts delete mode 100644 workflow_tests/deploy.test.ts delete mode 100644 workflow_tests/deployBlocker.test.ts delete mode 100644 workflow_tests/failureNotifier.test.ts delete mode 100644 workflow_tests/finishReleaseCycle.test.ts delete mode 100644 workflow_tests/jest.config.ts delete mode 100644 workflow_tests/lint.test.ts delete mode 100644 workflow_tests/lockDeploys.test.ts delete mode 100644 workflow_tests/mocks/authorChecklistMocks.ts delete mode 100644 workflow_tests/mocks/cherryPickMocks.ts delete mode 100644 workflow_tests/mocks/claMocks.ts delete mode 100644 workflow_tests/mocks/createNewVersionMocks.ts delete mode 100644 workflow_tests/mocks/deployBlockerMocks.ts delete mode 100644 workflow_tests/mocks/deployMocks.ts delete mode 100644 workflow_tests/mocks/failureNotifierMocks.ts delete mode 100644 workflow_tests/mocks/finishReleaseCycleMocks.ts delete mode 100644 workflow_tests/mocks/lintMocks.ts delete mode 100644 workflow_tests/mocks/lockDeploysMocks.ts delete mode 100644 workflow_tests/mocks/platformDeployMocks.ts delete mode 100644 workflow_tests/mocks/preDeployMocks.ts delete mode 100644 workflow_tests/mocks/reviewerChecklistMocks.ts delete mode 100644 workflow_tests/mocks/testBuildMocks.ts delete mode 100644 workflow_tests/mocks/testMocks.ts delete mode 100644 workflow_tests/mocks/validateGithubActionsMocks.ts delete mode 100644 workflow_tests/mocks/verifyPodfileMocks.ts delete mode 100644 workflow_tests/mocks/verifySignedCommitsMocks.ts delete mode 100644 workflow_tests/platformDeploy.test.ts delete mode 100644 workflow_tests/preDeploy.test.ts delete mode 100644 workflow_tests/reviewerChecklist.test.ts delete mode 100755 workflow_tests/scripts/runWorkflowTests.sh delete mode 100644 workflow_tests/test.test.ts delete mode 100644 workflow_tests/testBuild.test.ts delete mode 100644 workflow_tests/utils/ExtendedAct.ts delete mode 100644 workflow_tests/utils/JobMocker.ts delete mode 100644 workflow_tests/utils/preGenerateTest.ts delete mode 100644 workflow_tests/utils/utils.ts delete mode 100644 workflow_tests/validateGithubActions.test.ts delete mode 100644 workflow_tests/verifyPodfile.test.ts delete mode 100644 workflow_tests/verifySignedCommits.test.ts diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index 5cfe5e213d2f..e5ccdfa53076 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -4,7 +4,7 @@ name: Process new code merged to main on: push: branches: [main] - paths-ignore: [docs/**, contributingGuides/**, jest/**, tests/**, workflow_tests/**] + paths-ignore: [docs/**, contributingGuides/**, jest/**, tests/**] jobs: typecheck: diff --git a/.github/workflows/reassurePerformanceTests.yml b/.github/workflows/reassurePerformanceTests.yml index a0489a52711b..d4a25a63952b 100644 --- a/.github/workflows/reassurePerformanceTests.yml +++ b/.github/workflows/reassurePerformanceTests.yml @@ -4,7 +4,7 @@ on: pull_request: types: [opened, synchronize] branches-ignore: [staging, production] - paths-ignore: [docs/**, .github/**, contributingGuides/**, tests/**, workflow_tests/**, '**.md', '**.sh'] + paths-ignore: [docs/**, .github/**, contributingGuides/**, tests/**, '**.md', '**.sh'] jobs: perf-tests: diff --git a/.github/workflows/sendReassurePerfData.yml b/.github/workflows/sendReassurePerfData.yml index 30a30918f4f6..42d946cece95 100644 --- a/.github/workflows/sendReassurePerfData.yml +++ b/.github/workflows/sendReassurePerfData.yml @@ -3,7 +3,7 @@ name: Send Reassure Performance Tests to Graphite on: push: branches: [main] - paths-ignore: [docs/**, contributingGuides/**, jest/**, workflow_tests/**] + paths-ignore: [docs/**, contributingGuides/**, jest/**] jobs: perf-tests: @@ -36,7 +36,7 @@ jobs: - name: Get and save graphite string id: saveGraphiteString uses: ./.github/actions/javascript/getGraphiteString - with: + with: PR_NUMBER: ${{ steps.getMergedPullRequest.outputs.number }} - name: Send graphite data diff --git a/.github/workflows/testGithubActionsWorkflows.yml b/.github/workflows/testGithubActionsWorkflows.yml deleted file mode 100644 index f65319f14be4..000000000000 --- a/.github/workflows/testGithubActionsWorkflows.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Test GitHub Actions workflows - -on: - workflow_dispatch: - workflow_call: - pull_request: - types: [opened, reopened, 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: Login to GitHub Container Regstry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: OSBotify - password: ${{ secrets.GITHUB_TOKEN }} - - - 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 diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml index 3bfc0ed28d1a..32c9e35315b3 100644 --- a/.github/workflows/typecheck.yml +++ b/.github/workflows/typecheck.yml @@ -34,7 +34,7 @@ jobs: # - git diff is used to see the files that were added on this branch # - gh pr view is used to list files touched by this PR. Git diff may give false positives if the branch isn't up-to-date with main # - wc counts the words in the result of the intersection - count_new_js=$(comm -1 -2 <(git diff --name-only --diff-filter=A origin/main HEAD -- 'src/*.js' '__mocks__/*.js' '.storybook/*.js' 'assets/*.js' 'config/*.js' 'desktop/*.js' 'jest/*.js' 'scripts/*.js' 'tests/*.js' 'workflow_tests/*.js' '.github/libs/*.js' '.github/scripts/*.js' ':!src/libs/SearchParser/*.js') <(gh pr view ${{ github.event.pull_request.number }} --json files | jq -r '.files | map(.path) | .[]') | wc -l) + count_new_js=$(comm -1 -2 <(git diff --name-only --diff-filter=A origin/main HEAD -- 'src/*.js' '__mocks__/*.js' '.storybook/*.js' 'assets/*.js' 'config/*.js' 'desktop/*.js' 'jest/*.js' 'scripts/*.js' 'tests/*.js' '.github/libs/*.js' '.github/scripts/*.js' ':!src/libs/SearchParser/*.js') <(gh pr view ${{ github.event.pull_request.number }} --json files | jq -r '.files | map(.path) | .[]') | wc -l) if [ "$count_new_js" -gt "0" ]; then echo "ERROR: Found new JavaScript files in the project; use TypeScript instead." exit 1 diff --git a/.gitignore b/.gitignore index aa6aad4cc429..e33ec43a01fe 100644 --- a/.gitignore +++ b/.gitignore @@ -110,10 +110,6 @@ tsconfig.tsbuildinfo # Mock-github /repo/ -# Workflow test logs -/workflow_tests/logs/ -/workflow_tests/repo/ - # Yalc .yalc yalc.lock diff --git a/package.json b/package.json index 8ea2c90cc3f1..ff9554795d58 100644 --- a/package.json +++ b/package.json @@ -59,8 +59,6 @@ "test:e2e": "ts-node tests/e2e/testRunner.ts --config ./config.local.ts", "test:e2e:dev": "ts-node tests/e2e/testRunner.ts --config ./config.dev.ts", "gh-actions-unused-styles": "./.github/scripts/findUnusedKeys.sh", - "workflow-test": "./workflow_tests/scripts/runWorkflowTests.sh", - "workflow-test:generate": "ts-node workflow_tests/utils/preGenerateTest.ts", "setup-https": "mkcert -install && mkcert -cert-file config/webpack/certificate.pem -key-file config/webpack/key.pem dev.new.expensify.com localhost 127.0.0.1", "e2e-test-runner-build": "node --max-old-space-size=8192 node_modules/.bin/ncc build tests/e2e/testRunner.ts -o tests/e2e/dist/", "react-compiler-healthcheck": "react-compiler-healthcheck --verbose", diff --git a/tsconfig.json b/tsconfig.json index 16497c29b8cb..c0a588f47a64 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,6 @@ "@userActions/*": ["./src/libs/actions/*"] } }, - "include": ["src", "desktop", "web", "website", "docs", "assets", "config", "tests", "jest", "__mocks__", ".github/**/*", ".storybook/**/*", "workflow_tests", "scripts"], + "include": ["src", "desktop", "web", "website", "docs", "assets", "config", "tests", "jest", "__mocks__", ".github/**/*", ".storybook/**/*", "scripts"], "exclude": ["**/node_modules/*", "**/dist/*", ".github/actions/**/index.js", "**/docs/*"] } diff --git a/workflow_tests/.eslintrc.js b/workflow_tests/.eslintrc.js deleted file mode 100644 index 5cd4096bc831..000000000000 --- a/workflow_tests/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - rules: { - '@lwc/lwc/no-async-await': 'off', - 'no-await-in-loop': 'off', - 'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'], - }, -}; diff --git a/workflow_tests/README.md b/workflow_tests/README.md deleted file mode 100644 index b55e2691d13e..000000000000 --- a/workflow_tests/README.md +++ /dev/null @@ -1,422 +0,0 @@ -# Testing GitHub Actions workflows locally - -## Components -The workflow testing framework consists mainly of 3 components: -- [Jest](https://jestjs.io/) - testing framework, also used for [application tests](https://github.com/Expensify/App/tree/main/tests) -- [Mock-github](https://github.com/kiegroup/mock-github) - package allowing for creation of local repositories, which can be used to make sure that the workflow tests have access only to these files that they should and that they won't modify the actual repository -- [Act-js](https://github.com/kiegroup/act-js) - JS wrapper around [Act](https://github.com/nektos/act). Act is a tool that allows to run GitHub Actions workflows locally, and Act-js allows to configure and run Act from JS code, like Jest tests. It also provides additional tools like mocking workflow steps and retrieving the workflow output a JSON, which allows for comparison of the actual output with expected values - -## Setup -- Install dependencies from `package.json` file with `npm install` -- Make sure you have fulfilled the [prerequisites](https://github.com/nektos/act#necessary-prerequisites-for-running-act) for running `Act` -- Install `Act` with `brew install act` and follow the documentation on [first Act run](https://github.com/nektos/act#first-act-run) -- Set the environment variable `ACT_BINARY` to the path to your `Act` executable (`which act` if you're not sure what the path is) -- You should be ready to run the tests now with `npm run workflow-test` -- You can pre-generate new mocks/assertions/test files for a given workflow by running `npm run workflow-test:generate ` - -## Running -- To run the workflow tests simply use - - `npm run workflow-test` - - this will run all the tests sequentially, which can take some time -- To run a specific test suite you can use - - `npm run workflow-test -- -i ` - - this will run only the test from that specific test file -- To run a specific test or subset of tests use - - `npm run workflow-test -- -t ""` - - this will run only the tests having `` in their name/description -- You can combine these like `npm run workflow-test -- -i workflow_tests/preDeploy.test.js -t "single specific test"` -- You can also use all other options which are normally usable with `jest` - -## Limitations -Not all workflows can always be tested this way, for example: -- Act and Act-js do not support all the runner types available in GitHub Actions, like `macOS` runners or some specific version of `Ubuntu` runners like `ubuntu-20.04-64core`. In these cases the job will be omitted entirely and cannot be tested -- Testing more complex workflows in their entirety can be extremely time-consuming and cumbersome. It is often optimal to mock most of the steps with expressions printing the input and output conditions -- Due to the way `Act` and `Act-js` handle workflow output, not much can be checked in the test. What is available, namely whether the job/step executed or not, whether it was successful or not and what its printed output was, should be enough in most scenarios -- `Act` does not seem to support the conditions set on event parameters when determining whether to run the workflow or not, namely for a workflow defined with: -```yaml -on: - pull_request: - types: [opened, edited, reopened] -``` -running `act pull_request -e event_data.json` with `event_data.json` having `{"action": "opened"}` will execute the workflow (as expected), running for example `act push` will not execute it (as expected), but running `act pull_request -e event_data.json` with `event_data.json` having for example `{"action": "assigned"}` **will still execute the workflow** even though it should only be executed with `action` being `opened`, `edited` or `reopened`. This only applies to running the workflow with `Act`, in the GitHub environment it still works as expected - -## File structure -The testing framework file structure within the repository is as follows: -- `App/` - main application folder - - `.github/` - GitHub Actions folder - - `workflows/` - workflows folder - - `.yml` - workflow file - - `...` - other workflow files - - `...` - other GitHub Actions files - - `workflow_tests/` - workflow testing folder - - `jest.config.ts` - `Jest` configuration file - - `README.md` - this readme file - - `utils.js` - various utility functions used in multiple tests - - `.test.js` - test suite file for a GitHub Actions workflow named `` - - `mocks/` - folder with step mock definitions - - `Mocks.js` - file with step mock definitions for the `../.test.js` suite, or for the `` workflow - - `...` - other step mock definition files - - `assertions/` - folder with output assertions - - `Assertions.js` - file with output assertions for the `../.test.js` suite, or for the `` workflow - - `...` - other output assertion files - - `...` - other test suites - - `...` - other application files - -## Utility helpers -`utils.js` file provides several helper methods to speed up the tests development and maintenance - -### `setUpActParams` -`setUpActParams` allows for initiating the context in which Act will execute the workflow - -Parameters: -- `act` - instance of previously created `Act` object that will be updated with new params -- `event` - the name of the event, this can be any event name used by GitHub Actions, like `pull_request`, `push`, `workflow_dispatch`, etc. -- `event_options` - object with options of the event, allowing for customising it for different scenarios, for example `push` event can be customised for pushing to different branches with options `{head: {ref: ''}}` -- `secrets` - object with secret values provided, like `{: , ...}` -- `github_token` - value of the GitHub token, analogous to providing `GITHUB_TOKEN` secret - -Returns an updated `Act` object instance - -Example: -```javascript -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_s3cr3t_p455word'}, - 'dummy_github_token', -); -``` - -### `createMockStep` -`createMockStep` allows for creating uniform mock step definitions compatible with `Act-js` and reduces time required, as well as possibility of errors/typos slipping in while developing tests. More complex behaviours have to be mocked manually - -Parameters: -- `name` - name of the step that **must correspond to the `name` in the `.yml` file**, otherwise the step cannot be found -- `message` - the message to be printed to default output when mock gets executed -- `job_id` - an optional id of the job that will be printed in `[]` square brackets along the `message`, useful when assessing the output with many steps from many jobs -- `inputs` - a list of input parameters to be printed, useful when checking if the step had been executed with expected inputs -- `in_envs` - a list of input environment variables, to be printed, useful when checking if the step had been executed in expected environment -- `outputs` - an object with values which should be printed by the mock to `$GITHUB_OUTPUT`, useful for setting the step output -- `out_envs` - an objects with values of environment variables set by the step in `$GITHUB_ENV`, useful for modifying the environment by the mock -- `isSuccessful` - a boolean value indicating whether the step succeeds or not, exits with status `0` (if successful) or `1` (if not) - -Returns an object with step mock definition, ready to be provided to the `Act` object instance - -Example: -```javascript -let mockStep = utils.createMockStep( - 'Name of the step from .yml', - 'Message to be printed', - 'TEST_JOB', - ['INPUT_1', 'INPUT_2'], - ['ENV_1', 'ENV_2'], - {output_1: true, output_2: 'Some Result'}, - {OUT_ENV: 'ENV_VALUE'}, - false, -); -``` -results in -```javascript -{ - name: 'Name of the step from .yml', - mockWith: 'echo [MOCK]' - + ' [TEST_JOB]' - + ' Message to be printed' - + ', INPUT_1="{{ inputs.INPUT_1 }}' - + ', INPUT_2="{{ inputs.INPUT_2 }}' - + ', ENV_1="{{ env.ENV_1 }}' - + ', ENV_1="{{ env.ENV_1 }}' - + '\necho "output_1=true" >> "$GITHUB_OUTPUT"', - + '\necho "output_2=Some Result" >> "$GITHUB_OUTPUT"', - + '\necho "OUT_ENV=ENV_VALUE" >> "$GITHUB_ENV"', - + '\nexit 1', -} -``` - -### `createStepAssertion` -`createStepAssertion` allows for creating uniform assertions for output from executed step, compatible with step mocks provided by `createMockStep` - -Parameters: -- `name` - name of the step, **has to correspond to the name from `.yml` file**, and the name in the step mock if applicable -- `isSuccessful` - boolean value for checking if the step should have exited successfully -- `expectedOutput` - an output that is expected from the step, compared directly - if provided the subsequent parameters are ignored -- `jobId` - an optional expected job identifier -- `message` - expected message printed by the step -- `inputs` - expected input values provided to the step -- `envs` - expected input environment variables for the step - -Returns an object with step expected output definition ready to be provided to `expect()` matcher - -Example: -```javascript -utils.createStepAssertion( - 'Name of the step from .yml', - false, - null, - 'TEST_JOB', - 'Message to be printed', - [{key: 'INPUT_1', value: true}, {key: 'INPUT_2', value: 'Some value'}], - [{key: 'PLAIN_ENV_VAR', value: 'Value'}, {key: 'SECRET_ENV_VAR', value: '***'}], -) -``` -results in -```javascript -{ - name: 'Name of the step from .yml', - status: 1, - output: '[MOCK]' - + ' [TEST_JOB]' - + ' Message to be printed' - + ', INPUT_1=true' - + ', INPUT_2=Some value' - + ', PLAIN_ENV_VAR=Value' - + ', SECRET_ENV_VAR=***', -} -``` - -### `setJobRunners` -`setJobRunners` overwrites the runner types for given jobs, helpful when the runner type in the workflow is not supported by `Act` - -Parameters: -- `act` - instance of previously created `Act` object -- `jobs` - object with keys being the IDs of the workflow jobs to be modified and values being the names of runners that should be used for them in the test -- `workflowPath` - path to the workflow file to be updated, **NOTE**: this will modify the file, use the one from the local test repo, not from `App/.github/workflows`! - -Returns an `Act` object instance - -Let's say you have a workflow with a job using `macos-12` runner, which is unsupported by `Act` - in this case that job will simply be skipped altogether, not allowing you to test it in any way. -```yaml -iOS: - name: Build and deploy iOS - needs: validateActor - if: ${{ fromJSON(needs.validateActor.outputs.IS_DEPLOYER) }} - runs-on: macos-12 - steps: -``` -You can use this method to change the runner to something that is supported, like -```javascript -act = utils.setJobRunners( - act, - { - iOS: 'ubuntu-latest', - }, - workflowPath, -); -``` -Now the test workflow will look as follows, which will allow you to run the job and do at least limited testing -```yaml -iOS: - name: Build and deploy iOS - needs: validateActor - if: ${{ fromJSON(needs.validateActor.outputs.IS_DEPLOYER) }} - runs-on: ubuntu-latest - steps: -``` - -## Typical test file -The following is the typical test file content, which will be followed by a detailed breakdown -```javascript -const path = require('path'); -const kieActJs = require('@kie/act-js'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils'); -const assertions = require('./assertions/Assertions'); -const mocks = require('./mocks/Mocks'); - -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', - }, - { - src: path.resolve(__dirname, '..', '.github', 'workflows', '.yml'), - dest: '.github/workflows/.yml', - }, -]; - -beforeEach(async () => { - mockGithub = new MockGithub({ - repo: { - testWorkflowsRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); -}); - -afterEach(async () => { - await mockGithub.teardown(); -}); - -describe('test some general behaviour', () => { - test('something happens - test if expected happened next', async () => { - // get path to the local test repo - const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; - - // get path to the workflow file under test - const workflowPath = path.join(repoPath, '.github', 'workflows', '.yml'); - - // instantiate Act in the context of the test repo and given workflow file - let act = new kieActJs.Act(repoPath, workflowPath); - - // set run parameters - act = utils.setUpActParams( - act, - '', - {head: {ref: ''}}, - {'': '', - ); - - // set up mocks - const testMockSteps = { - '': [ - { - name: '', - mockWith: '', - }, - { - name: '', - mockWith: '', - }, - ], - '': [ - utils.createMockStep('', ''), - utils.createMockStep('', ''), - ], - }; - - // run an event and get the result - const result = await act - .runEvent('', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); - - // assert results (some steps can run in parallel to each other so the order is not assured - // therefore we can check which steps have been executed, but not the set job order - assertions.assertSomethingHappened(result); - assertions.assertSomethingDidNotHappen(result, false); - }, timeout); -); -``` - -### Breakdown -Define which files should be copied into the test repo. In this case we copy `actions`, `libs`, `scripts` folders in their entirety and just the one workflow file we want to test -```javascript -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', - }, - { - src: path.resolve(__dirname, '..', '.github', 'workflows', '.yml'), - dest: '.github/workflows/.yml', - }, -]; -``` -`beforeEach` gets executed before each test. Here we create the local test repository with the files defined in the `FILES_TO_COPY_INTO_TEST_REPO` variable. `testWorkflowRepo` is the name of the test repo and can be changed to whichever name you choose, just remember to use it later when accessing this repo. _Note that we can't use `beforeAll()` method, because while mocking steps `Act-js` modifies the workflow file copied into the test repo and thus mocking could persist between tests_ -```javascript -beforeEach(async () => { - mockGithub = new MockGithub({ - repo: { - testWorkflowsRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); -}); -``` -Similarly, `afterEach` gets executed after each test. In this case we remove the test repo after the test finishes -```javascript -afterEach(async () => { - await mockGithub.teardown(); -}); -``` -Get path to the local test repo, useful to have it in a variable -```javascript -const repoPath = mockGithub.repo.getPath('testWorkflowsRepo') || ''; -``` -Get path to the workflow under test. Note that it's the path **in the test repo** -```javascript -const workflowPath = path.join(repoPath, '.github', 'workflows', '.yml'); -``` -Instantiate `Act` object instance. Here we provide the constructor with the path to the test repo (so that `Act` can execute in its context) and the path the workflow file under test (so just the workflow we want to test would be executed) -```javascript -let act = new kieActJs.Act(repoPath, workflowPath); -``` -Set up initial parameters for `Act`. This is where we can set secrets, GitHub token and options for the events (like the name of the branch to which the push has been made, etc.) -```javascript -act = utils.setUpActParams( - act, - '', - {head: {ref: ''}}, - {'': '', -); -``` -Set up step mocks. Here we configure which steps in the workflow should be mocked, and with what behaviour. This takes form of an object with keys corresponding to the names of the jobs in the workflow, and values being mock definitions for specific steps. The steps can be identified either by `id`, `name`, `uses` or `run`. Step mock can be defined either by hand (``) or with the helper method `utils.createMockStep()` (``). Not mocked steps will be executed normally - **make sure this will not have unexpected consequences** -```javascript -const testMockSteps = { - '': [ - { - name: '', - mockWith: '', - }, - { - name: '', - mockWith: '', - }, - ], - '': [ - utils.createMockStep('', ''), - utils.createMockStep('', ''), - ], -}; -``` -Most important part - actually running the event with `Act`. This executes the specified `` in the context of the local test repo created before and with the workflow under test set up. `result` stores the output of `Act` execution, which can then be compared to what was expected. Note that the `workflowFile` is actually path to _workflow folder_ and not the file itself - `Act-js` determines the name of the workflow by itself, and tries to find it in the specified `workflowFile` path, so _providing the full path to the file will fail_ -```javascript -const result = await act - .runEvent('', { - workflowFile: path.join(repoPath, '.github', 'workflows'), - mockSteps: testMockSteps, - }); -``` -Assert results are as expected. This can, for example, include using `expect()` to check if the steps that should be executed have indeed been executed, steps that shouldn't run have not been executed, compare statuses (which steps succeeded, which failed) and step outputs. Outputs can include additional information, like input values, environmental variables, secrets (although these are usually not accessible and represented by `***`, this can still be useful to check if the value exists or not). Here it's usually done with the helper assertion methods defined in the assertions file. Step assertions can be created manually or with `createStepAssertion()` helper method -```javascript -assertions.assertSomethingHappened(result); -assertions.assertSomethingDidNotHappen(result, false); -``` - -## FAQ -### I'm positive that one of the jobs should run, but it doesn't - why? -#### Check the runner type (`runs-on`) it may not be set (which `Act` does not like) or it may be set to one of the unsupported types (primarily the `macos-...` runner types). You can always overwrite the runner type with `utils.setJobRunners()` helper method -### My workflow has many jobs, each with many steps, how do I start testing it without spending hours on setup? -#### First of all, consider splitting the workflow into several smaller pieces, with the main one acting as coordinator and calling the others. Secondly, you can bootstrap the test with `npm run workflow-test:generate .yml`, which will generate mocks and assertions for you, as well as the stub of the test file -### After using `workflow-test:generate` the files are incomplete, or they have errors. Why? -#### Make sure that the workflow file you want to test, has all steps with names, as the bootstrapping script uses step names to locate and mock them - same with assertions. After you've added the `name` properties to steps, remove the previously generated files and run the command again -### I want to just run the test that I am working on, without all the others - how can I do it? -#### You can pass parameters to the `npm run workflow-test` command as you would with `jest` or `npm test` - `npm run workflow-test -- -i ` will run just the tests within `testfile`. You can also filter further with `-t ` diff --git a/workflow_tests/assertions/authorChecklistAssertions.ts b/workflow_tests/assertions/authorChecklistAssertions.ts deleted file mode 100644 index 997eac2d3ea9..000000000000 --- a/workflow_tests/assertions/authorChecklistAssertions.ts +++ /dev/null @@ -1,19 +0,0 @@ -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.ts b/workflow_tests/assertions/cherryPickAssertions.ts deleted file mode 100644 index 8cf5dbd56d54..000000000000 --- a/workflow_tests/assertions/cherryPickAssertions.ts +++ /dev/null @@ -1,116 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertCherryPickJobExecuted(workflowResult: Step[], user = 'Dummy Author', pullRequestNumber = '1234', didExecute = true, hasConflicts = false, isSuccessful = true) { - const steps = [ - createStepAssertion( - 'Checkout staging branch', - true, - null, - 'CHERRYPICK', - 'Checking out staging branch', - [ - {key: 'ref', value: 'staging'}, - {key: 'token', value: '***'}, - ], - [], - ), - 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, - 'CHERRYPICK', - 'Get merge commit for pull request to CP', - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'USER', value: user}, - {key: 'PULL_REQUEST_NUMBER', value: pullRequestNumber}, - ], - [], - ), - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const conflictSteps = [ - createStepAssertion( - 'Create Pull Request to manually finish CP', - true, - null, - 'CHERRYPICK', - 'Creating Pull Request to manually finish CP', - [], - [{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}], - ), - ] as const; - - conflictSteps.forEach((step) => { - if (didExecute && hasConflicts) { - expect(workflowResult).toEqual(expect.arrayContaining([step])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([step])); - } - }); - - const failedSteps = [ - createStepAssertion( - 'Announces a CP failure in the #announce Slack room', - true, - null, - 'CHERRYPICK', - 'Announcing a CP failure', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - ] as const; - - failedSteps.forEach((step) => { - if (didExecute && !isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([step])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([step])); - } - }); -} - -export default {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted, assertCherryPickJobExecuted}; diff --git a/workflow_tests/assertions/claAssertions.ts b/workflow_tests/assertions/claAssertions.ts deleted file mode 100644 index 401e094923dc..000000000000 --- a/workflow_tests/assertions/claAssertions.ts +++ /dev/null @@ -1,73 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertCLAJobExecuted(workflowResult: Step[], commentBody = '', githubRepository = '', didExecute = true, runAssistant = true) { - const steps = [ - createStepAssertion( - 'CLA comment check', - true, - null, - 'CLA', - 'CLA comment check', - [ - {key: 'text', value: commentBody}, - {key: 'regex', value: '\\s*I have read the CLA Document and I hereby sign the CLA\\s*'}, - ], - [], - ), - createStepAssertion( - 'CLA comment re-check', - true, - null, - 'CLA', - 'CLA comment re-check', - [ - {key: 'text', value: commentBody}, - {key: 'regex', value: '\\s*recheck\\s*'}, - ], - [], - ), - ] as const; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const assistantSteps = [ - createStepAssertion( - 'CLA Assistant', - true, - null, - 'CLA', - 'CLA Assistant', - [ - {key: 'path-to-signatures', value: `${githubRepository}/cla.json`}, - {key: 'path-to-document', value: `https://github.com/${githubRepository}/blob/main/contributingGuides/CLA.md`}, - {key: 'branch', value: 'main'}, - {key: 'remote-organization-name', value: 'Expensify'}, - {key: 'remote-repository-name', value: 'CLA'}, - {key: 'lock-pullrequest-aftermerge', value: false}, - {key: 'allowlist', value: 'OSBotify,snyk-bot'}, - ], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'PERSONAL_ACCESS_TOKEN', value: '***'}, - ], - ), - ] as const; - - assistantSteps.forEach((step) => { - if (didExecute && runAssistant) { - expect(workflowResult).toEqual(expect.arrayContaining([step])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([step])); - } - }); -} - -// eslint-disable-next-line import/prefer-default-export -export {assertCLAJobExecuted}; diff --git a/workflow_tests/assertions/createNewVersionAssertions.ts b/workflow_tests/assertions/createNewVersionAssertions.ts deleted file mode 100644 index 253a44060c76..000000000000 --- a/workflow_tests/assertions/createNewVersionAssertions.ts +++ /dev/null @@ -1,71 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertCreateNewVersionJobExecuted(workflowResult: Step[], semverLevel = 'BUILD', didExecute = true, isSuccessful = true) { - const steps = [ - createStepAssertion('Run turnstyle', true, null, 'CREATENEWVERSION', 'Run turnstyle', [{key: 'poll-interval-seconds', value: '10'}], [{key: 'GITHUB_TOKEN', value: '***'}]), - createStepAssertion( - 'Check out', - true, - null, - 'CREATENEWVERSION', - 'Check out', - [ - {key: 'ref', value: 'main'}, - {key: 'token', value: '***'}, - ], - [], - ), - createStepAssertion('Setup git for OSBotify', true, null, 'CREATENEWVERSION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []), - createStepAssertion( - 'Generate version', - true, - null, - 'CREATENEWVERSION', - 'Generate version', - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SEMVER_LEVEL', value: semverLevel}, - ], - [], - ), - 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) { - if (isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const failedSteps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([step])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([step])); - } - }); -} - -export default {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted}; diff --git a/workflow_tests/assertions/deployAssertions.ts b/workflow_tests/assertions/deployAssertions.ts deleted file mode 100644 index 7d992aef99da..000000000000 --- a/workflow_tests/assertions/deployAssertions.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertDeployStagingJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - createStepAssertion('Checkout staging branch', true, null, 'DEPLOY_STAGING', 'Checking out staging branch', [ - {key: 'ref', value: 'staging'}, - {key: 'token', value: '***'}, - ]), - 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: '***'}, - ]), - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertDeployProductionJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - createStepAssertion('Checkout', true, null, 'DEPLOY_PRODUCTION', 'Checking out', [ - {key: 'ref', value: 'production'}, - {key: 'token', value: '***'}, - ]), - 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: '***'}, - ]), - createStepAssertion('Get current app version', true, null, 'DEPLOY_PRODUCTION', 'Getting current app version'), - createStepAssertion( - '🚀 Create release to trigger production deploy 🚀', - true, - null, - 'DEPLOY_PRODUCTION', - 'Creating release to trigger production deploy', - [], - [{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}], - ), - ] as const; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -export default {assertDeployStagingJobExecuted, assertDeployProductionJobExecuted}; diff --git a/workflow_tests/assertions/deployBlockerAssertions.ts b/workflow_tests/assertions/deployBlockerAssertions.ts deleted file mode 100644 index 3d031dda5d74..000000000000 --- a/workflow_tests/assertions/deployBlockerAssertions.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertUpdateChecklistJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { - const steps = [createStepAssertion('updateChecklist', true, null, 'UPDATECHECKLIST', 'Run updateChecklist')] as const; - - steps.forEach((expectedStep) => { - if (didExecute) { - if (isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertDeployBlockerJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true, failsAt = -1) { - const steps = [ - createStepAssertion('Checkout', true, null, 'DEPLOYBLOCKER', 'Checkout'), - createStepAssertion( - 'Give the issue/PR the Hourly, Engineering labels', - true, - null, - 'DEPLOYBLOCKER', - 'Give the issue/PR the Hourly, Engineering labels', - [], - [{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) { - 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])); - } - }); - - const successSteps = [ - createStepAssertion( - 'Post the issue in the #expensify-open-source slack room', - true, - null, - 'DEPLOYBLOCKER', - 'Post the issue in the expensify-open-source slack room', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - ] as const; - - successSteps.forEach((step) => { - if (didExecute && isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([step])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([step])); - } - }); - - const failedSteps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([step])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([step])); - } - }); -} - -export default {assertUpdateChecklistJobExecuted, assertDeployBlockerJobExecuted}; diff --git a/workflow_tests/assertions/failureNotifierAssertions.ts b/workflow_tests/assertions/failureNotifierAssertions.ts deleted file mode 100644 index 37be4e872d32..000000000000 --- a/workflow_tests/assertions/failureNotifierAssertions.ts +++ /dev/null @@ -1,19 +0,0 @@ -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.ts b/workflow_tests/assertions/finishReleaseCycleAssertions.ts deleted file mode 100644 index 5750200affae..000000000000 --- a/workflow_tests/assertions/finishReleaseCycleAssertions.ts +++ /dev/null @@ -1,194 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertValidateJobExecuted(workflowResult: Step[], issueNumber = '', didExecute = true, isTeamMember = true, hasBlockers = false, isSuccessful = true) { - const steps = [ - createStepAssertion('Checkout', true, null, 'VALIDATE', 'Checkout', [ - {key: 'ref', value: 'main'}, - {key: 'token', value: '***'}, - ]), - 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: '***'}, - ]), - 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( - createStepAssertion( - 'Check for any deploy blockers', - true, - null, - 'VALIDATE', - 'Checking for deploy blockers', - [ - {key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}, - {key: 'ISSUE_NUMBER', value: issueNumber}, - ], - [], - ), - ); - } - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - // eslint-disable-next-line rulesdir/no-negated-variables - const notTeamMemberSteps = [ - createStepAssertion( - 'Reopen and comment on issue (not a team member)', - true, - null, - 'VALIDATE', - 'Reopening issue - not a team member', - [ - {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!'}, - ], - [], - ), - ] as const; - - notTeamMemberSteps.forEach((expectedStep) => { - if (didExecute && !isTeamMember) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const blockerSteps = [ - createStepAssertion( - 'Reopen and comment on issue (has blockers)', - true, - null, - 'VALIDATE', - 'Reopening issue - blockers', - [ - {key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}, - {key: 'ISSUE_NUMBER', value: issueNumber}, - ], - [], - ), - ] as const; - - blockerSteps.forEach((expectedStep) => { - if (didExecute && hasBlockers) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const failedSteps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertUpdateProductionJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { - const steps = [ - createStepAssertion( - 'Checkout', - true, - null, - 'UPDATEPRODUCTION', - 'Checkout', - [ - {key: 'ref', value: 'staging'}, - {key: 'token', value: '***'}, - ], - [], - ), - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const failedSteps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertUpdateStagingJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { - const steps = [ - createStepAssertion( - 'Checkout', - true, - null, - 'UPDATESTAGING', - 'Checkout', - [ - {key: 'ref', value: 'main'}, - {key: 'token', value: '***'}, - ], - [], - ), - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const failedSteps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -export default {assertValidateJobExecuted, assertUpdateProductionJobExecuted, assertCreateNewPatchVersionJobExecuted, assertUpdateStagingJobExecuted}; diff --git a/workflow_tests/assertions/lintAssertions.ts b/workflow_tests/assertions/lintAssertions.ts deleted file mode 100644 index 488ec31df95f..000000000000 --- a/workflow_tests/assertions/lintAssertions.ts +++ /dev/null @@ -1,22 +0,0 @@ -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])); - } - }); -} - -export default {assertLintJobExecuted}; diff --git a/workflow_tests/assertions/lockDeploysAssertions.ts b/workflow_tests/assertions/lockDeploysAssertions.ts deleted file mode 100644 index 467e20bc5047..000000000000 --- a/workflow_tests/assertions/lockDeploysAssertions.ts +++ /dev/null @@ -1,74 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertlockStagingDeploysJobExecuted(workflowResult: Step[], didExecute = true, isSuccessful = true) { - const steps = [ - createStepAssertion( - 'Checkout', - true, - null, - 'LOCKSTAGINGDEPLOYS', - 'Checking out', - [ - {key: 'ref', value: 'main'}, - {key: 'token', value: '***'}, - ], - [], - ), - 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, - 'LOCKSTAGINGDEPLOYS', - 'Commenting in StagingDeployCash', - [], - [{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])); - } - }); - - const failProdSteps = [ - createStepAssertion('Announce failed workflow', true, null, 'LOCKSTAGINGDEPLOYS', 'Announcing failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []), - ] as const; - - failProdSteps.forEach((expectedStep) => { - if (didExecute && !isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertlockStagingDeploysJobFailedAfterFirstStep(workflowResult: Step[]) { - const steps = [ - createStepAssertion( - 'Checkout', - true, - null, - 'LOCKSTAGINGDEPLOYS', - 'Checking out', - [ - {key: 'ref', value: 'main'}, - {key: 'token', 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])); - }); -} - -export default {assertlockStagingDeploysJobExecuted, assertlockStagingDeploysJobFailedAfterFirstStep}; diff --git a/workflow_tests/assertions/platformDeployAssertions.ts b/workflow_tests/assertions/platformDeployAssertions.ts deleted file mode 100644 index af42c6818b47..000000000000 --- a/workflow_tests/assertions/platformDeployAssertions.ts +++ /dev/null @@ -1,379 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertDeployChecklistJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [createStepAssertion('deployChecklist', true, null, 'DEPLOY_CHECKLIST', 'Run deployChecklist')] as const; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertAndroidJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true, isSuccessful = true) { - const steps = [ - 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, - 'ANDROID', - 'Setup Java', - [ - {key: 'distribution', value: 'oracle'}, - {key: 'java-version', value: '17'}, - ], - [], - ), - createStepAssertion('Setup Ruby', true, null, 'ANDROID', 'Setting up Ruby', [ - {key: 'ruby-version', value: '2.7'}, - {key: 'bundler-cache', value: 'true'}, - ]), - 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'), - createStepAssertion('Run Fastlane', true, null, 'ANDROID', 'Running Fastlane', null, [ - {key: 'RUBYOPT', value: '-rostruct'}, - {key: 'MYAPP_UPLOAD_STORE_PASSWORD', value: '***'}, - {key: 'MYAPP_UPLOAD_KEY_PASSWORD', value: '***'}, - {key: 'VERSION', value: '1.2.3'}, - ]), - createStepAssertion('Archive Android sourcemaps', true, null, 'ANDROID', 'Archiving Android sourcemaps', [ - // Note 1.2.3 comes from the ref name that we are on, which is the version we are deploying - {key: 'name', value: 'android-sourcemap-1.2.3'}, - {key: 'path', value: 'android/app/build/generated/sourcemaps/react/productionRelease/index.android.bundle.map'}, - ]), - ]; - - if (isProduction) { - steps.push( - createStepAssertion('Upload Android build to GitHub Release', true, null, 'ANDROID', 'Uploading Android build to GitHub Release', null, [{key: 'GITHUB_TOKEN', value: '***'}]), - ); - } else { - steps.push( - createStepAssertion('Upload Android build to GitHub artifacts', true, null, 'ANDROID', 'Uploading Android build to GitHub artifacts', [ - {key: 'name', value: 'app-production-release.aab'}, - {key: 'path', value: 'android/app/build/outputs/bundle/productionRelease/app-production-release.aab'}, - ]), - createStepAssertion('Upload Android build to Browser Stack', true, null, 'ANDROID', 'Uploading Android build to Browser Stack', null, [{key: 'BROWSERSTACK', value: '***'}]), - ); - } - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const failProdSteps = [ - createStepAssertion( - 'Warn deployers if Android production deploy failed', - true, - null, - 'ANDROID', - 'Warning deployers of failed production deploy', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - ] as const; - - failProdSteps.forEach((expectedStep) => { - if (didExecute && isProduction && !isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertDesktopJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true) { - const steps = [ - 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: '***'}]), - createStepAssertion('Build desktop app', true, null, 'DESKTOP', 'Building desktop app', null, [ - {key: 'CSC_LINK', value: '***'}, - {key: 'CSC_KEY_PASSWORD', value: '***'}, - {key: 'APPLE_ID', value: '***'}, - {key: 'APPLE_APP_SPECIFIC_PASSWORD', value: '***'}, - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, - ]), - createStepAssertion('Upload desktop build to GitHub Workflow', true, null, 'DESKTOP', 'Uploading desktop build to GitHub Workflow', [ - {key: 'name', value: 'NewExpensify.dmg'}, - {key: 'path', value: 'desktop-build/NewExpensify.dmg'}, - ]), - ]; - - if (isProduction) { - steps.push( - createStepAssertion('Upload desktop build to GitHub Release', true, null, 'DESKTOP', 'Uploading desktop build to GitHub Release', null, [{key: 'GITHUB_TOKEN', value: '***'}]), - ); - } - - steps.push( - createStepAssertion('Archive desktop sourcemaps', true, null, 'DESKTOP', 'Archiving desktop sourcemaps', [ - // Note 1.2.3 comes from the ref name that we are on, which is the version we are deploying - {key: 'name', value: 'desktop-sourcemap-1.2.3'}, - {key: 'path', value: 'desktop/dist/www/merged-source-map.js.map'}, - ]), - ); - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertIOSJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true, isSuccessful = true) { - const steps = [ - 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'}, - ]), - createStepAssertion('Cache Pod dependencies', true, null, 'IOS', 'Cache Pod dependencies', [ - {key: 'path', value: 'ios/Pods'}, - {key: 'key', value: 'Linux-pods-cache-'}, - ]), - 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'}, - ]), - 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: '***'}]), - createStepAssertion('Set iOS version in ENV', true, null, 'IOS', 'Setting iOS version'), - createStepAssertion('Run Fastlane', true, null, 'IOS', 'Running Fastlane', null, [ - {key: 'APPLE_CONTACT_EMAIL', value: '***'}, - {key: 'APPLE_CONTACT_PHONE', value: '***'}, - {key: 'APPLE_DEMO_EMAIL', value: '***'}, - {key: 'APPLE_DEMO_PASSWORD', value: '***'}, - {key: 'VERSION', value: '1.2.3'}, - ]), - createStepAssertion('Archive iOS sourcemaps', true, null, 'IOS', 'Archiving sourcemaps', [ - // Note 1.2.3 comes from the ref name that we are on, which is the version we are deploying - {key: 'name', value: 'ios-sourcemap-1.2.3'}, - {key: 'path', value: 'main.jsbundle.map'}, - ]), - ]; - - if (isProduction) { - steps.push(createStepAssertion('Upload iOS build to GitHub Release', true, null, 'IOS', 'Uploading iOS build to GitHub Release', null, [{key: 'GITHUB_TOKEN', value: '***'}])); - } else { - steps.push( - createStepAssertion('Upload iOS build to GitHub artifacts', true, null, 'IOS', 'Uploading iOS build to GitHub artifacts', [ - {key: 'name', value: 'New Expensify.ipa'}, - {key: 'path', value: '/Users/runner/work/App/App/New Expensify.ipa'}, - ]), - createStepAssertion('Upload iOS build to Browser Stack', true, null, 'IOS', 'Uploading build to Browser Stack', null, [{key: 'BROWSERSTACK', value: '***'}]), - ); - } - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); - - const failProdSteps = [ - createStepAssertion( - 'Warn deployers if iOS production deploy failed', - true, - null, - 'IOS', - 'Warning developers of failed deploy', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - ] as const; - - failProdSteps.forEach((expectedStep) => { - if (didExecute && isProduction && !isSuccessful) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertWebJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - 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'}, - ]), - ]; - - steps.push( - createStepAssertion('Build web', true, null, 'WEB', 'Building web'), - createStepAssertion('Build storybook docs', true, null, 'WEB', 'Build storybook docs'), - createStepAssertion('Deploy to S3', true, null, 'WEB', 'Deploying to S3'), - createStepAssertion('Archive web sourcemaps', true, null, 'WEB', 'Archiving web sourcemaps', null, [ - // Note 1.2.3 comes from the ref name that we are on, which is the version we are deploying - {key: 'name', value: 'web-sourcemap-1.2.3'}, - {key: 'path', value: 'dist/merged-source-map.js.map'}, - ]), - createStepAssertion('Purge Cloudflare cache', true, null, 'WEB', 'Purging Cloudflare cache', null, [{key: 'CF_API_KEY', value: '***'}]), - ); - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertPostSlackOnFailureJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertPostSlackOnSuccessJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true) { - const steps = [ - 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, - 'POST_SLACK_SUCCESS', - 'Posting message to #announce channel', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - createStepAssertion( - 'Announces the deploy in the #deployer Slack room', - true, - null, - 'POST_SLACK_SUCCESS', - 'Posting message to #deployer channel', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - ]; - - if (isProduction) { - steps.push( - createStepAssertion( - 'Announces the deploy in the #expensify-open-source Slack room', - true, - null, - 'POST_SLACK_SUCCESS', - 'Posting message to #expensify-open-source channel', - [{key: 'status', value: 'custom'}], - [ - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'SLACK_WEBHOOK_URL', value: '***'}, - ], - ), - ); - } - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertPostGithubCommentJobExecuted(workflowResult: Step[], didExecute = true, isProduction = true, didDeploy = true) { - const steps = [ - 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'}, - ]), - 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'}, - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'ANDROID', value: didDeploy ? 'success' : 'skipped'}, - {key: 'DESKTOP', value: didDeploy ? 'success' : 'skipped'}, - {key: 'IOS', value: didDeploy ? 'success' : 'skipped'}, - {key: 'WEB', value: didDeploy ? 'success' : 'skipped'}, - ]), - ] as const; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -export default { - assertVerifyActorJobExecuted, - assertDeployChecklistJobExecuted, - assertAndroidJobExecuted, - assertDesktopJobExecuted, - assertIOSJobExecuted, - assertWebJobExecuted, - assertPostSlackOnFailureJobExecuted, - assertPostSlackOnSuccessJobExecuted, - assertPostGithubCommentJobExecuted, -}; diff --git a/workflow_tests/assertions/preDeployAssertions.ts b/workflow_tests/assertions/preDeployAssertions.ts deleted file mode 100644 index a2762bc3123c..000000000000 --- a/workflow_tests/assertions/preDeployAssertions.ts +++ /dev/null @@ -1,133 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertChooseDeployActionsJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -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.'; - const steps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertUpdateStagingJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - createStepAssertion('Run turnstyle', true, null, 'UPDATE_STAGING', 'Running turnstyle', [ - {key: 'poll-interval-seconds', value: '10'}, - {key: 'GITHUB_TOKEN', value: '***'}, - ]), - createStepAssertion('Checkout main', true, null, 'UPDATE_STAGING', 'Checkout main', [ - {key: 'ref', value: 'main'}, - {key: 'token', value: '***'}, - ]), - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertUpdateStagingJobFailed(workflowResult: Step[], didFail = false) { - const steps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -export default { - assertTypecheckJobExecuted, - assertLintJobExecuted, - assertTestJobExecuted, - assertChooseDeployActionsJobExecuted, - assertSkipDeployJobExecuted, - assertCreateNewVersionJobExecuted, - assertUpdateStagingJobExecuted, - assertUpdateStagingJobFailed, -}; diff --git a/workflow_tests/assertions/reviewerChecklistAssertions.ts b/workflow_tests/assertions/reviewerChecklistAssertions.ts deleted file mode 100644 index 4be8e1807dc7..000000000000 --- a/workflow_tests/assertions/reviewerChecklistAssertions.ts +++ /dev/null @@ -1,16 +0,0 @@ -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])); - } - }); -} - -export default {assertChecklistJobExecuted}; diff --git a/workflow_tests/assertions/testAssertions.ts b/workflow_tests/assertions/testAssertions.ts deleted file mode 100644 index 90fc624a76be..000000000000 --- a/workflow_tests/assertions/testAssertions.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertJestJobExecuted(workflowResult: Step[], didExecute = true, timesExecuted = 3) { - const steps = [ - 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, - 'JEST', - 'Cache Jest cache', - [ - {key: 'path', value: '.jest-cache'}, - {key: 'key', value: 'Linux-jest'}, - ], - [], - ), - createStepAssertion('Jest tests', true, null, 'JEST', 'Jest tests', [], []), - ] as const; - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - let cnt = 0; - workflowResult.forEach((executedStep) => { - if (executedStep.name !== expectedStep.name || executedStep.output !== expectedStep.output || executedStep.status !== expectedStep.status) { - return; - } - cnt += 1; - }); - expect(cnt).toEqual(timesExecuted); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -export default {assertJestJobExecuted}; diff --git a/workflow_tests/assertions/testBuildAssertions.ts b/workflow_tests/assertions/testBuildAssertions.ts deleted file mode 100644 index 8e1ba1a439d5..000000000000 --- a/workflow_tests/assertions/testBuildAssertions.ts +++ /dev/null @@ -1,407 +0,0 @@ -import type {Step} from '@kie/act-js'; -import {createStepAssertion} from '../utils/utils'; - -function assertValidateActorJobExecuted(workflowResult: Step[], pullRequestNumber = '1234', didExecute = true) { - const steps = [ - createStepAssertion('Is Expensify employee', true, null, 'VALIDATEACTOR', 'Is Expensify employee', [], [{key: 'GITHUB_TOKEN', value: '***'}]), - createStepAssertion( - 'Set HAS_READY_TO_BUILD_LABEL flag', - true, - null, - 'VALIDATEACTOR', - 'Set HAS_READY_TO_BUILD_LABEL flag', - [], - [ - {key: 'PULL_REQUEST_NUMBER', value: pullRequestNumber}, - {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])); - } - }); -} - -function assertGetBranchRefJobExecuted(workflowResult: Step[], didExecute = true) { - const steps = [ - 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) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertAndroidJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { - const steps = [ - 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, - 'ANDROID', - 'Setup Java', - [ - {key: 'distribution', value: 'oracle'}, - {key: 'java-version', value: '17'}, - ], - [], - ), - createStepAssertion( - 'Setup Ruby', - true, - null, - 'ANDROID', - 'Setup Ruby', - [ - {key: 'ruby-version', value: '2.7'}, - {key: 'bundler-cache', value: true}, - ], - [], - ), - 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, - 'ANDROID', - 'Configure AWS Credentials', - [ - {key: 'aws-access-key-id', value: '***'}, - {key: 'aws-secret-access-key', value: '***'}, - {key: 'aws-region', value: 'us-east-1'}, - ], - [], - ), - createStepAssertion('Configure MapBox SDK', true, null, 'ANDROID', 'Configure MapBox SDK'), - createStepAssertion( - 'Run Fastlane beta test', - true, - null, - 'ANDROID', - 'Run Fastlane beta test', - [], - [ - {key: 'S3_ACCESS_KEY', value: '***'}, - {key: 'S3_SECRET_ACCESS_KEY', value: '***'}, - {key: 'S3_BUCKET', value: 'ad-hoc-expensify-cash'}, - {key: 'S3_REGION', value: 'us-east-1'}, - {key: 'MYAPP_UPLOAD_STORE_PASSWORD', value: '***'}, - {key: 'MYAPP_UPLOAD_KEY_PASSWORD', value: '***'}, - ], - ), - createStepAssertion( - 'Upload Artifact', - true, - null, - 'ANDROID', - 'Upload Artifact', - [ - {key: 'name', value: 'android'}, - {key: 'path', value: './android_paths.json'}, - ], - [], - ), - ] as const; - - steps.forEach((expectedStep, i) => { - if (didExecute) { - if (failsAt === -1 || i < failsAt) { - // either whole job is successful, or steps up to this point are successful - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else if (i === failsAt) { - // this is the failing step - steps[i].status = 1; - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - // steps after failed one do not execute - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertIOSJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { - const steps = [ - 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, - 'IOS', - 'Setup Ruby', - [ - {key: 'ruby-version', value: '2.7'}, - {key: 'bundler-cache', value: true}, - ], - [], - ), - createStepAssertion('Cache Pod dependencies', true, null, 'IOS', 'Cache Pod dependencies', [ - {key: 'path', value: 'ios/Pods'}, - {key: 'key', value: 'Linux-pods-cache-'}, - ]), - createStepAssertion('Compare Podfile.lock and Manifest.lock', true, null, 'IOS', 'Compare Podfile.lock and Manifest.lock'), - createStepAssertion( - 'Install cocoapods', - true, - null, - 'IOS', - 'Install cocoapods', - [ - {key: 'timeout_minutes', value: '10'}, - {key: 'max_attempts', value: '5'}, - {key: 'command', value: 'cd ios && bundle exec pod install --verbose'}, - ], - [], - ), - createStepAssertion('Decrypt AdHoc profile', true, null, 'IOS', 'Decrypt AdHoc profile', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - createStepAssertion( - 'Decrypt AdHoc Notification Service profile', - true, - null, - 'IOS', - 'Decrypt AdHoc Notification Service profile', - [], - [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}], - ), - createStepAssertion('Decrypt certificate', true, null, 'IOS', 'Decrypt certificate', [], [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}]), - createStepAssertion( - 'Configure AWS Credentials', - true, - null, - 'IOS', - 'Configure AWS Credentials', - [ - {key: 'aws-access-key-id', value: '***'}, - {key: 'aws-secret-access-key', value: '***'}, - {key: 'aws-region', value: 'us-east-1'}, - ], - [], - ), - createStepAssertion( - 'Run Fastlane', - true, - null, - 'IOS', - 'Run Fastlane', - [], - [ - {key: 'S3_ACCESS_KEY', value: '***'}, - {key: 'S3_SECRET_ACCESS_KEY', value: '***'}, - {key: 'S3_BUCKET', value: 'ad-hoc-expensify-cash'}, - {key: 'S3_REGION', value: 'us-east-1'}, - ], - ), - createStepAssertion( - 'Upload Artifact', - true, - null, - 'IOS', - 'Upload Artifact', - [ - {key: 'name', value: 'ios'}, - {key: 'path', value: './ios_paths.json'}, - ], - [], - ), - ] as const; - - steps.forEach((expectedStep, i) => { - if (didExecute) { - if (failsAt === -1 || i < failsAt) { - // either whole job is successful, or steps up to this point are successful - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else if (i === failsAt) { - // this is the failing step - steps[i].status = 1; - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - // steps after failed one do not execute - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertDesktopJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { - const steps = [ - 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, - 'DESKTOP', - 'Configure AWS Credentials', - [ - {key: 'aws-access-key-id', value: '***'}, - {key: 'aws-secret-access-key', value: '***'}, - {key: 'aws-region', value: 'us-east-1'}, - ], - [], - ), - createStepAssertion( - 'Build desktop app for testing', - true, - null, - 'DESKTOP', - 'Build desktop app for testing', - [], - [ - {key: 'CSC_LINK', value: '***'}, - {key: 'CSC_KEY_PASSWORD', value: '***'}, - {key: 'APPLE_ID', value: '***'}, - {key: 'APPLE_APP_SPECIFIC_PASSWORD', value: '***'}, - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, - ], - ), - ] as const; - - steps.forEach((expectedStep, i) => { - if (didExecute) { - if (failsAt === -1 || i < failsAt) { - // either whole job is successful, or steps up to this point are successful - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else if (i === failsAt) { - // this is the failing step - steps[i].status = 1; - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - // steps after failed one do not execute - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertWebJobExecuted(workflowResult: Step[], ref = '', didExecute = true, failsAt = -1) { - const steps = [ - 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, - 'WEB', - 'Configure AWS Credentials', - [ - {key: 'aws-access-key-id', value: '***'}, - {key: 'aws-secret-access-key', value: '***'}, - {key: 'aws-region', value: 'us-east-1'}, - ], - [], - ), - 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) { - if (failsAt === -1 || i < failsAt) { - // either whole job is successful, or steps up to this point are successful - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else if (i === failsAt) { - // this is the failing step - steps[i].status = 1; - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - // steps after failed one do not execute - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -function assertPostGithubCommentJobExecuted( - workflowResult: Step[], - ref = '', - pullRequestNumber = '1234', - didExecute = true, - androidStatus = 'success', - iOSStatus = 'success', - desktopStatus = 'success', - webStatus = 'success', -) { - const steps = [ - createStepAssertion('Checkout', true, null, 'POSTGITHUBCOMMENT', 'Checkout', [{key: 'ref', value: ref}], []), - createStepAssertion('Download Artifact', true, null, 'POSTGITHUBCOMMENT', 'Download Artifact', [], []), - ]; - - if (androidStatus === 'success') { - steps.push(createStepAssertion('Read JSONs with android paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with android paths', [], [])); - } - if (iOSStatus === 'success') { - steps.push(createStepAssertion('Read JSONs with iOS paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with iOS paths', [], [])); - } - - steps.push( - createStepAssertion( - 'Publish links to apps for download', - true, - null, - 'POSTGITHUBCOMMENT', - 'Publish links to apps for download', - [ - {key: 'PR_NUMBER', value: pullRequestNumber}, - {key: 'GITHUB_TOKEN', value: '***'}, - {key: 'ANDROID', value: androidStatus}, - {key: 'DESKTOP', value: desktopStatus}, - {key: 'IOS', value: iOSStatus}, - {key: 'WEB', value: webStatus}, - {key: 'ANDROID_LINK', value: androidStatus === 'success' ? 'http://dummy.android.link' : ''}, - {key: 'DESKTOP_LINK', value: `https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/${pullRequestNumber}/NewExpensify.dmg`}, - {key: 'IOS_LINK', value: iOSStatus === 'success' ? 'http://dummy.ios.link' : ''}, - {key: 'WEB_LINK', value: `https://${pullRequestNumber}.pr-testing.expensify.com`}, - ], - [], - ), - ); - - steps.forEach((expectedStep) => { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - }); -} - -export default { - assertValidateActorJobExecuted, - assertGetBranchRefJobExecuted, - assertAndroidJobExecuted, - assertIOSJobExecuted, - assertDesktopJobExecuted, - assertWebJobExecuted, - assertPostGithubCommentJobExecuted, -}; diff --git a/workflow_tests/assertions/validateGithubActionsAssertions.ts b/workflow_tests/assertions/validateGithubActionsAssertions.ts deleted file mode 100644 index 89eb444299ed..000000000000 --- a/workflow_tests/assertions/validateGithubActionsAssertions.ts +++ /dev/null @@ -1,21 +0,0 @@ -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])); - } - }); -} - -export default {assertVerifyJobExecuted}; diff --git a/workflow_tests/assertions/verifyPodfileAssertions.ts b/workflow_tests/assertions/verifyPodfileAssertions.ts deleted file mode 100644 index d837507ede1b..000000000000 --- a/workflow_tests/assertions/verifyPodfileAssertions.ts +++ /dev/null @@ -1,20 +0,0 @@ -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])); - } - }); -} - -export default {assertVerifyJobExecuted}; diff --git a/workflow_tests/assertions/verifySignedCommitsAssertions.ts b/workflow_tests/assertions/verifySignedCommitsAssertions.ts deleted file mode 100644 index 8aaabafa9d9d..000000000000 --- a/workflow_tests/assertions/verifySignedCommitsAssertions.ts +++ /dev/null @@ -1,17 +0,0 @@ -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 default {assertVerifySignedCommitsJobExecuted}; diff --git a/workflow_tests/authorChecklist.test.ts b/workflow_tests/authorChecklist.test.ts deleted file mode 100644 index a40b183f6d7a..000000000000 --- a/workflow_tests/authorChecklist.test.ts +++ /dev/null @@ -1,179 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/authorChecklistAssertions'; -import mocks from './mocks/authorChecklistMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'authorChecklist.yml'), - dest: '.github/workflows/authorChecklist.yml', - }, -]; - -describe('test workflow authorChecklist', () => { - const githubToken = 'dummy_github_token'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testAuthorChecklistWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('pull request opened', () => { - const event = 'pull_request_target'; - const eventOptions = { - action: 'opened', - }; - describe('actor is not OSBotify', () => { - it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testAuthorChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('authorChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result); - }); - }); - describe('actor is OSBotify', () => { - it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testAuthorChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('authorChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result, false); - }); - }); - }); - describe('pull request edited', () => { - const event = 'pull_request_target'; - const eventOptions = { - action: 'edited', - }; - describe('actor is not OSBotify', () => { - it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testAuthorChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('authorChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result); - }); - }); - describe('actor is OSBotify', () => { - it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testAuthorChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('authorChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result, false); - }); - }); - }); - describe('pull request reopened', () => { - const event = 'pull_request_target'; - const eventOptions = { - action: 'reopened', - }; - describe('actor is not OSBotify', () => { - it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testAuthorChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('authorChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result); - }); - }); - describe('actor is OSBotify', () => { - it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testAuthorChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.AUTHORCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'authorChecklist.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('authorChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result, false); - }); - }); - }); -}); diff --git a/workflow_tests/cherryPick.test.ts b/workflow_tests/cherryPick.test.ts deleted file mode 100644 index 964be3ec427d..000000000000 --- a/workflow_tests/cherryPick.test.ts +++ /dev/null @@ -1,396 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/cherryPickAssertions'; -import mocks from './mocks/cherryPickMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import type {MockJobs} from './utils/JobMocker'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'cherryPick.yml'), - dest: '.github/workflows/cherryPick.yml', - }, -]; - -describe('test workflow cherryPick', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testCherryPickWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('manual workflow dispatch', () => { - const event = 'workflow_dispatch'; - describe('actor is not deployer', () => { - const actor = 'Dummy Author'; - it('workflow ends after validate job', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__FALSE__STEP_MOCKS, - cherryPick: mocks.getCherryPickMockSteps(true, false), - }; - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertCherryPickJobExecuted(result, actor, '1234', false); - }); - }); - describe('actor is OSBotify', () => { - const actor = 'OSBotify'; - const mergeConflicts = false; - const versionsMatch = true; - it('behaviour is the same as with actor being the deployer', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__FALSE__STEP_MOCKS, - cherryPick: mocks.getCherryPickMockSteps(versionsMatch, mergeConflicts), - }; - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertCherryPickJobExecuted(result, actor, '1234', true); - }); - }); - describe('actor is a deployer', () => { - const actor = 'Dummy Author'; - describe('no merge conflicts', () => { - const mergeConflicts = false; - describe('version match', () => { - const versionsMatch = true; - it('workflow executes, PR approved and merged automatically', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS, - }; - testMockSteps.cherryPick = mocks.getCherryPickMockSteps(versionsMatch, mergeConflicts); - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertCherryPickJobExecuted(result, actor, '1234', true); - }); - }); - describe('version does not match', () => { - const versionsMatch = false; - it('workflow executes, PR auto-assigned and commented, approved and merged automatically', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS, - }; - testMockSteps.cherryPick = mocks.getCherryPickMockSteps(versionsMatch, mergeConflicts); - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertCherryPickJobExecuted(result, actor, '1234', true); - }); - }); - }); - describe('merge conflicts', () => { - const mergeConflicts = true; - describe('version match', () => { - const versionsMatch = true; - it('workflow executes, PR auto-assigned and commented, not merged automatically', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS, - }; - testMockSteps.cherryPick = mocks.getCherryPickMockSteps(versionsMatch, mergeConflicts); - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertCherryPickJobExecuted(result, actor, '1234', true, true); - }); - }); - describe('version does not match', () => { - const versionsMatch = false; - it('workflow executes, PR auto-assigned and commented, not merged automatically', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS, - }; - testMockSteps.cherryPick = mocks.getCherryPickMockSteps(versionsMatch, mergeConflicts); - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertCherryPickJobExecuted(result, actor, '1234', true, true); - }); - }); - }); - }); - }); - describe('automatic trigger', () => { - const event = 'pull_request'; - it('workflow does not execute', async () => { - const repoPath = mockGithub.repo.getPath('testCherryPickWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - event, - null, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - null, - { - PULL_REQUEST_NUMBER: '1234', - }, - ); - const testMockSteps: MockStep = { - validateActor: mocks.CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS, - cherryPick: mocks.getCherryPickMockSteps(true, false), - }; - const testMockJobs: MockJobs = { - createNewVersion: { - steps: mocks.CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cherryPick.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('cherryPick', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertValidateActorJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertCherryPickJobExecuted(result, 'Dummy Author', '1234', false); - }); - }); -}); diff --git a/workflow_tests/cla.test.ts b/workflow_tests/cla.test.ts deleted file mode 100644 index 91691ec80587..000000000000 --- a/workflow_tests/cla.test.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {Step} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import {assertCLAJobExecuted} from './assertions/claAssertions'; -import {CLA__CLA__CHECK_MATCH__STEP_MOCKS, CLA__CLA__NO_MATCHES__STEP_MOCKS, CLA__CLA__RECHECK_MATCH__STEP_MOCKS} from './mocks/claMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'cla.yml'), - dest: '.github/workflows/cla.yml', - }, -]; - -describe('test workflow cla', () => { - const secrets: Record = { - CLA_BOTIFY_TOKEN: 'dummy_cla_botify_token', - }; - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Author'; - - // eslint-disable-next-line @typescript-eslint/require-await - beforeAll(async () => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testClaWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub?.teardown(); - }); - describe('event is issue_comment', () => { - const event = 'issue_comment'; - describe('no regex matches', () => { - const commentBody = 'Comment body'; - const eventData = { - action: 'created', - issue: { - pull_request: { - number: 1234, - }, - }, - comment: { - body: commentBody, - }, - }; - it('workflow executes, CLA assistant step not run', async () => { - const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventData, secrets, githubToken); - - const testMockSteps = { - CLA: CLA__CLA__NO_MATCHES__STEP_MOCKS, - }; - - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cla', expect.getState().currentTestName), - }); - - assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, false); - }); - }); - describe('check regex matches', () => { - const commentBody = 'I have read the CLA Document and I hereby sign the CLA'; - const eventData = { - action: 'created', - issue: { - pull_request: { - number: 1234, - }, - }, - comment: { - body: commentBody, - }, - }; - it('workflow executes, CLA assistant step run', async () => { - const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventData, secrets, githubToken); - - const testMockSteps = { - CLA: CLA__CLA__CHECK_MATCH__STEP_MOCKS, - }; - - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cla', expect.getState().currentTestName), - }); - - assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, true); - }); - }); - describe('re-check regex matches', () => { - const commentBody = 'recheck'; - const eventData = { - action: 'created', - issue: { - pull_request: { - number: 1234, - }, - }, - comment: { - body: commentBody, - }, - }; - it('workflow executes, CLA assistant step run', async () => { - const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventData, secrets, githubToken); - - const testMockSteps = { - CLA: CLA__CLA__RECHECK_MATCH__STEP_MOCKS, - }; - - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cla', expect.getState().currentTestName), - }); - - assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, true); - }); - }); - }); - describe('event is pull_request_target', () => { - const event = 'pull_request_target'; - describe("no regex matches - there's no comment", () => { - const eventData = { - action: 'opened', - issue: { - pull_request: { - number: 1234, - }, - }, - }; - it('workflow executes, CLA assistant step still run', async () => { - const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventData, secrets, githubToken); - - const testMockSteps = { - CLA: CLA__CLA__NO_MATCHES__STEP_MOCKS, - }; - - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cla', expect.getState().currentTestName), - }); - - assertCLAJobExecuted(result, '', `${repoPath}/remote/origin`, true, true); - }); - }); - }); - describe('different event', () => { - const event = 'push'; - it('workflow does not execute', async () => { - const eventData = { - ref: 'main', - }; - - const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventData, secrets, githubToken); - - const testMockSteps = { - CLA: CLA__CLA__NO_MATCHES__STEP_MOCKS, - }; - - const result: Step[] = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('cla', expect.getState().currentTestName), - }); - - assertCLAJobExecuted(result, '', `${repoPath}/remote/origin`, false); - }); - }); -}); diff --git a/workflow_tests/createNewVersion.test.ts b/workflow_tests/createNewVersion.test.ts deleted file mode 100644 index 05dcc2b10073..000000000000 --- a/workflow_tests/createNewVersion.test.ts +++ /dev/null @@ -1,169 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/createNewVersionAssertions'; -import mocks from './mocks/createNewVersionMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); // 90 sec -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'createNewVersion.yml'), - dest: '.github/workflows/createNewVersion.yml', - }, -]; - -describe('test workflow createNewVersion', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testCreateNewVersionWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - - describe('event is workflow_call', () => { - const event = 'workflow_call'; - const inputs = { - SEMVER_LEVEL: 'BUILD', - }; - const secrets = { - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - OS_BOTIFY_COMMIT_TOKEN: 'dummy_osbotify_commit_token', - SLACK_WEBHOOK: 'dummy_webhook', - OS_BOTIFY_APP_ID: 'os_botify_app_id', - OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key', - }; - const githubToken = 'dummy_github_token'; - - describe('actor is admin', () => { - const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS; - it('executes full workflow', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: validateActorMockSteps, - createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName), - }); - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - }); - }); - - describe('actor is writer', () => { - const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS; - it('executes full workflow', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: validateActorMockSteps, - createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName), - }); - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result); - }); - }); - - describe('actor is reader', () => { - const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS; - it('stops after validation', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: validateActorMockSteps, - createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName), - }); - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result, 'BUILD', false); - }); - }); - - describe('one step fails', () => { - it('announces failure on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS, - createNewVersion: utils.deepCopy(mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS), - }; - testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], {}, {}, false); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName), - }); - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result, 'BUILD', true, false); - }); - }); - - it('chooses source branch depending on the SEMVER_LEVEL', async () => { - const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, {SEMVER_LEVEL: 'MAJOR'}); - act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS, - createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName), - }); - assertions.assertValidateActorJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result, 'MAJOR'); - }); - }); -}); diff --git a/workflow_tests/deploy.test.ts b/workflow_tests/deploy.test.ts deleted file mode 100644 index 4edb3b252d38..000000000000 --- a/workflow_tests/deploy.test.ts +++ /dev/null @@ -1,164 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/deployAssertions'; -import mocks from './mocks/deployMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'deploy.yml'), - dest: '.github/workflows/deploy.yml', - }, -]; - -describe('test workflow deploy', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testDeployWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - - const secrets = { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - OS_BOTIFY_APP_ID: 'os_botify_app_id', - OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key', - }; - describe('push', () => { - it('to main - nothing triggered', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - { - ref: 'refs/heads/main', - }, - secrets, - 'dummy_github_token', - ); - const testMockSteps = { - deployStaging: mocks.DEPLOY_STAGING_STEP_MOCKS, - deployProduction: mocks.DEPLOY_PRODUCTION_STEP_MOCKS, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deploy.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('deploy', expect.getState().currentTestName), - }); - assertions.assertDeployStagingJobExecuted(result, false); - assertions.assertDeployProductionJobExecuted(result, false); - }); - - it('to staging - deployStaging triggered', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - { - ref: 'refs/heads/staging', - }, - secrets, - 'dummy_github_token', - ); - const testMockSteps = { - deployStaging: mocks.DEPLOY_STAGING_STEP_MOCKS, - deployProduction: mocks.DEPLOY_PRODUCTION_STEP_MOCKS, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deploy.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('deploy', expect.getState().currentTestName), - }); - assertions.assertDeployStagingJobExecuted(result); - assertions.assertDeployProductionJobExecuted(result, false); - }); - - it('to production - deployProduction triggered', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - { - ref: 'refs/heads/production', - }, - secrets, - 'dummy_github_token', - ); - const testMockSteps = { - deployStaging: mocks.DEPLOY_STAGING_STEP_MOCKS, - deployProduction: mocks.DEPLOY_PRODUCTION_STEP_MOCKS, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deploy.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('deploy', expect.getState().currentTestName), - }); - assertions.assertDeployStagingJobExecuted(result, false); - assertions.assertDeployProductionJobExecuted(result); - }); - }); - - it('different event than push - workflow does not execute', async () => { - const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps = { - deployStaging: mocks.DEPLOY_STAGING_STEP_MOCKS, - deployProduction: mocks.DEPLOY_PRODUCTION_STEP_MOCKS, - }; - - // pull_request - act = utils.setUpActParams(act, 'pull_request', {head: {ref: 'main'}}, secrets, 'dummy_github_token'); - let result = await act.runEvent('pull_request', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('deploy', expect.getState().currentTestName), - }); - assertions.assertDeployStagingJobExecuted(result, false); - assertions.assertDeployProductionJobExecuted(result, false); - - // workflow_dispatch - act = utils.setUpActParams(act, 'workflow_dispatch', {}, secrets, 'dummy_github_token'); - result = await act.runEvent('workflow_dispatch', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('deploy', expect.getState().currentTestName), - }); - assertions.assertDeployStagingJobExecuted(result, false); - assertions.assertDeployProductionJobExecuted(result, false); - }); -}); diff --git a/workflow_tests/deployBlocker.test.ts b/workflow_tests/deployBlocker.test.ts deleted file mode 100644 index eb4cdc2c9497..000000000000 --- a/workflow_tests/deployBlocker.test.ts +++ /dev/null @@ -1,161 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/deployBlockerAssertions'; -import mocks from './mocks/deployBlockerMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'deployBlocker.yml'), - dest: '.github/workflows/deployBlocker.yml', - }, -]; - -describe('test workflow deployBlocker', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Author'; - const secrets = { - OS_BOTIFY_TOKEN: 'dummy_osbotify_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testDeployBlockerWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are need add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('issue labeled', () => { - const event = 'issues'; - const eventOptions = { - action: 'labeled', - label: { - name: 'DeployBlockerCash', - }, - issue: { - title: 'Labeled issue title', - number: '1234', - html_url: 'http://issue.html.url', - }, - }; - describe('label is DeployBlockerCash', () => { - const testEventOptions = utils.deepCopy(eventOptions); - testEventOptions.label = {name: 'DeployBlockerCash'}; - it('runs the workflow and announces success on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); - const testMockSteps = { - deployBlocker: mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS, - }; - const testMockJobs = { - updateChecklist: { - steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertUpdateChecklistJobExecuted(result); - assertions.assertDeployBlockerJobExecuted(result); - }); - describe('one step fails', () => { - it('announces failure on Slack', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); - const testMockSteps = { - deployBlocker: utils.deepCopy(mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS), - }; - testMockSteps.deployBlocker[1] = utils.createMockStep( - 'Give the issue/PR the Hourly, Engineering labels', - 'Give the issue/PR the Hourly, Engineering labels', - 'DEPLOYBLOCKER', - [], - ['GITHUB_TOKEN'], - null, - null, - false, - ); - const testMockJobs = { - updateChecklist: { - steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertUpdateChecklistJobExecuted(result); - assertions.assertDeployBlockerJobExecuted(result, true, false, 1); - }); - }); - }); - describe('label is different', () => { - const testEventOptions = utils.deepCopy(eventOptions); - testEventOptions.label = {name: 'Different Label'}; - it('does not run workflow', async () => { - const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {}); - const testMockSteps = { - deployBlocker: mocks.DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS, - }; - const testMockJobs = { - updateChecklist: { - steps: mocks.DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('deployBlocker', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertUpdateChecklistJobExecuted(result, false); - assertions.assertDeployBlockerJobExecuted(result, false); - }); - }); - }); -}); diff --git a/workflow_tests/failureNotifier.test.ts b/workflow_tests/failureNotifier.test.ts deleted file mode 100644 index 772cd5d28050..000000000000 --- a/workflow_tests/failureNotifier.test.ts +++ /dev/null @@ -1,64 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/failureNotifierAssertions'; -import mocks from './mocks/failureNotifierMocks'; -import ExtendedAct from './utils/ExtendedAct'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'failureNotifier.yml'), - dest: '.github/workflows/failureNotifier.yml', - }, -] as const satisfies CreateRepositoryFile[]; - -describe('test workflow failureNotifier', () => { - const actor = 'Dummy Actor'; - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testFailureNotifierWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are needed add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - it('runs the notify failure when main fails', async () => { - const repoPath = mockGithub.repo.getPath('testFailureNotifierWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const event = 'workflow_run'; - act = act.setEvent({ - // eslint-disable-next-line @typescript-eslint/naming-convention - workflow_run: { - name: 'Process new code merged to main', - conclusion: 'failure', - }, - }); - const testMockSteps = { - notifyFailure: mocks.FAILURENOTIFIER__NOTIFYFAILURE__STEP_MOCKS, - } as const satisfies MockStep; - - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'), - mockSteps: testMockSteps, - actor, - }); - - // assert execution with imported assertions - assertions.assertNotifyFailureJobExecuted(result); - }); -}); diff --git a/workflow_tests/finishReleaseCycle.test.ts b/workflow_tests/finishReleaseCycle.test.ts deleted file mode 100644 index 7f81137807f4..000000000000 --- a/workflow_tests/finishReleaseCycle.test.ts +++ /dev/null @@ -1,240 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/finishReleaseCycleAssertions'; -import mocks from './mocks/finishReleaseCycleMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import type {MockJobs} from './utils/JobMocker'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'finishReleaseCycle.yml'), - dest: '.github/workflows/finishReleaseCycle.yml', - }, -]; - -describe('test workflow finishReleaseCycle', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testFinishReleaseCycleWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - const secrets = { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - SLACK_WEBHOOK: 'dummy_slack_webhook', - OS_BOTIFY_APP_ID: 'os_botify_app_id', - OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key', - }; - describe('issue closed', () => { - describe('issue has StagingDeployCash', () => { - describe('actor is a team member', () => { - describe('no deploy blockers', () => { - it('production updated, new version created', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'StagingDeployCash'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs: MockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234'); - assertions.assertUpdateProductionJobExecuted(result); - assertions.assertCreateNewPatchVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result); - }); - }); - describe('deploy blockers', () => { - it('production not updated, new version not created, issue reopened', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'StagingDeployCash'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234', true, true, true); - assertions.assertUpdateProductionJobExecuted(result, false); - assertions.assertCreateNewPatchVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - }); - }); - describe('actor is not a team member', () => { - it('production not updated, new version not created, issue reopened', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'StagingDeployCash'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234', true, false, false); - assertions.assertUpdateProductionJobExecuted(result, false); - assertions.assertCreateNewPatchVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - }); - }); - describe('issue does not have StagingDeployCash', () => { - it('validate job not run', async () => { - const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'closed', - type: 'closed', - issue: { - labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], - number: '1234', - }, - }, - secrets, - ); - const testMockSteps = { - validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS, - updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, - }; - const testMockJobs = { - createNewPatchVersion: { - steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertValidateJobExecuted(result, '1234', false); - assertions.assertUpdateProductionJobExecuted(result, false); - assertions.assertCreateNewPatchVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - }); - }); -}); diff --git a/workflow_tests/jest.config.ts b/workflow_tests/jest.config.ts deleted file mode 100644 index 8156e449039f..000000000000 --- a/workflow_tests/jest.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {Config} from 'jest'; - -const config: Config = { - verbose: true, - transform: { - '^.+\\.(js|jsx|ts|tsx)$': 'ts-jest', - }, - clearMocks: true, - resetMocks: true, -}; - -export default config; diff --git a/workflow_tests/lint.test.ts b/workflow_tests/lint.test.ts deleted file mode 100644 index e0b0fb13859d..000000000000 --- a/workflow_tests/lint.test.ts +++ /dev/null @@ -1,155 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/lintAssertions'; -import mocks from './mocks/lintMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'lint.yml'), - dest: '.github/workflows/lint.yml', - }, -]; - -describe('test workflow lint', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testLintWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are need add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('event is workflow_call', () => { - const event = 'workflow_call'; - const eventOptions = {}; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - lint: mocks.LINT__LINT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - describe('actor is OSBotify', () => { - const testActor = 'OSBotify'; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - lint: mocks.LINT__LINT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor: testActor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - }); - }); - describe('event is pull_request', () => { - const event = 'pull_request'; - describe('pull_request is opened', () => { - const eventOptions = { - action: 'opened', - }; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - lint: mocks.LINT__LINT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - describe('actor is OSBotify', () => { - const testActor = 'OSBotify'; - it('does not run the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - lint: mocks.LINT__LINT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor: testActor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result, false); - }); - }); - }); - describe('pull_request is synchronized', () => { - const eventOptions = { - action: 'synchronize', - }; - it('runs the lint', async () => { - const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - lint: mocks.LINT__LINT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lint.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('lint', expect.getState().currentTestName), - }); - - assertions.assertLintJobExecuted(result); - }); - }); - }); -}); diff --git a/workflow_tests/lockDeploys.test.ts b/workflow_tests/lockDeploys.test.ts deleted file mode 100644 index 7ffb4ed87b7a..000000000000 --- a/workflow_tests/lockDeploys.test.ts +++ /dev/null @@ -1,462 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/lockDeploysAssertions'; -import mocks from './mocks/lockDeploysMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'lockDeploys.yml'), - dest: '.github/workflows/lockDeploys.yml', - }, -]; - -describe('test workflow lockDeploys', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testLockDeploysWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('issue labeled', () => { - describe('label is LockCashDeploys', () => { - describe('issue has StagingDeployCash', () => { - describe('actor is not OSBotify', () => { - it('job triggered, comment left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: '🔐 LockCashDeploys 🔐', - }, - issue: { - labels: [{name: 'StagingDeployCash'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result); - }); - - it('one step fails, comment not left in StagingDeployCash, announced failure in Slack', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: '🔐 LockCashDeploys 🔐', - }, - issue: { - labels: [{name: 'StagingDeployCash'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - testMockSteps.lockStagingDeploys[1] = utils.createMockStep( - 'Wait for staging deploys to finish', - 'Waiting for staging deploys to finish', - 'LOCKSTAGINGDEPLOYS', - ['GITHUB_TOKEN'], - [], - null, - null, - false, - ); - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobFailedAfterFirstStep(result); - }); - }); - - describe('actor is OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: '🔐 LockCashDeploys 🔐', - }, - issue: { - labels: [{name: 'StagingDeployCash'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - }); - - describe('issue does not have StagingDeployCash', () => { - describe('actor is not OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: '🔐 LockCashDeploys 🔐', - }, - issue: { - labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - - describe('actor is OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: '🔐 LockCashDeploys 🔐', - }, - issue: { - labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - }); - }); - - describe('label is not LockCashDeploys', () => { - describe('issue has StagingDeployCash', () => { - describe('actor is not OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: 'Some different label', - }, - issue: { - labels: [{name: 'StagingDeployCash'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - - describe('actor is OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: 'Some different label', - }, - issue: { - labels: [{name: 'StagingDeployCash'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - }); - - describe('issue does not have StagingDeployCash', () => { - describe('actor is not OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: 'Some other label', - }, - issue: { - labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - - describe('actor is OSBotify', () => { - it('job not triggered, comment not left in StagingDeployCash', async () => { - const repoPath = mockGithub.repo.getPath('testLockDeploysWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'issues', - { - action: 'labeled', - type: 'labeled', - label: { - name: 'Some other label', - }, - issue: { - labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}], - }, - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - ); - act = utils.setJobRunners( - act, - { - lockStagingDeploys: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - lockStagingDeploys: mocks.LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, - }; - const result = await act.runEvent('issues', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'lockDeploys.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('lockDeploys', expect.getState().currentTestName), - }); - - assertions.assertlockStagingDeploysJobExecuted(result, false); - }); - }); - }); - }); - }); -}); diff --git a/workflow_tests/mocks/authorChecklistMocks.ts b/workflow_tests/mocks/authorChecklistMocks.ts deleted file mode 100644 index 34e6b0984e83..000000000000 --- a/workflow_tests/mocks/authorChecklistMocks.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -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.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/cherryPickMocks.ts b/workflow_tests/mocks/cherryPickMocks.ts deleted file mode 100644 index 13d7ebf95bfd..000000000000 --- a/workflow_tests/mocks/cherryPickMocks.ts +++ /dev/null @@ -1,113 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -import {createMockStep} from '../utils/utils'; - -// validateactor -const CHERRYPICK__VALIDATEACTOR__CHECK_IF_USER_IS_DEPLOYER_TRUE__STEP_MOCK = createMockStep( - 'Check if user is deployer', - 'Checking if user is a deployer', - 'VALIDATEACTOR', - [], - ['GITHUB_TOKEN'], - {IS_DEPLOYER: true}, -); -const CHERRYPICK__VALIDATEACTOR__CHECK_IF_USER_IS_DEPLOYER_FALSE__STEP_MOCK = createMockStep( - 'Check if user is deployer', - 'Checking if user is a deployer', - 'VALIDATEACTOR', - [], - ['GITHUB_TOKEN'], - {IS_DEPLOYER: false}, -); -const CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS = [CHERRYPICK__VALIDATEACTOR__CHECK_IF_USER_IS_DEPLOYER_TRUE__STEP_MOCK]; -const CHERRYPICK__VALIDATEACTOR__FALSE__STEP_MOCKS = [CHERRYPICK__VALIDATEACTOR__CHECK_IF_USER_IS_DEPLOYER_FALSE__STEP_MOCK]; - -// createnewversion -const CHERRYPICK__CREATENEWVERSION__CREATE_NEW_VERSION__STEP_MOCK = createMockStep( - 'Create new version', - 'Creating new version', - 'CREATENEWVERSION', - [], - [], - {NEW_VERSION: '1.2.3'}, - null, - true, - 'createNewVersion', -); -const CHERRYPICK__CREATENEWVERSION__STEP_MOCKS = [CHERRYPICK__CREATENEWVERSION__CREATE_NEW_VERSION__STEP_MOCK]; - -// cherrypick -const CHERRYPICK__CHERRYPICK__CHECKOUT_STAGING_BRANCH__STEP_MOCK = createMockStep('Checkout staging branch', 'Checking out staging branch', 'CHERRYPICK', ['ref', 'token'], []); -const CHERRYPICK__CHERRYPICK__SET_UP_GIT_FOR_OSBOTIFY__STEP_MOCK = createMockStep('Set up git for OSBotify', 'Setting up git for OSBotify', 'CHERRYPICK', ['GPG_PASSPHRASE'], [], { - OS_BOTIFY_API_TOKEN: 'os_botify_api_token', -}); -const CHERRYPICK__CHERRYPICK__GET_PREVIOUS_APP_VERSION__STEP_MOCK = createMockStep('Get previous app version', 'Get previous app version', 'CHERRYPICK', ['SEMVER_LEVEL']); -const CHERRYPICK__CHERRYPICK__FETCH_HISTORY_OF_RELEVANT_REFS__STEP_MOCK = createMockStep('Fetch history of relevant refs', 'Fetch history of relevant refs', 'CHERRYPICK'); -const CHERRYPICK__CHERRYPICK__GET_VERSION_BUMP_COMMIT__STEP_MOCK = createMockStep('Get version bump commit', 'Get version bump commit', 'CHERRYPICK', [], [], { - VERSION_BUMP_SHA: 'version_bump_sha', -}); -const CHERRYPICK__CHERRYPICK__GET_MERGE_COMMIT_FOR_PULL_REQUEST_TO_CP__STEP_MOCK = createMockStep( - 'Get merge commit for pull request to CP', - 'Get merge commit for pull request to CP', - 'CHERRYPICK', - ['GITHUB_TOKEN', 'USER', 'PULL_REQUEST_NUMBER'], - [], - {MERGE_ACTOR: '@dummyauthor'}, -); -const CHERRYPICK__CHERRYPICK__CHERRY_PICK_THE_VERSION_BUMP_TO_STAGING__STEP_MOCK = createMockStep( - 'Cherry-pick the version-bump to staging', - 'Cherry-picking the version-bump to staging', - 'CHERRYPICK', - [], - [], -); -const CHERRYPICK__CHERRYPICK__CHERRY_PICK_THE_MERGE_COMMIT_OF_TARGET_PR_TO_NEW_BRANCH__HAS_NO_CONFLICTS__STEP_MOCK = createMockStep( - 'Cherry-pick the merge commit of target PR', - 'Cherry-picking the merge commit of target PR', - 'CHERRYPICK', - [], - [], - {HAS_CONFLICTS: false}, -); -// eslint-disable-next-line rulesdir/no-negated-variables -const CHERRYPICK__CHERRYPICK__CHERRY_PICK_THE_MERGE_COMMIT_OF_TARGET_PR_TO_NEW_BRANCH__HAS_CONFLICTS__STEP_MOCK = createMockStep( - 'Cherry-pick the merge commit of target PR', - 'Cherry-picking the merge commit of target PR', - 'CHERRYPICK', - [], - [], - {HAS_CONFLICTS: true}, -); -const CHERRYPICK__CHERRYPICK__PUSH_CHANGES__STEP_MOCK = createMockStep('Push changes', 'Pushing changes', 'CHERRYPICK', [], []); -const CHERRYPICK__CHERRYPICK__CREATE_PULL_REQUEST_TO_MANUALLY_FINISH_CP__STEP_MOCK = createMockStep( - 'Create Pull Request to manually finish CP', - 'Creating Pull Request to manually finish CP', - 'CHERRYPICK', - [], - ['GITHUB_TOKEN'], -); -const CHERRYPICK__CHERRYPICK__ANNOUNCES_A_CP_FAILURE_IN_THE_ANNOUNCE_SLACK_ROOM__STEP_MOCK = createMockStep( - 'Announces a CP failure in the #announce Slack room', - 'Announcing a CP failure', - 'CHERRYPICK', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); - -const getCherryPickMockSteps = (upToDate: boolean, hasConflicts: boolean): StepIdentifier[] => [ - CHERRYPICK__CHERRYPICK__CHECKOUT_STAGING_BRANCH__STEP_MOCK, - CHERRYPICK__CHERRYPICK__SET_UP_GIT_FOR_OSBOTIFY__STEP_MOCK, - CHERRYPICK__CHERRYPICK__GET_PREVIOUS_APP_VERSION__STEP_MOCK, - CHERRYPICK__CHERRYPICK__FETCH_HISTORY_OF_RELEVANT_REFS__STEP_MOCK, - CHERRYPICK__CHERRYPICK__GET_VERSION_BUMP_COMMIT__STEP_MOCK, - CHERRYPICK__CHERRYPICK__GET_MERGE_COMMIT_FOR_PULL_REQUEST_TO_CP__STEP_MOCK, - CHERRYPICK__CHERRYPICK__CHERRY_PICK_THE_VERSION_BUMP_TO_STAGING__STEP_MOCK, - hasConflicts - ? CHERRYPICK__CHERRYPICK__CHERRY_PICK_THE_MERGE_COMMIT_OF_TARGET_PR_TO_NEW_BRANCH__HAS_CONFLICTS__STEP_MOCK - : CHERRYPICK__CHERRYPICK__CHERRY_PICK_THE_MERGE_COMMIT_OF_TARGET_PR_TO_NEW_BRANCH__HAS_NO_CONFLICTS__STEP_MOCK, - CHERRYPICK__CHERRYPICK__PUSH_CHANGES__STEP_MOCK, - CHERRYPICK__CHERRYPICK__CREATE_PULL_REQUEST_TO_MANUALLY_FINISH_CP__STEP_MOCK, - CHERRYPICK__CHERRYPICK__ANNOUNCES_A_CP_FAILURE_IN_THE_ANNOUNCE_SLACK_ROOM__STEP_MOCK, -]; - -export default {CHERRYPICK__CREATENEWVERSION__STEP_MOCKS, CHERRYPICK__VALIDATEACTOR__FALSE__STEP_MOCKS, CHERRYPICK__VALIDATEACTOR__TRUE__STEP_MOCKS, getCherryPickMockSteps}; diff --git a/workflow_tests/mocks/claMocks.ts b/workflow_tests/mocks/claMocks.ts deleted file mode 100644 index ca065510cd4a..000000000000 --- a/workflow_tests/mocks/claMocks.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// cla -const CLA__CLA__CLA_COMMENT_CHECK__NO_MATCH__STEP_MOCK = createMockStep('CLA comment check', 'CLA comment check', 'CLA', ['text', 'regex'], [], {match: ''}); -const CLA__CLA__CLA_COMMENT_CHECK__MATCH__STEP_MOCK = createMockStep('CLA comment check', 'CLA comment check', 'CLA', ['text', 'regex'], [], { - match: 'I have read the CLA Document and I hereby sign the CLA', -}); -const CLA__CLA__CLA_COMMENT_RE_CHECK__NO_MATCH__STEP_MOCK = createMockStep('CLA comment re-check', 'CLA comment re-check', 'CLA', ['text', 'regex'], [], {match: ''}); -const CLA__CLA__CLA_COMMENT_RE_CHECK__MATCH__STEP_MOCK = createMockStep('CLA comment re-check', 'CLA comment re-check', 'CLA', ['text', 'regex'], [], {match: 'recheck'}); -const CLA__CLA__CLA_ASSISTANT__STEP_MOCK = createMockStep( - 'CLA Assistant', - 'CLA Assistant', - 'CLA', - ['path-to-signatures', 'path-to-document', 'branch', 'remote-organization-name', 'remote-repository-name', 'lock-pullrequest-aftermerge', 'allowlist'], - ['GITHUB_TOKEN', 'PERSONAL_ACCESS_TOKEN'], -); -const CLA__CLA__NO_MATCHES__STEP_MOCKS = [CLA__CLA__CLA_COMMENT_CHECK__NO_MATCH__STEP_MOCK, CLA__CLA__CLA_COMMENT_RE_CHECK__NO_MATCH__STEP_MOCK, CLA__CLA__CLA_ASSISTANT__STEP_MOCK]; -const CLA__CLA__CHECK_MATCH__STEP_MOCKS = [CLA__CLA__CLA_COMMENT_CHECK__MATCH__STEP_MOCK, CLA__CLA__CLA_COMMENT_RE_CHECK__NO_MATCH__STEP_MOCK, CLA__CLA__CLA_ASSISTANT__STEP_MOCK]; -const CLA__CLA__RECHECK_MATCH__STEP_MOCKS = [CLA__CLA__CLA_COMMENT_CHECK__NO_MATCH__STEP_MOCK, CLA__CLA__CLA_COMMENT_RE_CHECK__MATCH__STEP_MOCK, CLA__CLA__CLA_ASSISTANT__STEP_MOCK]; - -export {CLA__CLA__NO_MATCHES__STEP_MOCKS, CLA__CLA__CHECK_MATCH__STEP_MOCKS, CLA__CLA__RECHECK_MATCH__STEP_MOCKS}; diff --git a/workflow_tests/mocks/createNewVersionMocks.ts b/workflow_tests/mocks/createNewVersionMocks.ts deleted file mode 100644 index dd094e6459e8..000000000000 --- a/workflow_tests/mocks/createNewVersionMocks.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -import {createMockStep} from '../utils/utils'; - -// validateactor -const CREATENEWVERSION__VALIDATEACTOR__GET_USER_PERMISSIONS__ADMIN__STEP_MOCK = createMockStep('Get user permissions', 'Get user permissions', 'VALIDATEACTOR', [], ['GITHUB_TOKEN'], { - PERMISSION: 'admin', -}); -const CREATENEWVERSION__VALIDATEACTOR__GET_USER_PERMISSIONS__WRITE__STEP_MOCK = createMockStep('Get user permissions', 'Get user permissions', 'VALIDATEACTOR', [], ['GITHUB_TOKEN'], { - PERMISSION: 'write', -}); -const CREATENEWVERSION__VALIDATEACTOR__GET_USER_PERMISSIONS__NONE__STEP_MOCK = createMockStep('Get user permissions', 'Get user permissions', 'VALIDATEACTOR', [], ['GITHUB_TOKEN'], { - PERMISSION: 'read', -}); -const CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS = [CREATENEWVERSION__VALIDATEACTOR__GET_USER_PERMISSIONS__ADMIN__STEP_MOCK] as const satisfies StepIdentifier[]; -const CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS = [CREATENEWVERSION__VALIDATEACTOR__GET_USER_PERMISSIONS__WRITE__STEP_MOCK] as const satisfies StepIdentifier[]; -const CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS = [CREATENEWVERSION__VALIDATEACTOR__GET_USER_PERMISSIONS__NONE__STEP_MOCK] as const satisfies StepIdentifier[]; - -// createnewversion -const CREATENEWVERSION__CREATENEWVERSION__RUN_TURNSTYLE__STEP_MOCK = createMockStep('Run turnstyle', 'Run turnstyle', 'CREATENEWVERSION', ['poll-interval-seconds'], ['GITHUB_TOKEN']); -const CREATENEWVERSION__CREATENEWVERSION__CHECK_OUT__STEP_MOCK = createMockStep('Check out', 'Check out', 'CREATENEWVERSION', ['ref', 'token'], []); -const CREATENEWVERSION__CREATENEWVERSION__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK = createMockStep('Setup git for OSBotify', 'Setup git for OSBotify', 'CREATENEWVERSION', ['GPG_PASSPHRASE'], []); -const CREATENEWVERSION__CREATENEWVERSION__GENERATE_VERSION__STEP_MOCK = createMockStep('Generate version', 'Generate version', 'CREATENEWVERSION', ['GITHUB_TOKEN', 'SEMVER_LEVEL'], []); -const CREATENEWVERSION__CREATENEWVERSION__COMMIT_NEW_VERSION__STEP_MOCK = createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], []); -const CREATENEWVERSION__CREATENEWVERSION__UPDATE_MAIN_BRANCH__STEP_MOCK = createMockStep('Update main branch', 'Update main branch', 'CREATENEWVERSION', [], []); -const CREATENEWVERSION__CREATENEWVERSION__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK = createMockStep( - 'Announce failed workflow in Slack', - 'Announce failed workflow in Slack', - 'CREATENEWVERSION', - ['SLACK_WEBHOOK'], - [], -); -const CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS = [ - CREATENEWVERSION__CREATENEWVERSION__RUN_TURNSTYLE__STEP_MOCK, - CREATENEWVERSION__CREATENEWVERSION__CHECK_OUT__STEP_MOCK, - CREATENEWVERSION__CREATENEWVERSION__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - CREATENEWVERSION__CREATENEWVERSION__GENERATE_VERSION__STEP_MOCK, - CREATENEWVERSION__CREATENEWVERSION__COMMIT_NEW_VERSION__STEP_MOCK, - CREATENEWVERSION__CREATENEWVERSION__UPDATE_MAIN_BRANCH__STEP_MOCK, - CREATENEWVERSION__CREATENEWVERSION__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -export default { - CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS, - CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS, - CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS, - CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/deployBlockerMocks.ts b/workflow_tests/mocks/deployBlockerMocks.ts deleted file mode 100644 index b60d41383a1e..000000000000 --- a/workflow_tests/mocks/deployBlockerMocks.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -import {createMockStep} from '../utils/utils'; - -// updateChecklist -const DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCK = createMockStep('updateChecklist', 'Run updateChecklist', 'UPDATECHECKLIST'); -const DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS = [DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCK] as const satisfies StepIdentifier[]; - -// deployblocker -const DEPLOYBLOCKER__DEPLOYBLOCKER__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'DEPLOYBLOCKER'); -const DEPLOYBLOCKER__DEPLOYBLOCKER__GIVE_LABELS__STEP_MOCK = createMockStep( - 'Give the issue/PR the Hourly, Engineering labels', - 'Give the issue/PR the Hourly, Engineering labels', - 'DEPLOYBLOCKER', - [], - ['GITHUB_TOKEN'], -); -const DEPLOYBLOCKER__DEPLOYBLOCKER__POST_THE_ISSUE_IN_THE_EXPENSIFY_OPEN_SOURCE_SLACK_ROOM__STEP_MOCK = createMockStep( - 'Post the issue in the #expensify-open-source slack room', - 'Post the issue in the expensify-open-source slack room', - 'DEPLOYBLOCKER', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); -const DEPLOYBLOCKER__DEPLOYBLOCKER__COMMENT_ON_DEPLOY_BLOCKER__STEP_MOCK = createMockStep('Comment on deploy blocker', 'Comment on deploy blocker', 'DEPLOYBLOCKER', [], ['GITHUB_TOKEN']); -const DEPLOYBLOCKER__DEPLOYBLOCKER__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK = createMockStep( - 'Announce failed workflow in Slack', - 'Announce failed workflow in Slack', - 'DEPLOYBLOCKER', - ['SLACK_WEBHOOK'], - [], -); -const DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS = [ - DEPLOYBLOCKER__DEPLOYBLOCKER__CHECKOUT__STEP_MOCK, - DEPLOYBLOCKER__DEPLOYBLOCKER__GIVE_LABELS__STEP_MOCK, - DEPLOYBLOCKER__DEPLOYBLOCKER__POST_THE_ISSUE_IN_THE_EXPENSIFY_OPEN_SOURCE_SLACK_ROOM__STEP_MOCK, - DEPLOYBLOCKER__DEPLOYBLOCKER__COMMENT_ON_DEPLOY_BLOCKER__STEP_MOCK, - DEPLOYBLOCKER__DEPLOYBLOCKER__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -export default {DEPLOYBLOCKER__UPDATECHECKLIST__STEP_MOCKS, DEPLOYBLOCKER__DEPLOYBLOCKER__STEP_MOCKS}; diff --git a/workflow_tests/mocks/deployMocks.ts b/workflow_tests/mocks/deployMocks.ts deleted file mode 100644 index 1fe5071133d7..000000000000 --- a/workflow_tests/mocks/deployMocks.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -import {createMockStep} from '../utils/utils'; - -const DEPLOY_STAGING__CHECKOUT__STEP_MOCK = createMockStep('Checkout staging branch', 'Checking out staging branch', 'DEPLOY_STAGING', ['ref', 'token']); -const DEPLOY_STAGING__SETUP_GIT__STEP_MOCK = createMockStep('Setup git for OSBotify', 'Setting up git for OSBotify', 'DEPLOY_STAGING', [ - 'GPG_PASSPHRASE', - 'OS_BOTIFY_APP_ID', - 'OS_BOTIFY_PRIVATE_KEY', -]); -const DEPLOY_STAGING__TAG_VERSION__STEP_MOCK = createMockStep('Tag version', 'Tagging new version', 'DEPLOY_STAGING'); -const DEPLOY_STAGING__PUSH_TAG__STEP_MOCK = createMockStep('🚀 Push tags to trigger staging deploy 🚀', 'Pushing tag to trigger staging deploy', 'DEPLOY_STAGING'); -const DEPLOY_STAGING__WARN_DEPLOYERS__STEP_MOCK = createMockStep('Warn deployers if staging deploy failed', 'Warning deployers in slack for workflow failure', 'DEPLOY_STAGING'); -const DEPLOY_STAGING_STEP_MOCKS = [ - DEPLOY_STAGING__CHECKOUT__STEP_MOCK, - DEPLOY_STAGING__SETUP_GIT__STEP_MOCK, - DEPLOY_STAGING__TAG_VERSION__STEP_MOCK, - DEPLOY_STAGING__PUSH_TAG__STEP_MOCK, - DEPLOY_STAGING__WARN_DEPLOYERS__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -const DEPLOY_PRODUCTION__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'DEPLOY_PRODUCTION', ['ref', 'token']); -const DEPLOY_PRODUCTION__SETUP_GIT__STEP_MOCK = createMockStep( - 'Setup git for OSBotify', - 'Setting up git for OSBotify', - 'DEPLOY_PRODUCTION', - ['GPG_PASSPHRASE', 'OS_BOTIFY_APP_ID', 'OS_BOTIFY_PRIVATE_KEY'], - null, - {OS_BOTIFY_API_TOKEN: 'os_botify_api_token'}, -); -const DEPLOY_PRODUCTION__CURRENT_APP_VERSION__STEP_MOCK = createMockStep('Get current app version', 'Getting current app version', 'DEPLOY_PRODUCTION', null, null, null, { - PRODUCTION_VERSION: '1.2.3', -}); -const DEPLOY_PRODUCTION__CREATE_RELEASE__STEP_MOCK = createMockStep( - '🚀 Create release to trigger production deploy 🚀', - 'Creating release to trigger production deploy', - 'DEPLOY_PRODUCTION', - [], - ['GITHUB_TOKEN'], -); -const DEPLOY_PRODUCTION__WARN_DEPLOYERS__STEP_MOCK = createMockStep('Warn deployers if production deploy failed', 'Warning deployers in slack for workflow failure', 'DEPLOY_STAGING'); -const DEPLOY_PRODUCTION_STEP_MOCKS = [ - DEPLOY_PRODUCTION__CHECKOUT__STEP_MOCK, - DEPLOY_PRODUCTION__SETUP_GIT__STEP_MOCK, - DEPLOY_PRODUCTION__CURRENT_APP_VERSION__STEP_MOCK, - DEPLOY_PRODUCTION__CREATE_RELEASE__STEP_MOCK, - DEPLOY_PRODUCTION__WARN_DEPLOYERS__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -export default {DEPLOY_STAGING_STEP_MOCKS, DEPLOY_PRODUCTION_STEP_MOCKS}; diff --git a/workflow_tests/mocks/failureNotifierMocks.ts b/workflow_tests/mocks/failureNotifierMocks.ts deleted file mode 100644 index ca4009aef952..000000000000 --- a/workflow_tests/mocks/failureNotifierMocks.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ - -/* eslint-disable rulesdir/no-negated-variables */ -import {createMockStep} from '../utils/utils'; - -// notifyfailure -const FAILURENOTIFIER__NOTIFYFAILURE__FETCH_WORKFLOW_RUN_JOBS__STEP_MOCK = createMockStep('Fetch Workflow Run Jobs', 'Fetch Workflow Run Jobs', 'NOTIFYFAILURE', [], []); -const FAILURENOTIFIER__NOTIFYFAILURE_FETCH_PREVIOUS_WORKFLOW_RUN__STEP_MOCK = createMockStep('Fetch Previous Workflow Run', 'Fetch Previous Workflow Run', 'NOTIFYFAILURE', [], []); -const FAILURENOTIFIER__NOTIFYFAILURE_FETCH_PREVIOUS_WORKFLOW_RUN_JOBS__STEP_MOCK = createMockStep( - 'Fetch Previous Workflow Run Jobs', - 'Fetch Previous Workflow Run Jobs', - 'NOTIFYFAILURE', - [], - [], -); -const FAILURENOTIFIER__NOTIFYFAILURE__PROCESS_EACH_FAILED_JOB__STEP_MOCK = createMockStep('Process Each Failed Job', 'Process Each Failed Job', 'NOTIFYFAILURE', [], []); - -const FAILURENOTIFIER__NOTIFYFAILURE__STEP_MOCKS = [ - FAILURENOTIFIER__NOTIFYFAILURE__FETCH_WORKFLOW_RUN_JOBS__STEP_MOCK, - FAILURENOTIFIER__NOTIFYFAILURE_FETCH_PREVIOUS_WORKFLOW_RUN__STEP_MOCK, - FAILURENOTIFIER__NOTIFYFAILURE_FETCH_PREVIOUS_WORKFLOW_RUN_JOBS__STEP_MOCK, - FAILURENOTIFIER__NOTIFYFAILURE__PROCESS_EACH_FAILED_JOB__STEP_MOCK, -]; - -export default { - FAILURENOTIFIER__NOTIFYFAILURE__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/finishReleaseCycleMocks.ts b/workflow_tests/mocks/finishReleaseCycleMocks.ts deleted file mode 100644 index 23d81a557705..000000000000 --- a/workflow_tests/mocks/finishReleaseCycleMocks.ts +++ /dev/null @@ -1,178 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -import {createMockStep} from '../utils/utils'; - -// validate -const FINISHRELEASECYCLE__VALIDATE__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'VALIDATE', ['ref', 'token']); -const FINISHRELEASECYCLE__VALIDATE__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK = createMockStep( - 'Setup git for OSBotify', - 'Setup git for OSBotify', - 'VALIDATE', - ['GPG_PASSPHRASE', 'OS_BOTIFY_APP_ID', 'OS_BOTIFY_PRIVATE_KEY'], - [], - {OS_BOTIFY_API_TOKEN: 'os_botify_api_token'}, -); -const FINISHRELEASECYCLE__VALIDATE__VALIDATE_ACTOR_IS_DEPLOYER_TRUE__STEP_MOCK = createMockStep( - 'Validate actor is deployer', - 'Validating if actor is deployer', - 'VALIDATE', - [], - ['GITHUB_TOKEN'], - {IS_DEPLOYER: true}, -); -const FINISHRELEASECYCLE__VALIDATE__VALIDATE_ACTOR_IS_DEPLOYER_FALSE__STEP_MOCK = createMockStep( - 'Validate actor is deployer', - 'Validating if actor is deployer', - 'VALIDATE', - [], - ['GITHUB_TOKEN'], - {IS_DEPLOYER: false}, -); -// eslint-disable-next-line rulesdir/no-negated-variables -const FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_NOT_A_TEAM_MEMBER__STEP_MOCK = createMockStep( - 'Reopen and comment on issue (not a team member)', - 'Reopening issue - not a team member', - 'VALIDATE', - ['GITHUB_TOKEN', 'ISSUE_NUMBER', 'COMMENT'], - [], -); -const FINISHRELEASECYCLE__VALIDATE__CHECK_FOR_ANY_DEPLOY_BLOCKERS_FALSE__STEP_MOCK = createMockStep( - 'Check for any deploy blockers', - 'Checking for deploy blockers', - 'VALIDATE', - ['GITHUB_TOKEN', 'ISSUE_NUMBER'], - [], - {HAS_DEPLOY_BLOCKERS: false}, -); -const FINISHRELEASECYCLE__VALIDATE__CHECK_FOR_ANY_DEPLOY_BLOCKERS_TRUE__STEP_MOCK = createMockStep( - 'Check for any deploy blockers', - 'Checking for deploy blockers', - 'VALIDATE', - ['GITHUB_TOKEN', 'ISSUE_NUMBER'], - [], - {HAS_DEPLOY_BLOCKERS: true}, -); -const FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_HAS_BLOCKERS__STEP_MOCK = createMockStep( - 'Reopen and comment on issue (has blockers)', - 'Reopening issue - blockers', - 'VALIDATE', - ['GITHUB_TOKEN', 'ISSUE_NUMBER'], - [], -); -const FINISHRELEASECYCLE__VALIDATE__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK = createMockStep( - 'Announce failed workflow in Slack', - 'Announce failed workflow in Slack', - 'VALIDATE', - ['SLACK_WEBHOOK'], - [], -); -const FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS = [ - FINISHRELEASECYCLE__VALIDATE__CHECKOUT__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__VALIDATE_ACTOR_IS_DEPLOYER_TRUE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_NOT_A_TEAM_MEMBER__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__CHECK_FOR_ANY_DEPLOY_BLOCKERS_FALSE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_HAS_BLOCKERS__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; -const FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_BLOCKERS__STEP_MOCKS = [ - FINISHRELEASECYCLE__VALIDATE__CHECKOUT__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__VALIDATE_ACTOR_IS_DEPLOYER_TRUE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_NOT_A_TEAM_MEMBER__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__CHECK_FOR_ANY_DEPLOY_BLOCKERS_TRUE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_HAS_BLOCKERS__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; -// eslint-disable-next-line rulesdir/no-negated-variables -const FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS = [ - FINISHRELEASECYCLE__VALIDATE__CHECKOUT__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__VALIDATE_ACTOR_IS_DEPLOYER_FALSE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_NOT_A_TEAM_MEMBER__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__CHECK_FOR_ANY_DEPLOY_BLOCKERS_FALSE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_HAS_BLOCKERS__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; -// eslint-disable-next-line rulesdir/no-negated-variables -const FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_BLOCKERS__STEP_MOCKS = [ - FINISHRELEASECYCLE__VALIDATE__CHECKOUT__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__VALIDATE_ACTOR_IS_DEPLOYER_FALSE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_NOT_A_TEAM_MEMBER__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__CHECK_FOR_ANY_DEPLOY_BLOCKERS_TRUE__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__REOPEN_AND_COMMENT_ON_ISSUE_HAS_BLOCKERS__STEP_MOCK, - FINISHRELEASECYCLE__VALIDATE__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -]; - -// updateproduction -const FINISHRELEASECYCLE__UPDATEPRODUCTION__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'UPDATEPRODUCTION', ['ref', 'token'], []); -const FINISHRELEASECYCLE__UPDATEPRODUCTION__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK = createMockStep( - 'Setup git for OSBotify', - 'Setup git for OSBotify', - 'UPDATEPRODUCTION', - ['GPG_PASSPHRASE'], - [], -); -const FINISHRELEASECYCLE__UPDATEPRODUCTION__UPDATE_PRODUCTION_BRANCH__STEP_MOCK = createMockStep('Update production branch', 'Updating production branch', 'UPDATEPRODUCTION', [], []); -const FINISHRELEASECYCLE__UPDATEPRODUCTION__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK = createMockStep( - 'Announce failed workflow in Slack', - 'Announce failed workflow in Slack', - 'UPDATEPRODUCTION', - ['SLACK_WEBHOOK'], - [], -); -const FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS = [ - FINISHRELEASECYCLE__UPDATEPRODUCTION__CHECKOUT__STEP_MOCK, - FINISHRELEASECYCLE__UPDATEPRODUCTION__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - FINISHRELEASECYCLE__UPDATEPRODUCTION__UPDATE_PRODUCTION_BRANCH__STEP_MOCK, - FINISHRELEASECYCLE__UPDATEPRODUCTION__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -// createnewpatchversion -const FINISHRELEASECYCLE__CREATENEWPATCHVERSION__CREATE_NEW_VERSION__STEP_MOCK = createMockStep( - 'Create new version', - 'Creating new version', - 'CREATENEWPATCHVERSION', - ['SEMVER_LEVEL'], - [], - {NEW_VERSION: '1.2.3'}, - null, - true, - 'createNewVersion', -); -const FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS = [FINISHRELEASECYCLE__CREATENEWPATCHVERSION__CREATE_NEW_VERSION__STEP_MOCK] as const satisfies StepIdentifier[]; - -// updatestaging -const FINISHRELEASECYCLE__UPDATESTAGING__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'UPDATESTAGING', ['ref', 'token'], []); -const FINISHRELEASECYCLE__UPDATESTAGING__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK = createMockStep('Setup git for OSBotify', 'Setup git for OSBotify', 'UPDATESTAGING', ['GPG_PASSPHRASE'], []); -const FINISHRELEASECYCLE__UPDATESTAGING__UPDATE_STAGING_BRANCH_TO_TRIGGER_STAGING_DEPLOY__STEP_MOCK = createMockStep( - 'Update staging branch to trigger staging deploy', - 'Updating staging branch', - 'UPDATESTAGING', - [], - [], -); -const FINISHRELEASECYCLE__UPDATESTAGING__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK = createMockStep( - 'Announce failed workflow in Slack', - 'Announce failed workflow in Slack', - 'UPDATESTAGING', - ['SLACK_WEBHOOK'], - [], -); -const FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS = [ - FINISHRELEASECYCLE__UPDATESTAGING__CHECKOUT__STEP_MOCK, - FINISHRELEASECYCLE__UPDATESTAGING__SETUP_GIT_FOR_OSBOTIFY__STEP_MOCK, - FINISHRELEASECYCLE__UPDATESTAGING__UPDATE_STAGING_BRANCH_TO_TRIGGER_STAGING_DEPLOY__STEP_MOCK, - FINISHRELEASECYCLE__UPDATESTAGING__ANNOUNCE_FAILED_WORKFLOW_IN_SLACK__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -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, - FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_BLOCKERS__STEP_MOCKS, - FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS, - FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS, - FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/lintMocks.ts b/workflow_tests/mocks/lintMocks.ts deleted file mode 100644 index 27ce53afc1f4..000000000000 --- a/workflow_tests/mocks/lintMocks.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {StepIdentifier} from '@kie/act-js'; -import {createMockStep} from '../utils/utils'; - -// lint -const LINT__LINT__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'LINT', [], []); -const LINT__LINT__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'LINT', [], []); -const LINT__LINT__LINT_JAVASCRIPT_WITH_ESLINT__STEP_MOCK = createMockStep('Lint JavaScript and Typescript with ESLint', 'Lint JavaScript with ESLint', 'LINT', [], ['CI']); -const LINT__LINT__VERIFY_NO_PRETTIER__STEP_MOCK = createMockStep("Verify there's no Prettier diff", 'Verify theres no Prettier diff', 'LINT'); -const LINT__LINT__RUN_UNUSED_SEARCHER__STEP_MOCK = createMockStep('Run unused style searcher', 'Run unused style searcher', 'LINT'); -const LINT__LINT__STEP_MOCKS = [ - LINT__LINT__CHECKOUT__STEP_MOCK, - LINT__LINT__SETUP_NODE__STEP_MOCK, - LINT__LINT__LINT_JAVASCRIPT_WITH_ESLINT__STEP_MOCK, - LINT__LINT__VERIFY_NO_PRETTIER__STEP_MOCK, - LINT__LINT__RUN_UNUSED_SEARCHER__STEP_MOCK, -] as const satisfies StepIdentifier[]; - -export default {LINT__LINT__STEP_MOCKS}; diff --git a/workflow_tests/mocks/lockDeploysMocks.ts b/workflow_tests/mocks/lockDeploysMocks.ts deleted file mode 100644 index 138b30fbb306..000000000000 --- a/workflow_tests/mocks/lockDeploysMocks.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// lockstagingdeploys -const LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'LOCKSTAGINGDEPLOYS', ['ref', 'token'], []); -const LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__WAIT_FOR_STAGING_DEPLOYS_TO_FINISH__STEP_MOCK = createMockStep( - 'Wait for staging deploys to finish', - 'Waiting for staging deploys to finish', - 'LOCKSTAGINGDEPLOYS', - ['GITHUB_TOKEN'], - [], -); -const LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__COMMENT_IN_STAGINGDEPLOYCASH_TO_GIVE_APPLAUSE_THE_GREEN_LIGHT_TO_BEGIN_QA__STEP_MOCK = createMockStep( - 'Comment in StagingDeployCash to give Applause the 🟢 to begin QA', - 'Commenting in StagingDeployCash', - 'LOCKSTAGINGDEPLOYS', - [], - ['GITHUB_TOKEN'], -); -const LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__ANNOUNCE_FAILED_WORKFLOW__STEP_MOCK = createMockStep( - 'Announce failed workflow', - 'Announcing failed workflow in Slack', - 'LOCKSTAGINGDEPLOYS', - ['SLACK_WEBHOOK'], - [], -); -const LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS = [ - LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__CHECKOUT__STEP_MOCK, - LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__WAIT_FOR_STAGING_DEPLOYS_TO_FINISH__STEP_MOCK, - LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__COMMENT_IN_STAGINGDEPLOYCASH_TO_GIVE_APPLAUSE_THE_GREEN_LIGHT_TO_BEGIN_QA__STEP_MOCK, - LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__ANNOUNCE_FAILED_WORKFLOW__STEP_MOCK, -]; - -export default { - LOCKDEPLOYS__LOCKSTAGINGDEPLOYS__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/platformDeployMocks.ts b/workflow_tests/mocks/platformDeployMocks.ts deleted file mode 100644 index 3aae07ec1c5a..000000000000 --- a/workflow_tests/mocks/platformDeployMocks.ts +++ /dev/null @@ -1,286 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// validateActor -const PLATFORM_DEPLOY__VALIDATE_ACTOR__CHECK_USER_DEPLOYER__TEAM_MEMBER__STEP_MOCK = createMockStep( - 'Check if user is deployer', - 'Checking if the user is a deployer', - 'VALIDATE_ACTOR', - [], - ['GITHUB_TOKEN'], - {IS_DEPLOYER: true}, -); -const PLATFORM_DEPLOY__VALIDATE_ACTOR__CHECK_USER_DEPLOYER__OUTSIDER__STEP_MOCK = createMockStep( - 'Check if user is deployer', - 'Checking if the user is a deployer', - 'VALIDATE_ACTOR', - [], - ['GITHUB_TOKEN'], - {IS_DEPLOYER: false}, -); -const PLATFORM_DEPLOY__VALIDATE_ACTOR__TEAM_MEMBER__STEP_MOCKS = [PLATFORM_DEPLOY__VALIDATE_ACTOR__CHECK_USER_DEPLOYER__TEAM_MEMBER__STEP_MOCK]; -const PLATFORM_DEPLOY__VALIDATE_ACTOR__OUTSIDER__STEP_MOCKS = [PLATFORM_DEPLOY__VALIDATE_ACTOR__CHECK_USER_DEPLOYER__OUTSIDER__STEP_MOCK]; - -// deployChecklist -const PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCK = createMockStep('deployChecklist', 'Run deployChecklist', 'DEPLOY_CHECKLIST'); -const PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCKS = [PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCK]; - -// android -const PLATFORM_DEPLOY__ANDROID__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'ANDROID'); -const PLATFORM_DEPLOY__ANDROID__CONFIGURE_MAPBOX_SDK__STEP_MOCK = createMockStep('Configure MapBox SDK', 'Configure MapBox SDK', 'ANDROID'); -const PLATFORM_DEPLOY__ANDROID__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setting up Node', 'ANDROID'); -const PLATFORM_DEPLOY__ANDROID__SETUP_JAVA__STEP_MOCK = createMockStep('Setup Java', 'Setup Java', 'ANDROID', ['distribution', 'java-version'], []); -const PLATFORM_DEPLOY__ANDROID__SETUP_RUBY__STEP_MOCK = createMockStep('Setup Ruby', 'Setting up Ruby', 'ANDROID', ['ruby-version', 'bundler-cache']); -const PLATFORM_DEPLOY__ANDROID__DECRYPT_KEYSTORE__STEP_MOCK = createMockStep('Decrypt keystore', 'Decrypting keystore', 'ANDROID', null, ['LARGE_SECRET_PASSPHRASE']); -const PLATFORM_DEPLOY__ANDROID__DECRYPT_JSON_KEY__STEP_MOCK = createMockStep('Decrypt json key', 'Decrypting JSON key', 'ANDROID', null, ['LARGE_SECRET_PASSPHRASE']); -const PLATFORM_DEPLOY__ANDROID__SET_VERSION__STEP_MOCK = createMockStep('Set version in ENV', 'Setting version in ENV', 'ANDROID', null, null, null, {VERSION_CODE: '1.2.3'}); -const PLATFORM_DEPLOY__ANDROID__FASTLANE__STEP_MOCK = createMockStep('Run Fastlane', 'Running Fastlane', 'ANDROID', null, [ - 'RUBYOPT', - 'MYAPP_UPLOAD_STORE_PASSWORD', - 'MYAPP_UPLOAD_KEY_PASSWORD', - 'VERSION', -]); -const PLATFORM_DEPLOY__ANDROID__ARCHIVE_SOURCEMAPS__STEP_MOCK = createMockStep('Archive Android sourcemaps', 'Archiving Android sourcemaps', 'ANDROID', ['name', 'path']); -const PLATFORM_DEPLOY__ANDROID__UPLOAD_TO_GITHUB_ARTIFACTS__STEP_MOCK = createMockStep('Upload Android build to GitHub artifacts', 'Uploading Android build to GitHub artifacts', 'ANDROID', [ - 'name', - 'path', -]); -const PLATFORM_DEPLOY__ANDROID__UPLOAD_TO_BROWSER_STACK__STEP_MOCK = createMockStep('Upload Android build to Browser Stack', 'Uploading Android build to Browser Stack', 'ANDROID', null, [ - 'BROWSERSTACK', -]); -const PLATFORM_DEPLOY__ANDROID__UPLOAD_TO_GH_RELEASE__STEP_MOCK = createMockStep('Upload Android build to GitHub Release', 'Uploading Android build to GitHub Release', 'ANDROID', null, [ - 'GITHUB_TOKEN', -]); -const PLATFORM_DEPLOY__ANDROID__WARN_DEPLOYERS__STEP_MOCK = createMockStep( - 'Warn deployers if Android production deploy failed', - 'Warning deployers of failed production deploy', - 'ANDROID', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); -const PLATFORM_DEPLOY__ANDROID__STEP_MOCKS = [ - PLATFORM_DEPLOY__ANDROID__CHECKOUT__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__CONFIGURE_MAPBOX_SDK__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__SETUP_NODE__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__SETUP_JAVA__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__SETUP_RUBY__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__DECRYPT_KEYSTORE__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__DECRYPT_JSON_KEY__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__SET_VERSION__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__FASTLANE__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__ARCHIVE_SOURCEMAPS__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__UPLOAD_TO_GITHUB_ARTIFACTS__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__UPLOAD_TO_BROWSER_STACK__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__UPLOAD_TO_GH_RELEASE__STEP_MOCK, - PLATFORM_DEPLOY__ANDROID__WARN_DEPLOYERS__STEP_MOCK, -]; - -// desktop -const PLATFORM_DEPLOY__DESKTOP__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'DESKTOP'); -const PLATFORM_DEPLOY__DESKTOP__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setting up Node', 'DESKTOP'); -const PLATFORM_DEPLOY__DESKTOP__DECRYPT_ID__STEP_MOCK = createMockStep('Decrypt Developer ID Certificate', 'Decrypting developer id certificate', 'DESKTOP', null, [ - 'DEVELOPER_ID_SECRET_PASSPHRASE', -]); -const PLATFORM_DEPLOY__DESKTOP__BUILD__STEP_MOCK = createMockStep('Build desktop app', 'Building desktop app', 'DESKTOP', null, [ - 'CSC_LINK', - 'CSC_KEY_PASSWORD', - 'APPLE_ID', - 'APPLE_APP_SPECIFIC_PASSWORD', - 'AWS_ACCESS_KEY_ID', - 'AWS_SECRET_ACCESS_KEY', -]); -const PLATFORM_DEPLOY__DESKTOP__UPLOAD_WORKFLOW__STEP_MOCK = createMockStep('Upload desktop build to GitHub Workflow', 'Uploading desktop build to GitHub Workflow', 'DESKTOP', [ - 'name', - 'path', -]); -const PLATFORM_DEPLOY__DESKTOP__UPLOAD_GH_RELEASE__STEP_MOCK = createMockStep('Upload desktop build to GitHub Release', 'Uploading desktop build to GitHub Release', 'DESKTOP', null, [ - 'GITHUB_TOKEN', -]); -const PLATFORM_DEPLOY__DESKTOP__ARCHIVE_SOURCEMAPS__STEP_MOCK = createMockStep('Archive desktop sourcemaps', 'Archiving desktop sourcemaps', 'DESKTOP', ['name', 'path']); -const PLATFORM_DEPLOY__DESKTOP__STEP_MOCKS = [ - PLATFORM_DEPLOY__DESKTOP__CHECKOUT__STEP_MOCK, - PLATFORM_DEPLOY__DESKTOP__SETUP_NODE__STEP_MOCK, - PLATFORM_DEPLOY__DESKTOP__DECRYPT_ID__STEP_MOCK, - PLATFORM_DEPLOY__DESKTOP__BUILD__STEP_MOCK, - PLATFORM_DEPLOY__DESKTOP__UPLOAD_WORKFLOW__STEP_MOCK, - PLATFORM_DEPLOY__DESKTOP__UPLOAD_GH_RELEASE__STEP_MOCK, - PLATFORM_DEPLOY__DESKTOP__ARCHIVE_SOURCEMAPS__STEP_MOCK, -]; - -// ios -const PLATFORM_DEPLOY__IOS__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'IOS'); -const PLATFORM_DEPLOY__IOS__CONFIGURE_MAPBOX_SDK__STEP_MOCK = createMockStep('Configure MapBox SDK', 'Configure MapBox SDK', 'IOS'); -const PLATFORM_DEPLOY__IOS__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setting up Node', 'IOS'); -const PLATFORM_DEPLOY__IOS__SETUP_RUBY__STEP_MOCK = createMockStep('Setup Ruby', 'Setting up Ruby', 'IOS', ['ruby-version', 'bundler-cache']); -const PLATFORM_DEPLOY__IOS__CACHE_POD_DEPENDENCIES__STEP_MOCK = createMockStep('Cache Pod dependencies', 'Cache Pod dependencies', 'IOS', ['path', 'key'], [], { - 'cache-hit': false, -}); -const PLATFORM_DEPLOY__IOS__COMPARE_PODFILE_AND_MANIFEST__STEP_MOCK = createMockStep('Compare Podfile.lock and Manifest.lock', 'Compare Podfile.lock and Manifest.lock', 'IOS', [], [], { - IS_PODFILE_SAME_AS_MANIFEST: false, -}); -const PLATFORM_DEPLOY__IOS__COCOAPODS__STEP_MOCK = createMockStep('Install cocoapods', 'Installing cocoapods', 'IOS', ['timeout_minutes', 'max_attempts', 'command']); -const PLATFORM_DEPLOY__IOS__DECRYPT_APPSTORE_PROFILE__STEP_MOCK = createMockStep('Decrypt AppStore profile', 'Decrypting profile', 'IOS', null, ['LARGE_SECRET_PASSPHRASE']); -const PLATFORM_DEPLOY__IOS__DECRYPT_APPSTORE_NSE_PROFILE__STEP_MOCK = createMockStep('Decrypt AppStore Notification Service profile', 'Decrypting profile', 'IOS', null, [ - 'LARGE_SECRET_PASSPHRASE', -]); -const PLATFORM_DEPLOY__IOS__DECRYPT_CERTIFICATE__STEP_MOCK = createMockStep('Decrypt certificate', 'Decrypting certificate', 'IOS', null, ['LARGE_SECRET_PASSPHRASE']); -const PLATFORM_DEPLOY__IOS__DECRYPT_APP_STORE_API_KEY__STEP_MOCK = createMockStep('Decrypt App Store Connect API key', 'Decrypting App Store API key', 'IOS', null, [ - 'LARGE_SECRET_PASSPHRASE', -]); -const PLATFORM_DEPLOY__IOS__SET_VERSION__STEP_MOCK = createMockStep('Set iOS version in ENV', 'Setting iOS version', 'IOS', null, null, null, {IOS_VERSION: '1.2.3'}); -const PLATFORM_DEPLOY__IOS__FASTLANE__STEP_MOCK = createMockStep('Run Fastlane', 'Running Fastlane', 'IOS', null, [ - 'APPLE_CONTACT_EMAIL', - 'APPLE_CONTACT_PHONE', - 'APPLE_DEMO_EMAIL', - 'APPLE_DEMO_PASSWORD', - 'VERSION', -]); -const PLATFORM_DEPLOY__IOS__ARCHIVE_SOURCEMAPS__STEP_MOCK = createMockStep('Archive iOS sourcemaps', 'Archiving sourcemaps', 'IOS', ['name', 'path']); -const PLATFORM_DEPLOY__IOS__UPLOAD_TO_GITHUB_ARTIFACTS__STEP_MOCK = createMockStep('Upload iOS build to GitHub artifacts', 'Uploading iOS build to GitHub artifacts', 'IOS', [ - 'name', - 'path', -]); -const PLATFORM_DEPLOY__IOS__UPLOAD_BROWSERSTACK__STEP_MOCK = createMockStep('Upload iOS build to Browser Stack', 'Uploading build to Browser Stack', 'IOS', null, ['BROWSERSTACK']); -const PLATFORM_DEPLOY__IOS__UPLOAD_TO_GH_RELEASE__STEP_MOCK = createMockStep('Upload iOS build to GitHub Release', 'Uploading iOS build to GitHub Release', 'IOS', null, ['GITHUB_TOKEN']); -const PLATFORM_DEPLOY__IOS__WARN_FAIL__STEP_MOCK = createMockStep( - 'Warn deployers if iOS production deploy failed', - 'Warning developers of failed deploy', - 'IOS', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); -const PLATFORM_DEPLOY__IOS__STEP_MOCKS = [ - PLATFORM_DEPLOY__IOS__CHECKOUT__STEP_MOCK, - PLATFORM_DEPLOY__IOS__CONFIGURE_MAPBOX_SDK__STEP_MOCK, - PLATFORM_DEPLOY__IOS__SETUP_NODE__STEP_MOCK, - PLATFORM_DEPLOY__IOS__SETUP_RUBY__STEP_MOCK, - PLATFORM_DEPLOY__IOS__CACHE_POD_DEPENDENCIES__STEP_MOCK, - PLATFORM_DEPLOY__IOS__COMPARE_PODFILE_AND_MANIFEST__STEP_MOCK, - PLATFORM_DEPLOY__IOS__COCOAPODS__STEP_MOCK, - PLATFORM_DEPLOY__IOS__DECRYPT_APPSTORE_PROFILE__STEP_MOCK, - PLATFORM_DEPLOY__IOS__DECRYPT_APPSTORE_NSE_PROFILE__STEP_MOCK, - PLATFORM_DEPLOY__IOS__DECRYPT_CERTIFICATE__STEP_MOCK, - PLATFORM_DEPLOY__IOS__DECRYPT_APP_STORE_API_KEY__STEP_MOCK, - PLATFORM_DEPLOY__IOS__SET_VERSION__STEP_MOCK, - PLATFORM_DEPLOY__IOS__FASTLANE__STEP_MOCK, - PLATFORM_DEPLOY__IOS__ARCHIVE_SOURCEMAPS__STEP_MOCK, - PLATFORM_DEPLOY__IOS__UPLOAD_TO_GITHUB_ARTIFACTS__STEP_MOCK, - PLATFORM_DEPLOY__IOS__UPLOAD_BROWSERSTACK__STEP_MOCK, - PLATFORM_DEPLOY__IOS__UPLOAD_TO_GH_RELEASE__STEP_MOCK, - PLATFORM_DEPLOY__IOS__WARN_FAIL__STEP_MOCK, -]; - -// web -const PLATFORM_DEPLOY__WEB__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'WEB'); -const PLATFORM_DEPLOY__WEB__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setting up Node', 'WEB'); -const PLATFORM_DEPLOY__WEB__CLOUDFLARE__STEP_MOCK = createMockStep('Setup Cloudflare CLI', 'Setting up Cloudflare CLI', 'WEB'); -const PLATFORM_DEPLOY__WEB__AWS_CREDENTIALS__STEP_MOCK = createMockStep('Configure AWS Credentials', 'Configuring AWS credentials', 'WEB', [ - 'aws-access-key-id', - 'aws-secret-access-key', - 'aws-region', -]); -const PLATFORM_DEPLOY__WEB__BUILD__STEP_MOCK = createMockStep('Build web', 'Building web', 'WEB'); -const PLATFORM_DEPLOY__WEB__BUILD_STORYBOOK_DOCS__STEP_MOCK = createMockStep('Build storybook docs', 'Build storybook docs', 'WEB'); -const PLATFORM_DEPLOY__WEB__DEPLOY_S3__STEP_MOCK = createMockStep('Deploy to S3', 'Deploying to S3', 'WEB'); -const PLATFORM_DEPLOY__WEB__PURGE_CLOUDFLARE_CACHE__STEP_MOCK = createMockStep('Purge Cloudflare cache', 'Purging Cloudflare cache', 'WEB', null, ['CF_API_KEY']); -const PLATFORM_DEPLOY__WEB__VERIFY_STAGING_DEPLOY = createMockStep('Verify staging deploy', 'Verifying staging deploy', 'WEB'); -const PLATFORM_DEPLOY__WEB__VERIFY_PROD_DEPLOY = createMockStep('Verify production deploy', 'Verifying production deploy', 'WEB'); -const PLATFORM_DEPLOY__WEB__UPlOAD_TO_GH_ARTIFACTS__STEP_MOCK = createMockStep('Upload web build to GitHub artifacts', 'Uploading web build to GitHub artifacts', 'WEB'); -const PLATFORM_DEPLOY__WEB__UPLOAD_TO_GH_RELEASE__STEP_MOCK = createMockStep('Upload web build to GitHub Release', 'Uploading web build to GitHub Release', 'WEB', null, ['GITHUB_TOKEN']); -const PLATFORM_DEPLOY__WEB__ARCHIVE_SOURCEMAPS__STEP_MOCK = createMockStep('Archive web sourcemaps', 'Archiving web sourcemaps', 'WEB', ['name', 'path']); -const PLATFORM_DEPLOY__WEB__STEP_MOCKS = [ - PLATFORM_DEPLOY__WEB__CHECKOUT__STEP_MOCK, - PLATFORM_DEPLOY__WEB__SETUP_NODE__STEP_MOCK, - PLATFORM_DEPLOY__WEB__CLOUDFLARE__STEP_MOCK, - PLATFORM_DEPLOY__WEB__AWS_CREDENTIALS__STEP_MOCK, - PLATFORM_DEPLOY__WEB__BUILD__STEP_MOCK, - PLATFORM_DEPLOY__WEB__BUILD_STORYBOOK_DOCS__STEP_MOCK, - PLATFORM_DEPLOY__WEB__DEPLOY_S3__STEP_MOCK, - PLATFORM_DEPLOY__WEB__ARCHIVE_SOURCEMAPS__STEP_MOCK, - PLATFORM_DEPLOY__WEB__PURGE_CLOUDFLARE_CACHE__STEP_MOCK, - PLATFORM_DEPLOY__WEB__VERIFY_STAGING_DEPLOY, - PLATFORM_DEPLOY__WEB__VERIFY_PROD_DEPLOY, - PLATFORM_DEPLOY__WEB__UPlOAD_TO_GH_ARTIFACTS__STEP_MOCK, - PLATFORM_DEPLOY__WEB__UPLOAD_TO_GH_RELEASE__STEP_MOCK, -]; - -// post slack message on failure -const PLATFORM_DEPLOY__POST_SLACK_FAIL__POST_SLACK__STEP_MOCK = createMockStep('Post Slack message on failure', 'Posting Slack message on platform deploy failure', 'POST_SLACK_FAIL', [ - 'SLACK_WEBHOOK', -]); -const PLATFORM_DEPLOY__POST_SLACK_FAIL__STEP_MOCKS = [PLATFORM_DEPLOY__POST_SLACK_FAIL__POST_SLACK__STEP_MOCK]; - -// post slack message on success -const PLATFORM_DEPLOY__POST_SLACK_SUCCESS__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'POST_SLACK_SUCCESS'); -const PLATFORM_DEPLOY__POST_SLACK_SUCCESS__SET_VERSION__STEP_MOCK = createMockStep('Set version', 'Setting version', 'POST_SLACK_SUCCESS', null, null, null, {VERSION: '1.2.3'}); -const PLATFORM_DEPLOY__POST_SLACK_SUCCESS__ANNOUNCE_CHANNEL__STEP_MOCK = createMockStep( - 'Announces the deploy in the #announce Slack room', - 'Posting message to \\#announce channel', - 'POST_SLACK_SUCCESS', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); -const PLATFORM_DEPLOY__POST_SLACK_SUCCESS__DEPLOYER_CHANNEL__STEP_MOCK = createMockStep( - 'Announces the deploy in the #deployer Slack room', - 'Posting message to \\#deployer channel', - 'POST_SLACK_SUCCESS', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); -const PLATFORM_DEPLOY__POST_SLACK_SUCCESS__EXPENSIFY_CHANNEL__STEP_MOCK = createMockStep( - 'Announces a production deploy in the #expensify-open-source Slack room', - 'Posting message to \\#expensify-open-source channel', - 'POST_SLACK_SUCCESS', - ['status'], - ['GITHUB_TOKEN', 'SLACK_WEBHOOK_URL'], -); -const PLATFORM_DEPLOY__POST_SLACK_SUCCESS__STEP_MOCKS = [ - PLATFORM_DEPLOY__POST_SLACK_SUCCESS__CHECKOUT__STEP_MOCK, - PLATFORM_DEPLOY__POST_SLACK_SUCCESS__SET_VERSION__STEP_MOCK, - PLATFORM_DEPLOY__POST_SLACK_SUCCESS__ANNOUNCE_CHANNEL__STEP_MOCK, - PLATFORM_DEPLOY__POST_SLACK_SUCCESS__DEPLOYER_CHANNEL__STEP_MOCK, - PLATFORM_DEPLOY__POST_SLACK_SUCCESS__EXPENSIFY_CHANNEL__STEP_MOCK, -]; - -// post github comment -const PLATFORM_DEPLOY__POST_GIHUB_COMMENT__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checking out', 'POST_GITHUB_COMMENT'); -const PLATFORM_DEPLOY__POST_GIHUB_COMMENT__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setting up Node', 'POST_GITHUB_COMMENT'); -const PLATFORM_DEPLOY__POST_GIHUB_COMMENT__SET_VERSION__STEP_MOCK = createMockStep('Set version', 'Setting version', 'POST_GITHUB_COMMENT', null, null, null, {VERSION: '1.2.3'}); -const PLATFORM_DEPLOY__POST_GIHUB_COMMENT__GET_PR_LIST__STEP_MOCK = createMockStep( - 'Get Release Pull Request List', - 'Getting release pull request list', - 'POST_GITHUB_COMMENT', - ['TAG', 'GITHUB_TOKEN', 'IS_PRODUCTION_DEPLOY'], - null, - {PR_LIST: '[1.2.1, 1.2.2]'}, -); -const PLATFORM_DEPLOY__POST_GIHUB_COMMENT__COMMENT__STEP_MOCK = createMockStep('Comment on issues', 'Commenting on issues', 'POST_GITHUB_COMMENT', [ - 'PR_LIST', - 'IS_PRODUCTION_DEPLOY', - 'DEPLOY_VERSION', - 'GITHUB_TOKEN', - 'ANDROID', - 'DESKTOP', - 'IOS', - 'WEB', -]); -const PLATFORM_DEPLOY__POST_GITHUB_COMMENT__STEP_MOCKS = [ - PLATFORM_DEPLOY__POST_GIHUB_COMMENT__CHECKOUT__STEP_MOCK, - PLATFORM_DEPLOY__POST_GIHUB_COMMENT__SETUP_NODE__STEP_MOCK, - PLATFORM_DEPLOY__POST_GIHUB_COMMENT__SET_VERSION__STEP_MOCK, - PLATFORM_DEPLOY__POST_GIHUB_COMMENT__GET_PR_LIST__STEP_MOCK, - PLATFORM_DEPLOY__POST_GIHUB_COMMENT__COMMENT__STEP_MOCK, -]; - -export default { - PLATFORM_DEPLOY__VALIDATE_ACTOR__TEAM_MEMBER__STEP_MOCKS, - PLATFORM_DEPLOY__VALIDATE_ACTOR__OUTSIDER__STEP_MOCKS, - PLATFORM_DEPLOY__ANDROID__STEP_MOCKS, - PLATFORM_DEPLOY__DESKTOP__STEP_MOCKS, - PLATFORM_DEPLOY__IOS__STEP_MOCKS, - PLATFORM_DEPLOY__WEB__STEP_MOCKS, - PLATFORM_DEPLOY__POST_SLACK_FAIL__STEP_MOCKS, - PLATFORM_DEPLOY__POST_SLACK_SUCCESS__STEP_MOCKS, - PLATFORM_DEPLOY__POST_GITHUB_COMMENT__STEP_MOCKS, - PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/preDeployMocks.ts b/workflow_tests/mocks/preDeployMocks.ts deleted file mode 100644 index 12156a690804..000000000000 --- a/workflow_tests/mocks/preDeployMocks.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// typecheck -const TYPECHECK_WORKFLOW_MOCK_STEP = createMockStep('Run typecheck workflow', 'Running typecheck workflow', 'TYPECHECK'); -const TYPECHECK_JOB_MOCK_STEPS = [TYPECHECK_WORKFLOW_MOCK_STEP]; - -// lint -const LINT_WORKFLOW_MOCK_STEP = createMockStep('Run lint workflow', 'Running lint workflow', 'LINT'); -const LINT_JOB_MOCK_STEPS = [LINT_WORKFLOW_MOCK_STEP]; - -// test -const TEST_WORKFLOW_MOCK_STEP = createMockStep('Run test workflow', 'Running test workflow', 'TEST'); -const TEST_JOB_MOCK_STEPS = [TEST_WORKFLOW_MOCK_STEP]; - -// confirm_passing_build -const ANNOUNCE_IN_SLACK_MOCK_STEP = createMockStep('Announce failed workflow in Slack', 'Announcing failed workflow in slack', 'CONFIRM_PASSING_BUILD', ['SLACK_WEBHOOK']); -const CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS = [ - ANNOUNCE_IN_SLACK_MOCK_STEP, - - // 2nd step runs normally -]; - -// choose_deploy_actions -const GET_MERGED_PULL_REQUEST_MOCK_STEP__CHOOSE_DEPLOY = createMockStep('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 = createMockStep( - 'Check if StagingDeployCash is locked', - 'Checking StagingDeployCash', - 'CHOOSE_DEPLOY_ACTIONS', - ['GITHUB_TOKEN'], - null, - {IS_LOCKED: true}, -); -const CHECK_IF_STAGINGDEPLOYCASH_IS_LOCKED_MOCK_STEP__UNLOCKED = createMockStep( - '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, - - // step 3 runs 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__UNLOCKED, - - // step 3 runs normally -]; - -// skip_deploy -const COMMENT_ON_DEFERRED_PR_MOCK_STEP = createMockStep('Comment on deferred PR', 'Skipping deploy', 'SKIP_DEPLOY', ['github_token', 'number', 'body']); -const SKIP_DEPLOY_JOB_MOCK_STEPS = [COMMENT_ON_DEFERRED_PR_MOCK_STEP]; - -// create_new_version -const CREATE_NEW_VERSION_MOCK_STEP = createMockStep('Create new version', 'Creating new version', 'CREATE_NEW_VERSION', null, null, {NEW_VERSION: '1.2.3'}, null, true, 'createNewVersion'); -const CREATE_NEW_VERSION_JOB_MOCK_STEPS = [CREATE_NEW_VERSION_MOCK_STEP]; - -// update_staging -const RUN_TURNSTYLE_MOCK_STEP = createMockStep('Run turnstyle', 'Running turnstyle', 'UPDATE_STAGING', ['poll-interval-seconds'], ['GITHUB_TOKEN']); -const CHECKOUT_MAIN_MOCK_STEP = createMockStep('Checkout main', 'Checkout main', 'UPDATE_STAGING', ['ref', 'token']); -const SETUP_GIT_FOR_OSBOTIFY_MOCK_STEP = createMockStep('Setup Git for OSBotify', 'Setup Git for OSBotify', 'UPDATE_STAGING', ['GPG_PASSPHRASE']); -const UPDATE_STAGING_BRANCH_FROM_MAIN_MOCK_STEP = createMockStep('Update staging branch from main', 'Update staging branch from main', 'UPDATE_STAGING'); -const ANNOUNCE_FAILED_WORKFLOW_IN_SLACK_MOCK_STEP = createMockStep('Announce failed workflow in Slack', 'Announcing failed workflow in Slack', 'UPDATE_STAGING', ['SLACK_WEBHOOK']); -const UPDATE_STAGING_JOB_MOCK_STEPS = [ - RUN_TURNSTYLE_MOCK_STEP, - CHECKOUT_MAIN_MOCK_STEP, - SETUP_GIT_FOR_OSBOTIFY_MOCK_STEP, - UPDATE_STAGING_BRANCH_FROM_MAIN_MOCK_STEP, - ANNOUNCE_FAILED_WORKFLOW_IN_SLACK_MOCK_STEP, -]; - -const PREDEPLOY__E2EPERFORMANCETESTS__PERFORM_E2E_TESTS__MOCK_STEP = createMockStep('Perform E2E tests', 'Perform E2E tests', 'E2EPERFORMANCETESTS'); -const PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS = [PREDEPLOY__E2EPERFORMANCETESTS__PERFORM_E2E_TESTS__MOCK_STEP]; - -export default { - TYPECHECK_JOB_MOCK_STEPS, - LINT_JOB_MOCK_STEPS, - TEST_JOB_MOCK_STEPS, - CONFIRM_PASSING_BUILD_JOB_MOCK_STEPS, - CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_LOCKED, - CHOOSE_DEPLOY_ACTIONS_JOB_MOCK_STEPS__STAGING_UNLOCKED, - SKIP_DEPLOY_JOB_MOCK_STEPS, - CREATE_NEW_VERSION_JOB_MOCK_STEPS, - UPDATE_STAGING_JOB_MOCK_STEPS, - PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, -}; diff --git a/workflow_tests/mocks/reviewerChecklistMocks.ts b/workflow_tests/mocks/reviewerChecklistMocks.ts deleted file mode 100644 index 8a70c0c71597..000000000000 --- a/workflow_tests/mocks/reviewerChecklistMocks.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// checklist -const REVIEWERCHECKLIST__CHECKLIST__REVIEWERCHECKLIST_JS__STEP_MOCK = createMockStep('reviewerChecklist.js', 'reviewerChecklist.js', 'CHECKLIST', ['GITHUB_TOKEN'], []); -const REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS = [REVIEWERCHECKLIST__CHECKLIST__REVIEWERCHECKLIST_JS__STEP_MOCK]; - -export default { - REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/testBuildMocks.ts b/workflow_tests/mocks/testBuildMocks.ts deleted file mode 100644 index 643e57ddf675..000000000000 --- a/workflow_tests/mocks/testBuildMocks.ts +++ /dev/null @@ -1,261 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// validateactor -const TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__TRUE__STEP_MOCK = createMockStep('Is Expensify employee', 'Is Expensify employee', 'VALIDATEACTOR', [], ['GITHUB_TOKEN'], { - IS_EXPENSIFY_EMPLOYEE: true, -}); -const TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__FALSE__STEP_MOCK = createMockStep('Is Expensify employee', 'Is Expensify employee', 'VALIDATEACTOR', [], ['GITHUB_TOKEN'], { - IS_EXPENSIFY_EMPLOYEE: false, -}); -const TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__TRUE__STEP_MOCK = createMockStep( - 'Set HAS_READY_TO_BUILD_LABEL flag', - 'Set HAS_READY_TO_BUILD_LABEL flag', - 'VALIDATEACTOR', - [], - ['PULL_REQUEST_NUMBER', 'GITHUB_TOKEN'], - {HAS_READY_TO_BUILD_LABEL: true}, -); -const TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__FALSE__STEP_MOCK = createMockStep( - 'Set HAS_READY_TO_BUILD_LABEL flag', - 'Set HAS_READY_TO_BUILD_LABEL flag', - 'VALIDATEACTOR', - [], - ['PULL_REQUEST_NUMBER', 'GITHUB_TOKEN'], - {HAS_READY_TO_BUILD_LABEL: false}, -); -const TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS = [ - TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__TRUE__STEP_MOCK, - TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__TRUE__STEP_MOCK, -]; -const TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS = [ - TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__TRUE__STEP_MOCK, - TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__FALSE__STEP_MOCK, -]; -const TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS = [ - TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__FALSE__STEP_MOCK, - TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__TRUE__STEP_MOCK, -]; -const TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS = [ - TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__FALSE__STEP_MOCK, - TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__FALSE__STEP_MOCK, -]; - -// getbranchref -const TESTBUILD__GETBRANCHREF__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'GETBRANCHREF', [], []); -const TESTBUILD__GETBRANCHREF__CHECK_IF_PULL_REQUEST_NUMBER_IS_CORRECT__STEP_MOCK = createMockStep( - 'Check if pull request number is correct', - 'Check if pull request number is correct', - 'GETBRANCHREF', - [], - ['GITHUB_TOKEN'], - {REF: 'test-ref'}, -); -const TESTBUILD__GETBRANCHREF__STEP_MOCKS = [TESTBUILD__GETBRANCHREF__CHECKOUT__STEP_MOCK, TESTBUILD__GETBRANCHREF__CHECK_IF_PULL_REQUEST_NUMBER_IS_CORRECT__STEP_MOCK]; - -// android -const TESTBUILD__ANDROID__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'ANDROID', ['ref'], []); -const TESTBUILD__ANDROID__CREATE_ENV_ADHOC__STEP_MOCK = createMockStep( - 'Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', - 'Creating .env.adhoc file based on staging', - 'ANDROID', - [], - [], -); -const TESTBUILD__ANDROID__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'ANDROID', [], []); -const TESTBUILD__ANDROID__SETUP_JAVA__STEP_MOCK = createMockStep('Setup Java', 'Setup Java', 'ANDROID', ['distribution', 'java-version'], []); -const TESTBUILD__ANDROID__SETUP_RUBY__STEP_MOCK = createMockStep('Setup Ruby', 'Setup Ruby', 'ANDROID', ['ruby-version', 'bundler-cache'], []); -const TESTBUILD__ANDROID__DECRYPT_KEYSTORE__STEP_MOCK = createMockStep('Decrypt keystore', 'Decrypt keystore', 'ANDROID', [], ['LARGE_SECRET_PASSPHRASE']); -const TESTBUILD__ANDROID__DECRYPT_JSON_KEY__STEP_MOCK = createMockStep('Decrypt json key', 'Decrypt json key', 'ANDROID', [], ['LARGE_SECRET_PASSPHRASE']); -const TESTBUILD__ANDROID__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = createMockStep( - 'Configure AWS Credentials', - 'Configure AWS Credentials', - 'ANDROID', - ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], - [], -); -const TESTBUILD__ANDROID__CONFIGURE_MAPBOX_SDK__STEP_MOCK = createMockStep('Configure MapBox SDK', 'Configure MapBox SDK', 'ANDROID'); -const TESTBUILD__ANDROID__RUN_FASTLANE_BETA_TEST__STEP_MOCK = createMockStep( - 'Run Fastlane beta test', - 'Run Fastlane beta test', - 'ANDROID', - [], - ['S3_ACCESS_KEY', 'S3_SECRET_ACCESS_KEY', 'S3_BUCKET', 'S3_REGION', 'MYAPP_UPLOAD_STORE_PASSWORD', 'MYAPP_UPLOAD_KEY_PASSWORD'], -); -const TESTBUILD__ANDROID__UPLOAD_ARTIFACT__STEP_MOCK = createMockStep('Upload Artifact', 'Upload Artifact', 'ANDROID', ['name', 'path'], []); -const TESTBUILD__ANDROID__STEP_MOCKS = [ - TESTBUILD__ANDROID__CHECKOUT__STEP_MOCK, - TESTBUILD__ANDROID__CREATE_ENV_ADHOC__STEP_MOCK, - TESTBUILD__ANDROID__SETUP_NODE__STEP_MOCK, - TESTBUILD__ANDROID__SETUP_JAVA__STEP_MOCK, - TESTBUILD__ANDROID__SETUP_RUBY__STEP_MOCK, - TESTBUILD__ANDROID__DECRYPT_KEYSTORE__STEP_MOCK, - TESTBUILD__ANDROID__DECRYPT_JSON_KEY__STEP_MOCK, - TESTBUILD__ANDROID__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, - TESTBUILD__ANDROID__CONFIGURE_MAPBOX_SDK__STEP_MOCK, - TESTBUILD__ANDROID__RUN_FASTLANE_BETA_TEST__STEP_MOCK, - TESTBUILD__ANDROID__UPLOAD_ARTIFACT__STEP_MOCK, -]; - -// ios -const TESTBUILD__IOS__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'IOS', ['ref'], []); -const TESTBUILD__IOS__CONFIGURE_MAPBOX_SDK__STEP_MOCK = createMockStep('Configure MapBox SDK', 'Configure MapBox SDK', 'IOS'); -const TESTBUILD__IOS__CREATE_ENV_ADHOC__STEP_MOCK = createMockStep( - 'Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', - 'Creating .env.adhoc file based on staging', - 'IOS', - [], - [], -); -const TESTBUILD__IOS__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'IOS', [], []); -const TESTBUILD__IOS__SETUP_XCODE__STEP_MOCK = createMockStep('Setup XCode', 'Setup XCode', 'IOS', [], []); -const TESTBUILD__IOS__SETUP_RUBY__STEP_MOCK = createMockStep('Setup Ruby', 'Setup Ruby', 'IOS', ['ruby-version', 'bundler-cache'], []); -const TESTBUILD__IOS__CACHE_POD_DEPENDENCIES__STEP_MOCK = createMockStep('Cache Pod dependencies', 'Cache Pod dependencies', 'IOS', ['path', 'key'], [], { - 'cache-hit': false, -}); -const TESTBUILD__IOS__COMPARE_PODFILE_AND_MANIFEST__STEP_MOCK = createMockStep('Compare Podfile.lock and Manifest.lock', 'Compare Podfile.lock and Manifest.lock', 'IOS', [], [], { - IS_PODFILE_SAME_AS_MANIFEST: false, -}); -const TESTBUILD__IOS__INSTALL_COCOAPODS__STEP_MOCK = createMockStep('Install cocoapods', 'Install cocoapods', 'IOS', ['timeout_minutes', 'max_attempts', 'command'], []); -const TESTBUILD__IOS__DECRYPT_ADHOC_PROFILE__STEP_MOCK = createMockStep('Decrypt AdHoc profile', 'Decrypt AdHoc profile', 'IOS', [], ['LARGE_SECRET_PASSPHRASE']); -const TESTBUILD__IOS__DECRYPT_ADHOC_NSE_PROFILE__STEP_MOCK = createMockStep( - 'Decrypt AdHoc Notification Service profile', - 'Decrypt AdHoc Notification Service profile', - 'IOS', - [], - ['LARGE_SECRET_PASSPHRASE'], -); -const TESTBUILD__IOS__DECRYPT_CERTIFICATE__STEP_MOCK = createMockStep('Decrypt certificate', 'Decrypt certificate', 'IOS', [], ['LARGE_SECRET_PASSPHRASE']); -const TESTBUILD__IOS__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = createMockStep( - 'Configure AWS Credentials', - 'Configure AWS Credentials', - 'IOS', - ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], - [], -); -const TESTBUILD__IOS__RUN_FASTLANE__STEP_MOCK = createMockStep('Run Fastlane', 'Run Fastlane', 'IOS', [], ['S3_ACCESS_KEY', 'S3_SECRET_ACCESS_KEY', 'S3_BUCKET', 'S3_REGION']); -const TESTBUILD__IOS__UPLOAD_ARTIFACT__STEP_MOCK = createMockStep('Upload Artifact', 'Upload Artifact', 'IOS', ['name', 'path'], []); -const TESTBUILD__IOS__STEP_MOCKS = [ - TESTBUILD__IOS__CHECKOUT__STEP_MOCK, - TESTBUILD__IOS__CONFIGURE_MAPBOX_SDK__STEP_MOCK, - TESTBUILD__IOS__CREATE_ENV_ADHOC__STEP_MOCK, - TESTBUILD__IOS__SETUP_NODE__STEP_MOCK, - TESTBUILD__IOS__SETUP_XCODE__STEP_MOCK, - TESTBUILD__IOS__SETUP_RUBY__STEP_MOCK, - TESTBUILD__IOS__CACHE_POD_DEPENDENCIES__STEP_MOCK, - TESTBUILD__IOS__COMPARE_PODFILE_AND_MANIFEST__STEP_MOCK, - TESTBUILD__IOS__INSTALL_COCOAPODS__STEP_MOCK, - TESTBUILD__IOS__DECRYPT_ADHOC_PROFILE__STEP_MOCK, - TESTBUILD__IOS__DECRYPT_ADHOC_NSE_PROFILE__STEP_MOCK, - TESTBUILD__IOS__DECRYPT_CERTIFICATE__STEP_MOCK, - TESTBUILD__IOS__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, - TESTBUILD__IOS__RUN_FASTLANE__STEP_MOCK, - TESTBUILD__IOS__UPLOAD_ARTIFACT__STEP_MOCK, -]; - -// desktop -const TESTBUILD__DESKTOP__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'DESKTOP', ['ref'], []); -const TESTBUILD__DESKTOP__CREATE_ENV_ADHOC__STEP_MOCK = createMockStep( - 'Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', - 'Creating .env.adhoc file based on staging', - 'DESKTOP', - [], - [], -); -const TESTBUILD__DESKTOP__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'DESKTOP', [], []); -const TESTBUILD__DESKTOP__DECRYPT_DEVELOPER_ID_CERTIFICATE__STEP_MOCK = createMockStep( - 'Decrypt Developer ID Certificate', - 'Decrypt Developer ID Certificate', - 'DESKTOP', - [], - ['DEVELOPER_ID_SECRET_PASSPHRASE'], -); -const TESTBUILD__DESKTOP__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = createMockStep( - 'Configure AWS Credentials', - 'Configure AWS Credentials', - 'DESKTOP', - ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], - [], -); -const TESTBUILD__DESKTOP__BUILD_DESKTOP_APP_FOR_TESTING__STEP_MOCK = createMockStep( - 'Build desktop app for testing', - 'Build desktop app for testing', - 'DESKTOP', - [], - ['CSC_LINK', 'CSC_KEY_PASSWORD', 'APPLE_ID', 'APPLE_APP_SPECIFIC_PASSWORD', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], -); -const TESTBUILD__DESKTOP__STEP_MOCKS = [ - TESTBUILD__DESKTOP__CHECKOUT__STEP_MOCK, - TESTBUILD__DESKTOP__CREATE_ENV_ADHOC__STEP_MOCK, - TESTBUILD__DESKTOP__SETUP_NODE__STEP_MOCK, - TESTBUILD__DESKTOP__DECRYPT_DEVELOPER_ID_CERTIFICATE__STEP_MOCK, - TESTBUILD__DESKTOP__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, - TESTBUILD__DESKTOP__BUILD_DESKTOP_APP_FOR_TESTING__STEP_MOCK, -]; - -// web -const TESTBUILD__WEB__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'WEB', ['ref'], []); -const TESTBUILD__WEB__CREATE_ENV_ADHOC__STEP_MOCK = createMockStep( - 'Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it', - 'Creating .env.adhoc file based on staging', - 'WEB', - [], - [], -); -const TESTBUILD__WEB__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'WEB', [], []); -const TESTBUILD__WEB__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = createMockStep( - 'Configure AWS Credentials', - 'Configure AWS Credentials', - 'WEB', - ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], - [], -); -const TESTBUILD__WEB__BUILD_WEB_FOR_TESTING__STEP_MOCK = createMockStep('Build web for testing', 'Build web for testing', 'WEB', [], []); -const TESTBUILD__WEB__BUILD_DOCS__STEP_MOCK = createMockStep('Build docs', 'Build docs', 'WEB', [], []); -const TESTBUILD__WEB__DEPLOY_TO_S3_FOR_INTERNAL_TESTING__STEP_MOCK = createMockStep('Deploy to S3 for internal testing', 'Deploy to S3 for internal testing', 'WEB', [], []); -const TESTBUILD__WEB__STEP_MOCKS = [ - TESTBUILD__WEB__CHECKOUT__STEP_MOCK, - TESTBUILD__WEB__CREATE_ENV_ADHOC__STEP_MOCK, - TESTBUILD__WEB__SETUP_NODE__STEP_MOCK, - TESTBUILD__WEB__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, - TESTBUILD__WEB__BUILD_WEB_FOR_TESTING__STEP_MOCK, - TESTBUILD__WEB__BUILD_DOCS__STEP_MOCK, - TESTBUILD__WEB__DEPLOY_TO_S3_FOR_INTERNAL_TESTING__STEP_MOCK, -]; - -// postgithubcomment -const TESTBUILD__POSTGITHUBCOMMENT__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'POSTGITHUBCOMMENT', ['ref'], []); -const TESTBUILD__POSTGITHUBCOMMENT__DOWNLOAD_ARTIFACT__STEP_MOCK = createMockStep('Download Artifact', 'Download Artifact', 'POSTGITHUBCOMMENT', [], []); -const TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_ANDROID_PATHS__STEP_MOCK = createMockStep('Read JSONs with android paths', 'Read JSONs with android paths', 'POSTGITHUBCOMMENT', [], [], { - android_path: 'http://dummy.android.link', -}); -const TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_IOS_PATHS__STEP_MOCK = createMockStep('Read JSONs with iOS paths', 'Read JSONs with iOS paths', 'POSTGITHUBCOMMENT', [], [], { - ios_path: 'http://dummy.ios.link', -}); -const TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK = createMockStep( - 'Publish links to apps for download', - 'Publish links to apps for download', - 'POSTGITHUBCOMMENT', - ['PR_NUMBER', 'GITHUB_TOKEN', 'ANDROID', 'DESKTOP', 'IOS', 'WEB', 'ANDROID_LINK', 'DESKTOP_LINK', 'IOS_LINK', 'WEB_LINK'], - [], -); -const TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS = [ - TESTBUILD__POSTGITHUBCOMMENT__CHECKOUT__STEP_MOCK, - TESTBUILD__POSTGITHUBCOMMENT__DOWNLOAD_ARTIFACT__STEP_MOCK, - TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_ANDROID_PATHS__STEP_MOCK, - TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_IOS_PATHS__STEP_MOCK, - TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK, -]; - -export default { - TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - TESTBUILD__GETBRANCHREF__STEP_MOCKS, - TESTBUILD__ANDROID__STEP_MOCKS, - TESTBUILD__IOS__STEP_MOCKS, - TESTBUILD__DESKTOP__STEP_MOCKS, - TESTBUILD__WEB__STEP_MOCKS, - TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/testMocks.ts b/workflow_tests/mocks/testMocks.ts deleted file mode 100644 index 96bec3f0422a..000000000000 --- a/workflow_tests/mocks/testMocks.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// jest -const TEST__JEST__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'JEST', [], []); -const TEST__JEST__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'JEST', [], []); -const TEST__JEST__GET_NUMBER_OF_CPU_CORES__STEP_MOCK = createMockStep('Get number of CPU cores', 'Get number of CPU cores', 'JEST', [], [], {count: 8}); -const TEST__JEST__CACHE_JEST_CACHE__STEP_MOCK = createMockStep('Cache Jest cache', 'Cache Jest cache', 'JEST', ['path', 'key'], []); -const TEST__JEST__JEST_TESTS__STEP_MOCK = createMockStep('Jest tests', 'Jest tests', 'JEST', [], []); -const TEST__JEST__STEP_MOCKS = [ - TEST__JEST__CHECKOUT__STEP_MOCK, - TEST__JEST__SETUP_NODE__STEP_MOCK, - TEST__JEST__GET_NUMBER_OF_CPU_CORES__STEP_MOCK, - TEST__JEST__CACHE_JEST_CACHE__STEP_MOCK, - TEST__JEST__JEST_TESTS__STEP_MOCK, -]; - -export default {TEST__JEST__STEP_MOCKS}; diff --git a/workflow_tests/mocks/validateGithubActionsMocks.ts b/workflow_tests/mocks/validateGithubActionsMocks.ts deleted file mode 100644 index 2c1afba74387..000000000000 --- a/workflow_tests/mocks/validateGithubActionsMocks.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// verify -const VALIDATEGITHUBACTIONS__VERIFY__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'VERIFY'); -const VALIDATEGITHUBACTIONS__VERIFY__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'VERIFY', [], []); -const VALIDATEGITHUBACTIONS__VERIFY__VERIFY_JAVASCRIPT_ACTION_BUILDS__STEP_MOCK = createMockStep('Verify Javascript Action Builds', 'Verify Javascript Action Builds', 'VERIFY', [], []); -const VALIDATEGITHUBACTIONS__VERIFY__VALIDATE_ACTIONS_AND_WORKFLOWS__STEP_MOCK = createMockStep('Validate actions and workflows', 'Validate actions and workflows', 'VERIFY', [], []); -const VALIDATEGITHUBACTIONS__VERIFY__STEP_MOCKS = [ - VALIDATEGITHUBACTIONS__VERIFY__CHECKOUT__STEP_MOCK, - VALIDATEGITHUBACTIONS__VERIFY__SETUP_NODE__STEP_MOCK, - VALIDATEGITHUBACTIONS__VERIFY__VERIFY_JAVASCRIPT_ACTION_BUILDS__STEP_MOCK, - VALIDATEGITHUBACTIONS__VERIFY__VALIDATE_ACTIONS_AND_WORKFLOWS__STEP_MOCK, -]; - -export default { - VALIDATEGITHUBACTIONS__VERIFY__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/verifyPodfileMocks.ts b/workflow_tests/mocks/verifyPodfileMocks.ts deleted file mode 100644 index 0cd7ea396dad..000000000000 --- a/workflow_tests/mocks/verifyPodfileMocks.ts +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// verify -const VERIFYPODFILE__VERIFY__CHECKOUT__STEP_MOCK = createMockStep('Checkout', 'Checkout', 'VERIFY'); -const VERIFYPODFILE__VERIFY__SETUP_NODE__STEP_MOCK = createMockStep('Setup Node', 'Setup Node', 'VERIFY', [], []); -const VERIFYPODFILE__VERIFY__VERIFY_PODFILE__STEP_MOCK = createMockStep('Verify podfile', 'Verify podfile', 'VERIFY', [], []); -const VERIFYPODFILE__VERIFY__STEP_MOCKS = [VERIFYPODFILE__VERIFY__CHECKOUT__STEP_MOCK, VERIFYPODFILE__VERIFY__SETUP_NODE__STEP_MOCK, VERIFYPODFILE__VERIFY__VERIFY_PODFILE__STEP_MOCK]; - -export default { - VERIFYPODFILE__VERIFY__STEP_MOCKS, -}; diff --git a/workflow_tests/mocks/verifySignedCommitsMocks.ts b/workflow_tests/mocks/verifySignedCommitsMocks.ts deleted file mode 100644 index 6109af183fd7..000000000000 --- a/workflow_tests/mocks/verifySignedCommitsMocks.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {createMockStep} from '../utils/utils'; - -// verifysignedcommits -const VERIFYSIGNEDCOMMITS__VERIFYSIGNEDCOMMITS__VERIFY_SIGNED_COMMITS__STEP_MOCK = createMockStep( - 'Verify signed commits', - 'Verify signed commits', - 'VERIFYSIGNEDCOMMITS', - ['GITHUB_TOKEN'], - [], -); -const VERIFYSIGNEDCOMMITS__VERIFYSIGNEDCOMMITS__STEP_MOCKS = [VERIFYSIGNEDCOMMITS__VERIFYSIGNEDCOMMITS__VERIFY_SIGNED_COMMITS__STEP_MOCK]; - -export default { - VERIFYSIGNEDCOMMITS__VERIFYSIGNEDCOMMITS__STEP_MOCKS, -}; diff --git a/workflow_tests/platformDeploy.test.ts b/workflow_tests/platformDeploy.test.ts deleted file mode 100644 index 074154798f32..000000000000 --- a/workflow_tests/platformDeploy.test.ts +++ /dev/null @@ -1,303 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/platformDeployAssertions'; -import mocks from './mocks/platformDeployMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import type {MockJobs} from './utils/JobMocker'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'platformDeploy.yml'), - dest: '.github/workflows/platformDeploy.yml', - }, -]; - -describe('test workflow platformDeploy', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testPlatformDeployWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - pushedBranches: [], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - - describe('push', () => { - describe('tag', () => { - it('as team member - platform deploy executes on staging', async () => { - const repoPath = mockGithub.repo.getPath('testPlatformDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'platformDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - { - ref: 'refs/tags/1.2.3', - // eslint-disable-next-line @typescript-eslint/naming-convention - ref_type: 'tag', - // eslint-disable-next-line @typescript-eslint/naming-convention - ref_name: '1.2.3', - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - MYAPP_UPLOAD_STORE_PASSWORD: 'dummy_store_password', - MYAPP_UPLOAD_KEY_PASSWORD: 'dummy_key_password', - BROWSERSTACK: 'dummy_browserstack', - SLACK_WEBHOOK: 'dummy_slack_webhook', - DEVELOPER_ID_SECRET_PASSPHRASE: 'dummy_secret_passphrase', - CSC_LINK: 'dummy_csc_link', - CSC_KEY_PASSWORD: 'dummy_csc_key_pass', - APPLE_ID: 'dummy_apple_id', - APPLE_ID_PASSWORD: 'dummy_apple_pass', - AWS_ACCESS_KEY_ID: 'dummy_aws_access_key_id', - AWS_SECRET_ACCESS_KEY: 'dummy_aws_secret_access_key', - APPLE_CONTACT_EMAIL: 'dummy@email.com', - APPLE_CONTACT_PHONE: '123456789', - APPLE_DEMO_EMAIL: 'dummy.demo@email.com', - APPLE_DEMO_PASSWORD: 'dummy_password', - CLOUDFLARE_TOKEN: 'dummy_cloudflare_token', - }, - 'dummy_github_token', - { - AS_REPO: 'App', - }, - ); - act = utils.setJobRunners( - act, - { - desktop: 'ubuntu-latest', - iOS: 'ubuntu-latest', - android: 'ubuntu-latest', - web: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps: MockStep = { - validateActor: mocks.PLATFORM_DEPLOY__VALIDATE_ACTOR__TEAM_MEMBER__STEP_MOCKS, - android: mocks.PLATFORM_DEPLOY__ANDROID__STEP_MOCKS, - desktop: mocks.PLATFORM_DEPLOY__DESKTOP__STEP_MOCKS, - iOS: mocks.PLATFORM_DEPLOY__IOS__STEP_MOCKS, - web: mocks.PLATFORM_DEPLOY__WEB__STEP_MOCKS, - postSlackMessageOnFailure: mocks.PLATFORM_DEPLOY__POST_SLACK_FAIL__STEP_MOCKS, - postSlackMessageOnSuccess: mocks.PLATFORM_DEPLOY__POST_SLACK_SUCCESS__STEP_MOCKS, - postGithubComment: mocks.PLATFORM_DEPLOY__POST_GITHUB_COMMENT__STEP_MOCKS, - }; - const testMockJobs: MockJobs = { - deployChecklist: { - steps: mocks.PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'platformDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('platformDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertVerifyActorJobExecuted(result); - assertions.assertDeployChecklistJobExecuted(result, true); - assertions.assertAndroidJobExecuted(result, true, false, true); - assertions.assertDesktopJobExecuted(result, true, false); - assertions.assertIOSJobExecuted(result, true, false, true); - assertions.assertWebJobExecuted(result, true); - assertions.assertPostSlackOnFailureJobExecuted(result, false); - assertions.assertPostSlackOnSuccessJobExecuted(result, true, false); - assertions.assertPostGithubCommentJobExecuted(result, true, false); - }); - - it('as OSBotify - platform deploy executes on staging', async () => { - const repoPath = mockGithub.repo.getPath('testPlatformDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'platformDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - { - ref: 'refs/tags/1.2.3', - // eslint-disable-next-line @typescript-eslint/naming-convention - ref_type: 'tag', - // eslint-disable-next-line @typescript-eslint/naming-convention - ref_name: '1.2.3', - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - MYAPP_UPLOAD_STORE_PASSWORD: 'dummy_store_password', - MYAPP_UPLOAD_KEY_PASSWORD: 'dummy_key_password', - BROWSERSTACK: 'dummy_browserstack', - SLACK_WEBHOOK: 'dummy_slack_webhook', - DEVELOPER_ID_SECRET_PASSPHRASE: 'dummy_secret_passphrase', - CSC_LINK: 'dummy_csc_link', - CSC_KEY_PASSWORD: 'dummy_csc_key_pass', - APPLE_ID: 'dummy_apple_id', - APPLE_ID_PASSWORD: 'dummy_apple_pass', - AWS_ACCESS_KEY_ID: 'dummy_aws_access_key_id', - AWS_SECRET_ACCESS_KEY: 'dummy_aws_secret_access_key', - APPLE_CONTACT_EMAIL: 'dummy@email.com', - APPLE_CONTACT_PHONE: '123456789', - APPLE_DEMO_EMAIL: 'dummy.demo@email.com', - APPLE_DEMO_PASSWORD: 'dummy_password', - CLOUDFLARE_TOKEN: 'dummy_cloudflare_token', - }, - 'dummy_github_token', - { - AS_REPO: 'App', - }, - ); - act = utils.setJobRunners( - act, - { - desktop: 'ubuntu-latest', - iOS: 'ubuntu-latest', - android: 'ubuntu-latest', - web: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps = { - validateActor: mocks.PLATFORM_DEPLOY__VALIDATE_ACTOR__OUTSIDER__STEP_MOCKS, - android: mocks.PLATFORM_DEPLOY__ANDROID__STEP_MOCKS, - desktop: mocks.PLATFORM_DEPLOY__DESKTOP__STEP_MOCKS, - iOS: mocks.PLATFORM_DEPLOY__IOS__STEP_MOCKS, - web: mocks.PLATFORM_DEPLOY__WEB__STEP_MOCKS, - postSlackMessageOnFailure: mocks.PLATFORM_DEPLOY__POST_SLACK_FAIL__STEP_MOCKS, - postSlackMessageOnSuccess: mocks.PLATFORM_DEPLOY__POST_SLACK_SUCCESS__STEP_MOCKS, - postGithubComment: mocks.PLATFORM_DEPLOY__POST_GITHUB_COMMENT__STEP_MOCKS, - }; - const testMockJobs: MockJobs = { - deployChecklist: { - steps: mocks.PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'platformDeploy.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('platformDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertVerifyActorJobExecuted(result); - assertions.assertDeployChecklistJobExecuted(result, true); - assertions.assertAndroidJobExecuted(result, true, false, true); - assertions.assertDesktopJobExecuted(result, true, false); - assertions.assertIOSJobExecuted(result, true, false, true); - assertions.assertWebJobExecuted(result, true); - assertions.assertPostSlackOnFailureJobExecuted(result, false); - assertions.assertPostSlackOnSuccessJobExecuted(result, true, false); - assertions.assertPostGithubCommentJobExecuted(result, true, false); - }); - - it('as outsider - platform deploy does not execute', async () => { - const repoPath = mockGithub.repo.getPath('testPlatformDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'platformDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - { - ref: 'refs/tags/1.2.3', - // eslint-disable-next-line @typescript-eslint/naming-convention - ref_type: 'tag', - // eslint-disable-next-line @typescript-eslint/naming-convention - ref_name: '1.2.3', - }, - { - OS_BOTIFY_TOKEN: 'dummy_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - MYAPP_UPLOAD_STORE_PASSWORD: 'dummy_store_password', - MYAPP_UPLOAD_KEY_PASSWORD: 'dummy_key_password', - BROWSERSTACK: 'dummy_browserstack', - SLACK_WEBHOOK: 'dummy_slack_webhook', - DEVELOPER_ID_SECRET_PASSPHRASE: 'dummy_secret_passphrase', - CSC_LINK: 'dummy_csc_link', - CSC_KEY_PASSWORD: 'dummy_csc_key_pass', - APPLE_ID: 'dummy_apple_id', - APPLE_ID_PASSWORD: 'dummy_apple_pass', - AWS_ACCESS_KEY_ID: 'dummy_aws_access_key_id', - AWS_SECRET_ACCESS_KEY: 'dummy_aws_secret_access_key', - APPLE_CONTACT_EMAIL: 'dummy@email.com', - APPLE_CONTACT_PHONE: '123456789', - APPLE_DEMO_EMAIL: 'dummy.demo@email.com', - APPLE_DEMO_PASSWORD: 'dummy_password', - CLOUDFLARE_TOKEN: 'dummy_cloudflare_token', - }, - 'dummy_github_token', - { - AS_REPO: 'App', - }, - ); - act = utils.setJobRunners( - act, - { - desktop: 'ubuntu-latest', - iOS: 'ubuntu-latest', - android: 'ubuntu-latest', - web: 'ubuntu-latest', - }, - workflowPath, - ); - const testMockSteps = { - validateActor: mocks.PLATFORM_DEPLOY__VALIDATE_ACTOR__OUTSIDER__STEP_MOCKS, - android: mocks.PLATFORM_DEPLOY__ANDROID__STEP_MOCKS, - desktop: mocks.PLATFORM_DEPLOY__DESKTOP__STEP_MOCKS, - iOS: mocks.PLATFORM_DEPLOY__IOS__STEP_MOCKS, - web: mocks.PLATFORM_DEPLOY__WEB__STEP_MOCKS, - postSlackMessageOnFailure: mocks.PLATFORM_DEPLOY__POST_SLACK_FAIL__STEP_MOCKS, - postSlackMessageOnSuccess: mocks.PLATFORM_DEPLOY__POST_SLACK_SUCCESS__STEP_MOCKS, - postGithubComment: mocks.PLATFORM_DEPLOY__POST_GITHUB_COMMENT__STEP_MOCKS, - }; - const testMockJobs: MockJobs = { - deployChecklist: { - steps: mocks.PLATFORM_DEPLOY__DEPLOY_CHECKLIST__STEP_MOCKS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'platformDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Author', - logFile: utils.getLogFilePath('platformDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - assertions.assertVerifyActorJobExecuted(result); - assertions.assertDeployChecklistJobExecuted(result, true); - assertions.assertAndroidJobExecuted(result, false); - assertions.assertDesktopJobExecuted(result, false); - assertions.assertIOSJobExecuted(result, false); - assertions.assertWebJobExecuted(result, false); - assertions.assertPostSlackOnFailureJobExecuted(result, false); - assertions.assertPostSlackOnSuccessJobExecuted(result, false); - assertions.assertPostGithubCommentJobExecuted(result, true, false, false); - }); - }); - }); -}); diff --git a/workflow_tests/preDeploy.test.ts b/workflow_tests/preDeploy.test.ts deleted file mode 100644 index 1d467b0bd705..000000000000 --- a/workflow_tests/preDeploy.test.ts +++ /dev/null @@ -1,800 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/preDeployAssertions'; -import mocks from './mocks/preDeployMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import type {MockJobs} from './utils/JobMocker'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'preDeploy.yml'), - dest: '.github/workflows/preDeploy.yml', - }, -]; - -describe('test workflow preDeploy', () => { - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testPreDeployWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - pushedBranches: ['different_branch'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - it('push to main - workflow executes', async () => { - // get path to the local test repo - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - - // get path to the workflow file under test - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - - // instantiate Act in the context of the test repo and given workflow file - let act = new ExtendedAct(repoPath, workflowPath); - - // set run parameters - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - - // set up mocks - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - - // run an event and get the result - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - - // assert results (some steps can run in parallel to each other so the order is not assured - // therefore we can check which steps have been executed, but not the set job order - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result); - }); - - it('different event than push - workflow does not execute', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - - // pull_request - act = utils.setUpActParams( - act, - 'pull_request', - {head: {ref: 'main'}}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - let result = await act.runEvent('pull_request', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result, false); - assertions.assertLintJobExecuted(result, false); - assertions.assertTestJobExecuted(result, false); - assertions.assertChooseDeployActionsJobExecuted(result, false); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - - // workflow_dispatch - act = utils.setUpActParams( - act, - 'workflow_dispatch', - {}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - result = await act.runEvent('workflow_dispatch', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result, false); - assertions.assertLintJobExecuted(result, false); - assertions.assertTestJobExecuted(result, false); - assertions.assertChooseDeployActionsJobExecuted(result, false); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - - describe('confirm passing build', () => { - it('typecheck job failed - workflow exits', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: [utils.createMockStep('Run typecheck workflow', 'Running typecheck workflow - Typecheck workflow failed', 'TYPECHECK', null, null, null, null, false)], - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - expect(result).toEqual( - expect.arrayContaining([utils.createStepAssertion('Run typecheck workflow', false, null, 'TYPECHECK', 'Running typecheck workflow - Typecheck workflow failed')]), - ); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - expect(result).toEqual( - expect.arrayContaining([ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'CONFIRM_PASSING_BUILD', 'Announcing failed workflow in slack', [ - {key: 'SLACK_WEBHOOK', value: '***'}, - ]), - utils.createStepAssertion('Exit failed workflow', false, 'Checks failed, exiting ~ typecheck: failure, lint: success, test: success'), - ]), - ); - assertions.assertChooseDeployActionsJobExecuted(result, false); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - - it('lint job failed - workflow exits', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: [utils.createMockStep('Run lint workflow', 'Running lint workflow - Lint workflow failed', 'LINT', null, null, null, null, false)], - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - expect(result).toEqual(expect.arrayContaining([utils.createStepAssertion('Run lint workflow', false, null, 'LINT', 'Running lint workflow - Lint workflow failed')])); - assertions.assertTestJobExecuted(result); - expect(result).toEqual( - expect.arrayContaining([ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'CONFIRM_PASSING_BUILD', 'Announcing failed workflow in slack', [ - {key: 'SLACK_WEBHOOK', value: '***'}, - ]), - utils.createStepAssertion('Exit failed workflow', false, 'Checks failed, exiting ~ typecheck: success, lint: failure, test: success'), - ]), - ); - assertions.assertChooseDeployActionsJobExecuted(result, false); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - - it('test job failed - workflow exits', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: [utils.createMockStep('Run test workflow', 'Running test workflow - Test workflow failed', 'TEST', null, null, null, null, false)], - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - expect(result).toEqual(expect.arrayContaining([utils.createStepAssertion('Run test workflow', false, null, 'TEST', 'Running test workflow - Test workflow failed')])); - expect(result).toEqual( - expect.arrayContaining([ - utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'CONFIRM_PASSING_BUILD', 'Announcing failed workflow in slack', [ - {key: 'SLACK_WEBHOOK', value: '***'}, - ]), - utils.createStepAssertion('Exit failed workflow', false, 'Checks failed, exiting ~ typecheck: success, lint: success, test: failure'), - ]), - ); - assertions.assertChooseDeployActionsJobExecuted(result, false); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - }); - - it('lint and test job succeed - workflow continues', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result); - }); - }); - - describe('choose deploy actions', () => { - describe('staging locked', () => { - it('not automated PR - deploy skipped and comment left', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, 'push', {ref: 'refs/heads/main'}, {OS_BOTIFY_TOKEN: 'dummy_token', SLACK_WEBHOOK: 'dummy_slack_webhook'}, 'dummy_github_token'); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - assertions.assertUpdateStagingJobFailed(result, false); - }); - - it('automated PR - deploy skipped, but no comment left', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, 'push', {ref: 'refs/heads/main'}, {OS_BOTIFY_TOKEN: 'dummy_token', SLACK_WEBHOOK: 'dummy_slack_webhook'}, 'dummy_github_token'); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - assertions.assertUpdateStagingJobFailed(result, false); - }); - }); - - describe('staging not locked', () => { - it('not automated PR - proceed with deploy', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobExecuted(result, true); - assertions.assertUpdateStagingJobFailed(result, false); - }); - - it('automated PR - deploy skipped, but no comment left', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'OSBotify', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result, false); - assertions.assertUpdateStagingJobExecuted(result, false); - assertions.assertUpdateStagingJobFailed(result, false); - }); - }); - - it('one of updateStaging steps failed - failure announced in Slack', async () => { - const repoPath = mockGithub.repo.getPath('testPreDeployWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - 'push', - {ref: 'refs/heads/main'}, - { - OS_BOTIFY_TOKEN: 'dummy_token', - SLACK_WEBHOOK: 'dummy_slack_webhook', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - }, - 'dummy_github_token', - ); - const testMockSteps: MockStep = { - 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, - updateStaging: mocks.UPDATE_STAGING_JOB_MOCK_STEPS, - }; - testMockSteps.updateStaging[3].mockWith = 'exit 1'; - const testMockJobs: MockJobs = { - typecheck: { - steps: mocks.TYPECHECK_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - lint: { - steps: mocks.LINT_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - test: { - steps: mocks.TEST_JOB_MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - createNewVersion: { - steps: mocks.CREATE_NEW_VERSION_JOB_MOCK_STEPS, - outputs: { - // eslint-disable-next-line no-template-curly-in-string - NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}', - }, - runsOn: 'ubuntu-latest', - }, - e2ePerformanceTests: { - steps: mocks.PREDEPLOY__E2EPERFORMANCETESTS__MOCK_STEPS, - runsOn: 'ubuntu-latest', - }, - }; - const result = await act.runEvent('push', { - workflowFile: path.join(repoPath, '.github', 'workflows', 'preDeploy.yml'), - mockSteps: testMockSteps, - actor: 'Dummy Tester', - logFile: utils.getLogFilePath('preDeploy', expect.getState().currentTestName), - mockJobs: testMockJobs, - }); - assertions.assertTypecheckJobExecuted(result); - assertions.assertLintJobExecuted(result); - assertions.assertTestJobExecuted(result); - assertions.assertChooseDeployActionsJobExecuted(result); - assertions.assertSkipDeployJobExecuted(result, false); - assertions.assertCreateNewVersionJobExecuted(result); - assertions.assertUpdateStagingJobFailed(result, true); - }); - }); -}); diff --git a/workflow_tests/reviewerChecklist.test.ts b/workflow_tests/reviewerChecklist.test.ts deleted file mode 100644 index 1fea2b60008c..000000000000 --- a/workflow_tests/reviewerChecklist.test.ts +++ /dev/null @@ -1,88 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/reviewerChecklistAssertions'; -import mocks from './mocks/reviewerChecklistMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'reviewerChecklist.yml'), - dest: '.github/workflows/reviewerChecklist.yml', - }, -]; - -describe('test workflow reviewerChecklist', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testReviewerChecklistWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('event is pull_request_review', () => { - const event = 'pull_request_review'; - const eventOptions = {}; - it('runs the workflow', async () => { - const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('reviewerChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result); - }); - describe('actor is OSBotify', () => { - const osbotifyActor = 'OSBotify'; - it('does not run the workflow', async () => { - const repoPath = mockGithub.repo.getPath('testReviewerChecklistWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - checklist: mocks.REVIEWERCHECKLIST__CHECKLIST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'reviewerChecklist.yml'), - mockSteps: testMockSteps, - actor: osbotifyActor, - logFile: utils.getLogFilePath('reviewerChecklist', expect.getState().currentTestName), - }); - - assertions.assertChecklistJobExecuted(result, false); - }); - }); - }); -}); diff --git a/workflow_tests/scripts/runWorkflowTests.sh b/workflow_tests/scripts/runWorkflowTests.sh deleted file mode 100755 index c8ee88e33e99..000000000000 --- a/workflow_tests/scripts/runWorkflowTests.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -source ./scripts/shellUtils.sh - -title 'GitHub Actions workflow tests' -printf '\n' - -# Check setup -info 'Checking environment setup' - -# Check if docker is installed -if ! docker --version > /dev/null 2>&1; then - error 'Docker is not installed' - info 'Act requires docker to be installed. Please install docker and try again' - exit 1 -fi -info 'Docker installed' - -# Check if docker is running -if ! docker info > /dev/null 2>&1; then - error 'Docker is not running' - info 'Act requires docker engine to be running. Enable docker engine and try again' - exit 1 -fi -info 'Docker engine running' - -# Check if act is installed -if ! act --version > /dev/null 2>&1; then - error 'Act not installed' - info 'Install Act with brew install act and follow the documentation on first Act run (https://github.com/nektos/act#first-act-run)' - exit 1 -fi -info 'Act installed' - -# Check if ACT_BINARY is set -if [[ -z ${ACT_BINARY} ]]; then - info 'ACT_BINARY not set, checking .env file' - if [ -f .env ]; then - set -a - source .env - set +a - else - info '.env file does not exist' - fi - if [[ -z ${ACT_BINARY} ]]; then - error 'ACT_BINARY variable not set' - info 'To make sure Act behaves in a predictable manner please set the ACT_BINARY environment variable to the path to your Act binary' - exit 1 - fi -fi -info 'ACT_BINARY environment variable set' - -if ! eval '${ACT_BINARY} --version' > /dev/null 2>&1; then - error 'ACT_BINARY variable not set properly' - info 'ACT_BINARY environment variable should be set to the path to your Act executable. Please set the variable correctly (try running "which act" to check the path)' - exit 1 -fi -info 'ACT_BINARY environment variable set to an Act executable' - -success 'Environment setup properly - running tests' - -# Run tests -npm test -- --config=workflow_tests/jest.config.ts --runInBand "$@" diff --git a/workflow_tests/test.test.ts b/workflow_tests/test.test.ts deleted file mode 100644 index 926abff56bed..000000000000 --- a/workflow_tests/test.test.ts +++ /dev/null @@ -1,176 +0,0 @@ -import type {MockStep} from '@kie/act-js'; -import {MockGithub} from '@kie/mock-github'; -import type {CreateRepositoryFile} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/testAssertions'; -import mocks from './mocks/testMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); - -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'test.yml'), - dest: '.github/workflows/test.yml', - }, -]; - -describe('test workflow test', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - const osbotifyActor = 'OSBotify'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testTestWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - - describe('pull request opened', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'opened', - }; - it('runs all tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - jest: mocks.TEST__JEST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'test.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('test', expect.getState().currentTestName), - }); - - assertions.assertJestJobExecuted(result); - }); - describe('actor is OSBotify', () => { - it('does not run tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - jest: mocks.TEST__JEST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'test.yml'), - mockSteps: testMockSteps, - actor: osbotifyActor, - logFile: utils.getLogFilePath('test', expect.getState().currentTestName), - }); - - assertions.assertJestJobExecuted(result, false); - }); - }); - }); - - describe('pull request synchronized', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'synchronize', - }; - it('runs all tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - jest: mocks.TEST__JEST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'test.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('test', expect.getState().currentTestName), - }); - - assertions.assertJestJobExecuted(result); - }); - describe('actor is OSBotify', () => { - it('does not run tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - jest: mocks.TEST__JEST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'test.yml'), - mockSteps: testMockSteps, - actor: osbotifyActor, - logFile: utils.getLogFilePath('test', expect.getState().currentTestName), - }); - - assertions.assertJestJobExecuted(result, false); - }); - }); - }); - - describe('event is workflow_call', () => { - const event = 'workflow_call'; - const eventOptions = {}; - it('runs all tests', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - jest: mocks.TEST__JEST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'test.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('test', expect.getState().currentTestName), - }); - - assertions.assertJestJobExecuted(result); - }); - describe('actor is OSBotify', () => { - it('runs all tests normally', async () => { - const repoPath = mockGithub.repo.getPath('testTestWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'test.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps: MockStep = { - jest: mocks.TEST__JEST__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'test.yml'), - mockSteps: testMockSteps, - actor: osbotifyActor, - logFile: utils.getLogFilePath('test', expect.getState().currentTestName), - }); - - assertions.assertJestJobExecuted(result); - }); - }); - }); -}); diff --git a/workflow_tests/testBuild.test.ts b/workflow_tests/testBuild.test.ts deleted file mode 100644 index cd793fa9aaca..000000000000 --- a/workflow_tests/testBuild.test.ts +++ /dev/null @@ -1,754 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/testBuildAssertions'; -import mocks from './mocks/testBuildMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'testBuild.yml'), - dest: '.github/workflows/testBuild.yml', - }, -]; - -describe('test workflow testBuild', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - const secrets = { - OS_BOTIFY_TOKEN: 'dummy_osbotify_token', - LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', - AWS_ACCESS_KEY_ID: 'dummy_aws_access_kry_id', - AWS_SECRET_ACCESS_KEY: 'dummy_aws_secret_access_key', - DEVELOPER_ID_SECRET_PASSPHRASE: 'dummy_developer_id_secret_passphrase', - CSC_LINK: 'dummy_csc_link', - CSC_KEY_PASSWORD: 'dummy_csc_key_password', - APPLE_ID_PASSWORD: 'dummy_apple_id_password', - APPLE_ID: 'dummy_apple_id_value', - MYAPP_UPLOAD_STORE_PASSWORD: 'dummy_myapp_upload_store_password', - MYAPP_UPLOAD_KEY_PASSWORD: 'dummy_myapp_upload_key_password', - }; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testTestBuildWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('event is workflow_dispatch', () => { - const event = 'workflow_dispatch'; - const inputs = { - PULL_REQUEST_NUMBER: '1234', - }; - it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); - }); - describe('actor is not a team member', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('android fails', () => { - it('executes workflow, failure reflected', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: utils.deepCopy(mocks.TESTBUILD__ANDROID__STEP_MOCKS), - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - testMockSteps.android[5] = utils.createMockStep('Decrypt keystore', 'Decrypt keystore', 'ANDROID', [], ['LARGE_SECRET_PASSPHRASE'], {}, {}, false); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result); - assertions.assertAndroidJobExecuted(result, 'test-ref', true, 5); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'failure', 'success', 'success', 'success'); - }); - }); - describe('iOS fails', () => { - it('executes workflow, failure reflected', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: utils.deepCopy(mocks.TESTBUILD__IOS__STEP_MOCKS), - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - testMockSteps.iOS[8] = utils.createMockStep('Install cocoapods', 'Install cocoapods', 'IOS', ['timeout_minutes', 'max_attempts', 'command'], [], {}, {}, false); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref', true, 8); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'success', 'failure', 'success', 'success'); - }); - }); - describe('desktop fails', () => { - it('executes workflow, failure reflected', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: utils.deepCopy(mocks.TESTBUILD__DESKTOP__STEP_MOCKS), - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - testMockSteps.desktop[3] = utils.createMockStep( - 'Decrypt Developer ID Certificate', - 'Decrypt Developer ID Certificate', - 'DESKTOP', - [], - ['DEVELOPER_ID_SECRET_PASSPHRASE'], - {}, - {}, - false, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref', true, 3); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'success', 'success', 'failure', 'success'); - }); - }); - describe('web fails', () => { - it('executes workflow, failure reflected', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: utils.deepCopy(mocks.TESTBUILD__WEB__STEP_MOCKS), - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - testMockSteps.web[3] = utils.createMockStep( - 'Configure AWS Credentials', - 'Configure AWS Credentials', - 'WEB', - ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], - [], - {}, - {}, - false, - ); - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref', true, 3); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'success', 'success', 'success', 'failure'); - }); - }); - }); - describe('pull request opened', () => { - const event = 'pull_request_target'; - const eventOptions = { - action: 'opened', - number: '1234', - pull_request: { - head: { - sha: 'test-ref', - }, - }, - }; - it('executes workflow, without getBranchRef', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); - }); - describe('actor is not a team member', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - }); - describe('pull request synchronized', () => { - const event = 'pull_request_target'; - const eventOptions = { - action: 'synchronize', - number: '1234', - pull_request: { - head: { - sha: 'test-ref', - }, - }, - }; - it('executes workflow, without getBranchRef', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); - }); - describe('actor is not a team member', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - }); - describe('pull request labeled', () => { - const event = 'pull_request_target'; - const eventOptions = { - action: 'labeled', - number: '1234', - pull_request: { - head: { - sha: 'test-ref', - }, - }, - }; - it('executes workflow, withuout getBranchRef', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref'); - assertions.assertIOSJobExecuted(result, 'test-ref'); - assertions.assertDesktopJobExecuted(result, 'test-ref'); - assertions.assertWebJobExecuted(result, 'test-ref'); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); - }); - describe('actor is not a team member', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { - it('stops the workflow after validation', async () => { - const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); - act = utils.setJobRunners(act, {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest', web: 'ubuntu-latest', android: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, - getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, - android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, - iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, - desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, - web: mocks.TESTBUILD__WEB__STEP_MOCKS, - postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'testBuild.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('testBuild', expect.getState().currentTestName), - }); - - assertions.assertValidateActorJobExecuted(result, '1234'); - assertions.assertGetBranchRefJobExecuted(result, false); - assertions.assertAndroidJobExecuted(result, 'test-ref', false); - assertions.assertIOSJobExecuted(result, 'test-ref', false); - assertions.assertDesktopJobExecuted(result, 'test-ref', false); - assertions.assertWebJobExecuted(result, 'test-ref', false); - assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); - }); - }); - }); -}); diff --git a/workflow_tests/utils/ExtendedAct.ts b/workflow_tests/utils/ExtendedAct.ts deleted file mode 100644 index f5a0742afd76..000000000000 --- a/workflow_tests/utils/ExtendedAct.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* eslint-disable @typescript-eslint/dot-notation */ -// This eslint-disable comment is here to allow accessing private properties in the Act class -import type {RunOpts, Step, Workflow} from '@kie/act-js'; -import {Act} from '@kie/act-js'; -import os from 'os'; -import path from 'path'; -import JobMocker from './JobMocker'; -import type {MockJobs} from './JobMocker'; - -type ExtendedActOpts = RunOpts & {actor?: string; workflowFile?: string; mockJobs?: MockJobs}; - -type ActOptions = { - cwd: string; - actArguments: string[]; - proxy: unknown; -}; - -// @ts-expect-error Override shouldn't be done on private methods wait until https://github.com/kiegroup/act-js/issues/77 is resolved or try to create a params workaround -class ExtendedAct extends Act { - async parseRunOpts(opts?: ExtendedActOpts): Promise { - const {cwd, actArguments, proxy} = await (super['parseRunOpts'] as (opts?: ExtendedActOpts) => Promise)(opts); - - if (opts?.actor) { - actArguments.push('--actor', opts.actor); - } - - if (os.arch() === 'arm64') { - actArguments.push('--container-architecture', 'linux/amd64'); - } - - return {cwd, actArguments, proxy}; - } - - async runEvent(event: string, opts?: ExtendedActOpts): Promise { - const {mockJobs, ...vanillaOpts} = opts ?? {}; - - if (mockJobs) { - await this.handleJobMocking((workflow) => workflow.events.includes(event), {mockJobs, workflowFile: vanillaOpts.workflowFile, cwd: vanillaOpts.cwd}); - } - - return super.runEvent(event, vanillaOpts); - } - - async handleJobMocking(filter: (workflow: Workflow) => boolean, opts: ExtendedActOpts): Promise { - let workflowFiles: string[]; - - if (opts.workflowFile) { - workflowFiles = [path.basename(opts.workflowFile)]; - } else if (this['workflowFile'] !== this['cwd']) { - workflowFiles = [path.basename(this['workflowFile'] as string)]; - } else { - const availableWorkflows = await this.list(undefined, opts.cwd, opts.workflowFile); - workflowFiles = availableWorkflows.filter(filter).map((workflow: Workflow) => workflow.workflowFile); - } - - return workflowFiles.map((workflowFile) => { - const jobMocker = new JobMocker(workflowFile, opts.cwd ?? (this['cwd'] as string)); - return jobMocker.mock(opts.mockJobs); - }); - } -} - -export default ExtendedAct; diff --git a/workflow_tests/utils/JobMocker.ts b/workflow_tests/utils/JobMocker.ts deleted file mode 100644 index 9434b52ef0a5..000000000000 --- a/workflow_tests/utils/JobMocker.ts +++ /dev/null @@ -1,106 +0,0 @@ -import type {StepIdentifier} from '@kie/act-js'; -import type {PathOrFileDescriptor} from 'fs'; -import fs from 'fs'; -import path from 'path'; -import yaml from 'yaml'; - -// eslint-disable-next-line @typescript-eslint/naming-convention -type YamlMockJob = Omit & {'runs-on'?: string}; - -type YamlWorkflow = { - jobs: Record; -}; - -type MockJob = { - steps: StepIdentifier[]; - uses?: string; - secrets?: string[]; - with?: string; - outputs?: Record; - runsOn: string; -}; - -type MockJobs = Record; - -class JobMocker { - workflowFile: string; - - cwd: string; - - constructor(workflowFile: string, cwd: string) { - this.workflowFile = workflowFile; - this.cwd = cwd; - } - - mock(mockJobs: MockJobs = {}) { - const filePath = this.getWorkflowPath(); - const workflow = this.readWorkflowFile(filePath); - - Object.entries(mockJobs).forEach(([jobId, mockJob]) => { - const job = this.locateJob(workflow, jobId); - if (job) { - if (job.uses) { - delete job.uses; - } - if (job.secrets) { - delete job.secrets; - } - let jobWith: string | undefined; - if (job.with) { - jobWith = job.with; - delete job.with; - } - job.steps = mockJob.steps.map((step) => { - const mockStep = { - name: step.name, - run: step.mockWith, - } as StepIdentifier; - if (step.id) { - mockStep.id = step.id; - } - if (jobWith) { - mockStep.with = jobWith; - } - return mockStep; - }); - if (mockJob.outputs) { - job.outputs = mockJob.outputs; - } - if (mockJob.runsOn) { - job['runs-on'] = mockJob.runsOn; - } - } else { - throw new Error('Could not find job'); - } - }); - return this.writeWorkflowFile(filePath, workflow); - } - - locateJob(workflow: YamlWorkflow, jobId: string): YamlMockJob { - return workflow.jobs[jobId]; - } - - getWorkflowPath(): string { - if (fs.existsSync(path.join(this.cwd, this.workflowFile))) { - return path.join(this.cwd, this.workflowFile); - } - if (this.cwd.endsWith('.github')) { - return path.join(this.cwd, 'workflows', this.workflowFile); - } - if (fs.existsSync(path.join(this.cwd, '.github', 'workflows', this.workflowFile))) { - return path.join(this.cwd, '.github', 'workflows', this.workflowFile); - } - throw new Error(`Could not locate ${this.workflowFile}`); - } - - readWorkflowFile(location: PathOrFileDescriptor): YamlWorkflow { - return yaml.parse(fs.readFileSync(location, 'utf8')) as YamlWorkflow; - } - - writeWorkflowFile(location: PathOrFileDescriptor, data: YamlWorkflow) { - return fs.writeFileSync(location, yaml.stringify(data), 'utf8'); - } -} - -export default JobMocker; -export type {MockJob, MockJobs, YamlWorkflow, YamlMockJob}; diff --git a/workflow_tests/utils/preGenerateTest.ts b/workflow_tests/utils/preGenerateTest.ts deleted file mode 100644 index 2c2e18eaeafa..000000000000 --- a/workflow_tests/utils/preGenerateTest.ts +++ /dev/null @@ -1,297 +0,0 @@ -/* eslint no-console: ["error", { allow: ["warn", "log"] }] */ -import type {StepIdentifier} from '@kie/act-js'; -import type {PathLike} from 'fs'; -import fs from 'fs'; -import path from 'path'; -import {exit} from 'process'; -import yaml from 'yaml'; -import type {YamlMockJob, YamlWorkflow} from './JobMocker'; - -const workflowsDirectory = path.resolve(__dirname, '..', '..', '.github', 'workflows'); -const workflowTestsDirectory = path.resolve(__dirname, '..'); -const workflowTestMocksDirectory = path.join(workflowTestsDirectory, 'mocks'); -const workflowTestAssertionsDirectory = path.join(workflowTestsDirectory, 'assertions'); -const workflowFilePattern = '\\w+\\.yml'; -const workflowFileRegex = new RegExp(workflowFilePattern, 'g'); - -const capitalize = (s: string): string => (s && s.charAt(0).toUpperCase() + s.slice(1)) || ''; -const mockFileTemplate = (mockSteps: string, exports: string) => `const utils = require('../utils/utils'); -${mockSteps} -${exports} -`; - -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'); -const assertions = require('./assertions/${workflowName}Assertions'); -const mocks = require('./mocks/${workflowName}Mocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; - -jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', '${workflowName}.yml'), - dest: '.github/workflows/${workflowName}.yml', - }, -]; - -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({ - repo: { - test${capitalize(workflowName)}WorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are need add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - it('test stub', async () => { - const repoPath = mockGithub.repo.getPath('test${capitalize(workflowName)}WorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', '${workflowName}.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams( - act, - '[EVENT]', - {}, - {}, - githubToken, - ); - const testMockSteps = { - // mock steps with imported mocks - }; - const result = await act - .runEvent('[EVENT]', { - workflowFile: path.join(repoPath, '.github', 'workflows', '${workflowName}.yml'), - mockSteps: testMockSteps, - actor, - }); - - // assert execution with imported assertions - }); -}); -`; - -const mockStepTemplate = (stepMockName: string, step: StepIdentifier, jobId: string | undefined) => ` -const ${stepMockName} = utils.createMockStep( - '${step.name ?? ''}', - '${step.name ?? ''}', - ${jobId ? `'${jobId.toUpperCase()}'` : 'null'}, - ${step.inputs ? JSON.stringify(step.inputs).replaceAll('"', "'") : 'null'}, - ${step.envs ? JSON.stringify(step.envs).replaceAll('"', "'") : 'null'}, - // add outputs if needed -);`; - -const stepAssertionTemplate = (stepName: string, jobId: string, stepMessage: string, inputs: string[] = [], envs: string[] = []): string => { - const inputsString = inputs.map((input) => `{key: '${input}', value: '[FILL_IN]'}`).join(','); - const envsString = envs.map((env) => `{key: '${env}', value: '[FILL_IN]'}`).join(','); - - return ` - utils.createStepAssertion( - '${stepName}', - true, - null, - '${jobId}', - '${stepMessage}', - [${inputsString}], - [${envsString}], - ),`; -}; - -const jobMocksTemplate = (jobMocksName: string, stepMocks: string[]): string => { - const stepMocksString = stepMocks.map((stepMock) => `${stepMock}`).join(','); - - return `const ${jobMocksName} = [${stepMocksString}\n];`; -}; - -const jobAssertionTemplate = (jobAssertionName: string, stepAssertionsContent: string) => ` -function ${jobAssertionName}(workflowResult: Step[], didExecute = true) { - const steps = [\n${stepAssertionsContent}\n]; - - for (const expectedStep of steps) { - if (didExecute) { - expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); - } else { - expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); - } - } -};`; - -const mocksExportsTemplate = (jobMocks: string[]): string => { - const jobMocksString = jobMocks.map((jobMock) => ` ${jobMock}`).join(',\n'); - - return `\nmodule.exports = {\n${jobMocksString}\n};\n`; -}; - -const assertionsExportsTemplate = (jobAssertions: string[]): string => { - 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 `\n${eslintDisable}export default {\n${assertionsString}\n};\n`; -}; - -const checkArguments = (args: string[]) => { - if (args.length > 0 && args[0]) { - return; - } - console.warn('Please provide workflow file name'); - exit(1); -}; -const checkWorkflowFileName = (fileName: string) => { - if (workflowFileRegex.test(fileName)) { - return; - } - console.warn(`Please provide a valid workflow file name ([workflow].yml) instead of ${fileName}`); - exit(1); -}; -const checkWorkflowFilePath = (filePath: PathLike) => { - if (fs.existsSync(filePath)) { - return; - } - console.warn(`Provided workflow file does not exist: ${filePath.toString()}`); - exit(1); -}; -const checkIfTestFileExists = (testsDirectory: string, testFileName: string) => { - if (!fs.existsSync(path.join(testsDirectory, testFileName))) { - return; - } - console.warn(`The test file ${testFileName} already exists, exiting`); - exit(1); -}; -const checkIfMocksFileExists = (mocksDirectory: string, mocksFileName: string) => { - if (!fs.existsSync(path.join(mocksDirectory, mocksFileName))) { - return; - } - console.warn(`The mocks file ${mocksFileName} already exists, exiting`); - exit(1); -}; -const checkIfAssertionsFileExists = (assertionsDirectory: string, assertionsFileName: string) => { - if (!fs.existsSync(path.join(assertionsDirectory, assertionsFileName))) { - return; - } - console.warn(`The assertions file ${assertionsFileName} already exists, exiting`); - exit(1); -}; -const parseWorkflowFile = (workflow: YamlWorkflow) => { - const workflowJobs: Record = {}; - Object.entries(workflow.jobs).forEach(([jobId, job]) => { - workflowJobs[jobId] = { - steps: [], - }; - job.steps.forEach((step) => { - const workflowStep = { - name: step.name ?? '', - inputs: Object.keys(step.with ?? {}), - envs: step.envs ?? [], - } as StepIdentifier; - workflowJobs[jobId].steps.push(workflowStep); - }); - }); - return workflowJobs; -}; -const getMockFileContent = (workflowName: string, jobs: Record): string => { - let content = ''; - const jobMocks: string[] = []; - Object.entries(jobs).forEach(([jobId, job]) => { - let mockStepsContent = `\n// ${jobId.toLowerCase()}`; - const stepMocks: string[] = []; - job.steps.forEach((step) => { - const stepMockName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__${step.name - .replaceAll(' ', '_') - .replaceAll('-', '_') - .replaceAll(',', '') - .replaceAll('#', '') - .replaceAll('.ts', '') - .replaceAll('.js', '') - .toUpperCase()}__STEP_MOCK`; - stepMocks.push(stepMockName); - mockStepsContent += mockStepTemplate(stepMockName, step, jobId); - }); - - const jobMocksName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__STEP_MOCKS`; - jobMocks.push(jobMocksName); - mockStepsContent += jobMocksTemplate(jobMocksName, stepMocks); - content += mockStepsContent; - }); - return mockFileTemplate(content, mocksExportsTemplate(jobMocks)); -}; - -const getAssertionsFileContent = (jobs: Record): string => { - let content = ''; - const jobAssertions: string[] = []; - - Object.entries(jobs).forEach(([jobId, job]) => { - let stepAssertionsContent = ''; - job.steps.forEach((step: StepIdentifier) => { - stepAssertionsContent += stepAssertionTemplate(step.name, jobId.toUpperCase(), step.name, step.inputs, step.envs); - }); - const jobAssertionName = `assert${jobId.charAt(0).toUpperCase() + jobId.slice(1)}JobExecuted`; - 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); -checkArguments(callArgs); - -const workflowFileName = callArgs[0]; -checkWorkflowFileName(workflowFileName); - -const workflowName = workflowFileName.slice(0, -4); -const workflowFilePath = path.join(workflowsDirectory, workflowFileName); -checkWorkflowFilePath(workflowFilePath); - -const workflowTestFileName = `${workflowName}.test.js`; -checkIfTestFileExists(workflowTestsDirectory, workflowTestFileName); - -const workflowTestMocksFileName = `${workflowName}Mocks.js`; -checkIfMocksFileExists(workflowTestMocksDirectory, workflowTestMocksFileName); - -const workflowTestAssertionsFileName = `${workflowName}Assertions.ts`; -checkIfAssertionsFileExists(workflowTestAssertionsDirectory, workflowTestAssertionsFileName); - -const workflow = yaml.parse(fs.readFileSync(workflowFilePath, 'utf8')) as YamlWorkflow; -const workflowJobs = parseWorkflowFile(workflow); - -const mockFileContent = getMockFileContent(workflowName, workflowJobs); -const mockFilePath = path.join(workflowTestMocksDirectory, workflowTestMocksFileName); -console.log(`Creating mock file ${mockFilePath}`); -fs.writeFileSync(mockFilePath, mockFileContent); -console.log(`Mock file ${mockFilePath} created`); - -const assertionsFileContent = getAssertionsFileContent(workflowJobs); -const assertionsFilePath = path.join(workflowTestAssertionsDirectory, workflowTestAssertionsFileName); -console.log(`Creating assertions file ${assertionsFilePath}`); -fs.writeFileSync(assertionsFilePath, assertionsFileContent); -console.log(`Assertions file ${assertionsFilePath} created`); - -const testFileContent = getTestFileContent(workflowName); -const testFilePath = path.join(workflowTestsDirectory, workflowTestFileName); -console.log(`Creating test file ${testFilePath}`); -fs.writeFileSync(testFilePath, testFileContent); -console.log(`Test file ${testFilePath} created`); diff --git a/workflow_tests/utils/utils.ts b/workflow_tests/utils/utils.ts deleted file mode 100644 index 1fd60e3f92bc..000000000000 --- a/workflow_tests/utils/utils.ts +++ /dev/null @@ -1,225 +0,0 @@ -import type {EventJSON, StepIdentifier} from '@kie/act-js'; -import fs from 'fs'; -import path from 'path'; -import yaml from 'yaml'; -import type ExtendedAct from './ExtendedAct'; - -type StepAssertionInputEntry = {key: string; value: string | boolean}; - -type StepAssertion = { - name: string; - status: number; - output: string; -}; - -type Jobs = Record< - string, - { - // eslint-disable-next-line @typescript-eslint/naming-convention - 'runs-on': string; - } ->; - -type Workflow = { - jobs: Jobs; -}; - -function setUpActParams( - act: ExtendedAct, - event: string | null = null, - eventOptions: EventJSON | null = null, - secrets: Record | null = null, - githubToken: string | null = null, - envVars: Record | null = null, - inputs: Record | null = null, -): ExtendedAct { - let updatedAct = act; - - if (event && eventOptions) { - // according to `Act` docs event data should be under the key with the event name (`[event]: eventOptions`), but - // for some event types this does not work (like `issues`), but providing the data on the JSON top level does, - // hence `...eventOptions` - this seems to cover all options - const eventData = { - [event]: eventOptions, - ...eventOptions, - }; - updatedAct = updatedAct.setEvent(eventData); - } - - if (secrets) { - Object.entries(secrets).forEach(([key, value]) => { - updatedAct = updatedAct.setSecret(key, value); - }); - } - - if (githubToken) { - updatedAct = updatedAct.setGithubToken(githubToken); - } - - if (envVars) { - Object.entries(envVars).forEach(([key, value]) => { - updatedAct = updatedAct.setEnv(key, value); - }); - } - - if (inputs) { - Object.entries(inputs).forEach(([key, value]) => { - updatedAct = updatedAct.setInput(key, value); - }); - } - - return updatedAct; -} - -function createMockStep( - name: string, - message: string, - jobId: string | null = null, - inputs: string[] | null = null, - inEnvs: string[] | null = null, - outputs: Record | null = null, - outEnvs: Record | null = null, - isSuccessful = true, - id: string | null = null, -): StepIdentifier { - const mockStepName = name; - let mockWithCommand = 'echo [MOCK]'; - if (jobId) { - mockWithCommand += ` [${jobId}]`; - } - mockWithCommand += ` ${message}`; - if (inputs) { - inputs.forEach((input) => { - mockWithCommand += `, ${input}="\${{ inputs.${input} && inputs.${input} || github.event.inputs.${input} }}"`; - }); - } - if (inEnvs) { - inEnvs.forEach((env) => { - mockWithCommand += `, ${env}="\${{ env.${env} }}"`; - }); - } - if (outputs) { - Object.entries(outputs).forEach(([key, value]) => { - mockWithCommand += `\necho "${key}=${value}" >> "$GITHUB_OUTPUT"`; - }); - } - if (outEnvs) { - Object.entries(outEnvs).forEach(([key, value]) => { - mockWithCommand += `\necho "${key}=${value}" >> "$GITHUB_ENV"`; - }); - } - if (!isSuccessful) { - mockWithCommand += '\nexit 1'; - } - if (!id) { - return { - name: mockStepName, - mockWith: mockWithCommand, - }; - } - - return { - id, - name: mockStepName, - mockWith: mockWithCommand, - }; -} - -function createStepAssertion( - name: string, - isSuccessful = true, - expectedOutput: string | null = null, - jobId: string | null = null, - message: string | null = null, - inputs: StepAssertionInputEntry[] | null = null, - envs: StepAssertionInputEntry[] | null = null, -): StepAssertion { - const stepName = `Main ${name}`; - const stepStatus = isSuccessful ? 0 : 1; - let stepOutput: string; - if (expectedOutput !== null) { - stepOutput = expectedOutput; - } else { - stepOutput = '[MOCK]'; - if (jobId) { - stepOutput += ` [${jobId}]`; - } - if (message) { - stepOutput += ` ${message}`; - } - if (inputs) { - inputs.forEach((input) => { - stepOutput += `, ${input.key}=${input.value}`; - }); - } - if (envs) { - envs.forEach((env) => { - stepOutput += `, ${env.key}=${env.value}`; - }); - } - } - return { - name: stepName, - status: stepStatus, - output: stepOutput, - }; -} - -function setJobRunners(act: ExtendedAct, jobs: Record, workflowPath: string): ExtendedAct { - if (!act || !jobs || !workflowPath) { - return act; - } - - const workflow = yaml.parse(fs.readFileSync(workflowPath, 'utf8')) as Workflow; - Object.entries(jobs).forEach(([jobId, runner]) => { - const job = workflow.jobs[jobId]; - job['runs-on'] = runner; - }); - fs.writeFileSync(workflowPath, yaml.stringify(workflow), 'utf8'); - return act; -} - -function deepCopy(originalObject: TObject): TObject { - return JSON.parse(JSON.stringify(originalObject)) as TObject; -} - -function getLogFilePath(workflowName: string, testName: string | undefined): string { - if (!testName) { - throw new Error(); - } - - const logsDir = path.resolve(__dirname, '..', 'logs'); - if (!fs.existsSync(logsDir)) { - fs.mkdirSync(logsDir); - } - const workflowTestsLogDir = path.resolve(logsDir, workflowName); - if (!fs.existsSync(workflowTestsLogDir)) { - fs.mkdirSync(workflowTestsLogDir); - } - const cleanTestName = testName.replace(' ', '_').replace('-', '_').substr(0, 240); - return path.resolve(workflowTestsLogDir, `${cleanTestName}.log`); -} - -function removeMockRepoDir() { - const mockDirRepo = path.resolve(__dirname, '..', '..', 'repo'); - if (fs.existsSync(mockDirRepo)) { - fs.rmSync(mockDirRepo, {recursive: true, force: true}); - } -} - -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', - }, -]; - -export {setUpActParams, createMockStep, createStepAssertion, setJobRunners, deepCopy, getLogFilePath, FILES_TO_COPY_INTO_TEST_REPO, removeMockRepoDir}; diff --git a/workflow_tests/validateGithubActions.test.ts b/workflow_tests/validateGithubActions.test.ts deleted file mode 100644 index f4972a9ae653..000000000000 --- a/workflow_tests/validateGithubActions.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/validateGithubActionsAssertions'; -import mocks from './mocks/validateGithubActionsMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'validateGithubActions.yml'), - dest: '.github/workflows/validateGithubActions.yml', - }, -]; - -describe('test workflow validateGithubActions', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testValidateGithubActionsWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('pull request opened', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'opened', - }; - it('executes verification', async () => { - const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - verify: mocks.VALIDATEGITHUBACTIONS__VERIFY__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('validateGithubActions', expect.getState().currentTestName), - }); - - assertions.assertVerifyJobExecuted(result); - }); - }); - describe('pull request synchronized', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'synchronize', - }; - it('executes verification', async () => { - const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - verify: mocks.VALIDATEGITHUBACTIONS__VERIFY__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('validateGithubActions', expect.getState().currentTestName), - }); - - assertions.assertVerifyJobExecuted(result); - }); - }); -}); diff --git a/workflow_tests/verifyPodfile.test.ts b/workflow_tests/verifyPodfile.test.ts deleted file mode 100644 index 6124cdc856c1..000000000000 --- a/workflow_tests/verifyPodfile.test.ts +++ /dev/null @@ -1,134 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/verifyPodfileAssertions'; -import mocks from './mocks/verifyPodfileMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'verifyPodfile.yml'), - dest: '.github/workflows/verifyPodfile.yml', - }, -]; - -describe('test workflow verifyPodfile', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - const osbotifyActor = 'OSBotify'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testVerifyPodfileWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('pull request opened', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'opened', - }; - it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - act = utils.setJobRunners(act, {verify: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - verify: mocks.VERIFYPODFILE__VERIFY__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('verifyPodfile', expect.getState().currentTestName), - }); - - assertions.assertVerifyJobExecuted(result); - }); - describe('actor is OSBotify', () => { - it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - act = utils.setJobRunners(act, {verify: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - verify: mocks.VERIFYPODFILE__VERIFY__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'), - mockSteps: testMockSteps, - actor: osbotifyActor, - logFile: utils.getLogFilePath('verifyPodfile', expect.getState().currentTestName), - }); - - assertions.assertVerifyJobExecuted(result, false); - }); - }); - }); - describe('pull request synchronized', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'synchronize', - }; - it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - act = utils.setJobRunners(act, {verify: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - verify: mocks.VERIFYPODFILE__VERIFY__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('verifyPodfile', expect.getState().currentTestName), - }); - - assertions.assertVerifyJobExecuted(result); - }); - describe('actor is OSBotify', () => { - it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - act = utils.setJobRunners(act, {verify: 'ubuntu-latest'}, workflowPath); - const testMockSteps = { - verify: mocks.VERIFYPODFILE__VERIFY__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'), - mockSteps: testMockSteps, - actor: osbotifyActor, - logFile: utils.getLogFilePath('verifyPodfile', expect.getState().currentTestName), - }); - - assertions.assertVerifyJobExecuted(result, false); - }); - }); - }); -}); diff --git a/workflow_tests/verifySignedCommits.test.ts b/workflow_tests/verifySignedCommits.test.ts deleted file mode 100644 index 3bf6c15ec1bb..000000000000 --- a/workflow_tests/verifySignedCommits.test.ts +++ /dev/null @@ -1,91 +0,0 @@ -import {MockGithub} from '@kie/mock-github'; -import path from 'path'; -import assertions from './assertions/verifySignedCommitsAssertions'; -import mocks from './mocks/verifySignedCommitsMocks'; -import ExtendedAct from './utils/ExtendedAct'; -import * as utils from './utils/utils'; - -jest.setTimeout(90 * 1000); -let mockGithub: MockGithub; - -const FILES_TO_COPY_INTO_TEST_REPO = [ - ...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO), - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'verifySignedCommits.yml'), - dest: '.github/workflows/verifySignedCommits.yml', - }, -]; - -describe('test workflow verifySignedCommits', () => { - const githubToken = 'dummy_github_token'; - const actor = 'Dummy Actor'; - - beforeAll(() => { - // in case of the tests being interrupted without cleanup the mock repo directory may be left behind - // which breaks the next test run, this removes any possible leftovers - utils.removeMockRepoDir(); - }); - - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new MockGithub({ - repo: { - testVerifySignedCommitsWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - describe('pull request opened', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'opened', - }; - it('test stub', async () => { - const repoPath = mockGithub.repo.getPath('testVerifySignedCommitsWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifySignedCommits.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - verifySignedCommits: mocks.VERIFYSIGNEDCOMMITS__VERIFYSIGNEDCOMMITS__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'verifySignedCommits.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('verifySignedCommits', expect.getState().currentTestName), - }); - - assertions.assertVerifySignedCommitsJobExecuted(result); - }); - }); - describe('pull request synchronized', () => { - const event = 'pull_request'; - const eventOptions = { - action: 'synchronize', - }; - it('test stub', async () => { - const repoPath = mockGithub.repo.getPath('testVerifySignedCommitsWorkflowRepo') ?? ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifySignedCommits.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); - const testMockSteps = { - verifySignedCommits: mocks.VERIFYSIGNEDCOMMITS__VERIFYSIGNEDCOMMITS__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'verifySignedCommits.yml'), - mockSteps: testMockSteps, - actor, - logFile: utils.getLogFilePath('verifySignedCommits', expect.getState().currentTestName), - }); - - assertions.assertVerifySignedCommitsJobExecuted(result); - }); - }); -});