|
1 | 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
2 | 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
3 | 3 |
|
4 |
| -name: Node.js CI |
| 4 | +name: Build and test |
5 | 5 |
|
6 | 6 | on:
|
7 | 7 | push:
|
8 | 8 | branches: [ main ]
|
9 | 9 | pull_request:
|
10 | 10 | branches: [ main ]
|
11 | 11 |
|
12 |
| -jobs: |
13 |
| - build: |
| 12 | +env: |
| 13 | + CACHE_NAME: osd-node-modules |
| 14 | + TEST_BROWSER_HEADLESS: 1 |
| 15 | + CI: 1 |
| 16 | + GCS_UPLOAD_PREFIX: fake |
| 17 | + TEST_OPENSEARCH_DASHBOARDS_HOST: localhost |
| 18 | + TEST_OPENSEARCH_DASHBOARDS_PORT: 6610 |
| 19 | + TEST_OPENSEARCH_TRANSPORT_PORT: 9403 |
| 20 | + TEST_OPENSEARCH_PORT: 9400 |
14 | 21 |
|
| 22 | +jobs: |
| 23 | + build-lint-test: |
15 | 24 | runs-on: ubuntu-latest
|
| 25 | + name: Build and Verify |
| 26 | + steps: |
| 27 | + # Access a cache of set results from a previous run of the job |
| 28 | + # This is to prevent re-running steps that were already successful since it is not native to github actions |
| 29 | + # Can be used to verify flaky steps with reduced times |
| 30 | + - name: Restore the cached run |
| 31 | + uses: actions/cache@v2 |
| 32 | + with: |
| 33 | + path: | |
| 34 | + job_successful |
| 35 | + linter_results |
| 36 | + unit_tests_results |
| 37 | + integration_tests_results |
| 38 | + key: ${{ github.run_id }}-${{ github.job }}-${{ github.sha }} |
| 39 | + restore-keys: | |
| 40 | + ${{ github.run_id }}-${{ github.job }}-${{ github.sha }} |
| 41 | +
|
| 42 | + - name: Get if previous job was successful |
| 43 | + id: job_successful |
| 44 | + run: cat job_successful 2>/dev/null || echo 'false' |
| 45 | + |
| 46 | + - name: Get the previous linter results |
| 47 | + id: linter_results |
| 48 | + run: cat linter_results 2>/dev/null || echo 'default' |
| 49 | + |
| 50 | + - name: Get the previous unit tests results |
| 51 | + id: unit_tests_results |
| 52 | + run: cat unit_tests_results 2>/dev/null || echo 'default' |
| 53 | + |
| 54 | + - name: Get the previous integration tests results |
| 55 | + id: integration_tests_results |
| 56 | + run: cat integration_tests_results 2>/dev/null || echo 'default' |
| 57 | + |
| 58 | + - name: Checkout code |
| 59 | + if: steps.job_successful.outputs.job_successful != 'true' |
| 60 | + uses: actions/checkout@v2 |
| 61 | + |
| 62 | + - name: Setup Node |
| 63 | + if: steps.job_successful.outputs.job_successful != 'true' |
| 64 | + uses: actions/setup-node@v2 |
| 65 | + with: |
| 66 | + node-version: "10.24.1" |
| 67 | + registry-url: 'https://registry.npmjs.org' |
| 68 | + |
| 69 | + - name: Setup Yarn |
| 70 | + if: steps.job_successful.outputs.job_successful != 'true' |
| 71 | + run: | |
| 72 | + npm uninstall -g yarn |
| 73 | + |
| 74 | +
|
| 75 | + - name: Run bootstrap |
| 76 | + if: steps.job_successful.outputs.job_successful != 'true' |
| 77 | + run: yarn osd bootstrap |
| 78 | + |
| 79 | + - name: Run linter |
| 80 | + if: steps.linter_results.outputs.linter_results != 'success' |
| 81 | + id: linter |
| 82 | + run: yarn lint |
| 83 | + |
| 84 | + # Runs unit tests while limiting workers because github actions will spawn more than it can handle and crash |
| 85 | + # Continues on error but will create a comment on the pull request if this step failed. |
| 86 | + - name: Run unit tests |
| 87 | + if: steps.unit_tests_results.outputs.unit_tests_results != 'success' |
| 88 | + id: unit-tests |
| 89 | + continue-on-error: true |
| 90 | + run: node scripts/jest --ci --colors --maxWorkers=10 |
| 91 | + env: |
| 92 | + SKIP_BAD_APPLES: true |
| 93 | + |
| 94 | + - run: echo Unit tests completed unsuccessfully. However, unit tests are inconsistent on the CI so please verify locally with `yarn test:jest`. |
| 95 | + if: steps.unit_tests_results.outputs.unit_tests_results != 'success' && steps.unit-tests.outcome != 'success' |
| 96 | + |
| 97 | + # TODO: This gets rejected, we need approval to add this |
| 98 | + # - name: Add comment if unit tests did not succeed |
| 99 | + # if: steps.unit_tests_results.outputs.unit_tests_results != 'success' && steps.unit-tests.outcome != 'success' |
| 100 | + # uses: actions/github-script@v5 |
| 101 | + # with: |
| 102 | + # github-token: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + # script: | |
| 104 | + # github.rest.issues.createComment({ |
| 105 | + # issue_number: context.issue.number, |
| 106 | + # owner: context.repo.owner, |
| 107 | + # repo: context.repo.repo, |
| 108 | + # body: 'Unit tests completed unsuccessfully. However, unit tests are inconsistent on the CI so please verify locally with `yarn test:jest`.' |
| 109 | + # }) |
16 | 110 |
|
| 111 | + - name: Run integration tests |
| 112 | + if: steps.integration_tests_results.outputs.integration_tests_results != 'success' |
| 113 | + id: integration-tests |
| 114 | + run: node scripts/jest_integration --ci --colors --max-old-space-size=5120 |
| 115 | + |
| 116 | + # Set cache if linter, unit tests, and integration tests were successful then the job will be marked successful |
| 117 | + # Sets individual results to empower re-runs of the same build without re-running successful steps. |
| 118 | + - if: | |
| 119 | + (steps.linter.outcome == 'success' || steps.linter.outcome == 'skipped') && |
| 120 | + (steps.unit-tests.outcome == 'success' || steps.unit-tests.outcome == 'skipped') && |
| 121 | + (steps.integration-tests.outcome == 'success' || steps.integration-tests.outcome == 'skipped') |
| 122 | + run: echo "::set-output name=job_successful::true" > job_successful |
| 123 | + - if: steps.linter.outcome == 'success' || steps.linter.outcome == 'skipped' |
| 124 | + run: echo "::set-output name=linter_results::success" > linter_results |
| 125 | + - if: steps.unit-tests.outcome == 'success' || steps.unit-tests.outcome == 'skipped' |
| 126 | + run: echo "::set-output name=unit_tests_results::success" > unit_tests_results |
| 127 | + - if: steps.integration-tests.outcome == 'success' || steps.integration-tests.outcome == 'skipped' |
| 128 | + run: echo "::set-output name=integration_tests_results::success" > integration_tests_results |
| 129 | + functional-tests: |
| 130 | + needs: [ build-lint-test ] |
| 131 | + runs-on: ubuntu-latest |
| 132 | + name: Run functional tests |
| 133 | + strategy: |
| 134 | + matrix: |
| 135 | + group: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] |
17 | 136 | steps:
|
18 |
| - - uses: actions/checkout@v2 |
19 |
| - - name: Use Node.js |
20 |
| - uses: actions/setup-node@v2 |
21 |
| - with: |
22 |
| - node-version: '10.24.1' |
23 |
| - check-latest: false |
24 |
| - - run: yarn osd bootstrap |
25 |
| - - run: yarn lint |
| 137 | + - run: echo Running functional tests for ciGroup${{ matrix.group }} |
| 138 | + |
| 139 | + # Access a cache of set results from a previous run of the job |
| 140 | + # This is to prevent re-running a CI group that was already successful since it is not native to github actions |
| 141 | + # Can be used to verify flaky steps with reduced times |
| 142 | + - name: Restore the cached run |
| 143 | + uses: actions/cache@v2 |
| 144 | + with: |
| 145 | + path: | |
| 146 | + ftr_tests_results |
| 147 | + key: ${{ github.run_id }}-${{ github.job }}-${{ matrix.group }}-${{ github.sha }} |
| 148 | + restore-keys: | |
| 149 | + ${{ github.run_id }}-${{ github.job }}-${{ matrix.group }}-${{ github.sha }} |
| 150 | +
|
| 151 | + - name: Get the cached tests results |
| 152 | + id: ftr_tests_results |
| 153 | + run: cat ftr_tests_results 2>/dev/null || echo 'default' |
| 154 | + |
| 155 | + - name: Checkout code |
| 156 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 157 | + uses: actions/checkout@v2 |
| 158 | + |
| 159 | + - name: Setup Node |
| 160 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 161 | + uses: actions/setup-node@v2 |
| 162 | + with: |
| 163 | + node-version: "10.24.1" |
| 164 | + registry-url: 'https://registry.npmjs.org' |
| 165 | + |
| 166 | + - name: Setup Yarn |
| 167 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 168 | + run: | |
| 169 | + npm uninstall -g yarn |
| 170 | + |
| 171 | +
|
| 172 | + - name: Get cache path |
| 173 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 174 | + id: cache-path |
| 175 | + run: echo "::set-output name=CACHE_DIR::$(yarn cache dir)" |
| 176 | + |
| 177 | + - name: Setup cache |
| 178 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 179 | + uses: actions/cache@v2 |
| 180 | + with: |
| 181 | + path: ${{ steps.cache-path.outputs.CACHE_DIR }} |
| 182 | + key: ${{ runner.os }}-yarn-${{ env.CACHE_NAME }}-${{ hashFiles('**/yarn.lock') }} |
| 183 | + restore-keys: | |
| 184 | + ${{ runner.os }}-yarn-${{ env.CACHE_NAME }}- |
| 185 | + ${{ runner.os }}-yarn- |
| 186 | + ${{ runner.os }}- |
| 187 | +
|
| 188 | + # github virtual env is the latest chrome |
| 189 | + - name: Setup chromedriver |
| 190 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 191 | + run: yarn add --dev [email protected] |
| 192 | + |
| 193 | + - name: Run bootstrap |
| 194 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 195 | + run: yarn osd bootstrap |
| 196 | + |
| 197 | + - name: Build plugins |
| 198 | + if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 199 | + run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 10 |
| 200 | + |
| 201 | + - if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success' |
| 202 | + id: ftr-tests |
| 203 | + run: node scripts/functional_tests.js --config test/functional/config.js --include ciGroup${{ matrix.group }} |
| 204 | + env: |
| 205 | + CI_GROUP: ciGroup${{ matrix.group }} |
| 206 | + CI_PARALLEL_PROCESS_NUMBER: ciGroup${{ matrix.group }} |
| 207 | + JOB: ci${{ matrix.group }} |
| 208 | + CACHE_DIR: ciGroup${{ matrix.group }} |
| 209 | + |
| 210 | + - if: steps.ftr-tests.outcome == 'success' || steps.ftr-tests.outcome == 'skipped' |
| 211 | + run: echo "::set-output name=ftr_tests_results::success" > ftr_tests_results |
0 commit comments