|
| 1 | +name: 'dhis2: e2e tests' |
| 2 | + |
| 3 | +# Requirements: |
| 4 | +# |
| 5 | +# - Secrets: |
| 6 | +# GITHUB_TOKEN |
| 7 | +# CYPRESS_DHIS2_USERNAME |
| 8 | +# CYPRESS_DHIS2_PASSWORD |
| 9 | +# |
| 10 | +# - Customize environment variables: |
| 11 | +# URL_PREFIX_INSTANCES: Set the URL prefix for your instances. |
| 12 | +# All instances are required to have this prefix followed by "[majorVersion].[minorVersion]" for released versions (e.g. 2.39) and "dev" for a dev instance. |
| 13 | +# Example: https://test.e2e.dhis2.org/test- |
| 14 | +# CYPRESS_CONTAINERS: Set the number of parallel Cypress job runs running for each backend version. |
| 15 | +# TRIGGER_LABELS: Set the labels that will trigger the workflow. |
| 16 | +# |
| 17 | +# - Set status check as required: |
| 18 | +# We recommend setting "call-e2e-tests-result / e2e-tests-success" as a required step in your workflow. |
| 19 | +# This will ensure that one of the following must be true before the PR can be merged: |
| 20 | +# 1) The tests have successfully run |
| 21 | +# 2) The dev took a conscious decision not to run the tests (see e2e-tests-skip.yml) |
| 22 | +# 3) They were skipped due to a special case (see e2e-tests-exception.yml) |
| 23 | + |
| 24 | +on: |
| 25 | + pull_request: |
| 26 | + types: [labeled] |
| 27 | + |
| 28 | +env: |
| 29 | + URL_PREFIX_INSTANCES: [YOUR URL PREFIX] |
| 30 | + CYPRESS_CONTAINERS: 6 |
| 31 | + TRIGGER_LABELS: e2e-tests, testing |
| 32 | + |
| 33 | +defaults: |
| 34 | + run: |
| 35 | + shell: bash |
| 36 | + |
| 37 | +jobs: |
| 38 | + prerequisites: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + json-labels: ${{ steps.json-labels.outputs.labels }} |
| 42 | + matrix-containers: ${{ steps.matrix-containers.outputs.containers }} |
| 43 | + versions: ${{ steps.legacy-versions.outputs.versions }} |
| 44 | + steps: |
| 45 | + - name: compute-json-labels |
| 46 | + id: json-labels |
| 47 | + run: | |
| 48 | + arrLabels=(${TRIGGER_LABELS//,/ }) |
| 49 | + for item in ${arrLabels[@]}; do labels+=\"$item\",; done |
| 50 | + echo "::set-output name=labels::[ ${labels%,} ]" |
| 51 | +
|
| 52 | + - name: compute-matrix-containers |
| 53 | + id: matrix-containers |
| 54 | + if: contains(fromJson(steps.json-labels.outputs.labels), github.event.label.name) |
| 55 | + run: | |
| 56 | + for (( cnt = 1; cnt <= $CYPRESS_CONTAINERS; cnt++)); do containers+=$cnt,; done |
| 57 | + echo "::set-output name=containers::[ ${containers%,} ]" |
| 58 | +
|
| 59 | + - if: contains(fromJson(steps.json-labels.outputs.labels), github.event.label.name) |
| 60 | + uses: actions/checkout@v2 |
| 61 | + |
| 62 | + - id: legacy-versions |
| 63 | + if: contains(fromJson(steps.json-labels.outputs.labels), github.event.label.name) |
| 64 | + uses: dhis2/action-supported-legacy-versions@v1 |
| 65 | + with: |
| 66 | + instance-url-latest: ${{ env.URL_PREFIX_INSTANCES }}dev # can be removed if maxDHIS2Version has been specified |
| 67 | + username: ${{ secrets.CYPRESS_DHIS2_USERNAME }} # can be removed if maxDHIS2Version has been specified |
| 68 | + password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }} # can be removed if maxDHIS2Version has been specified |
| 69 | + |
| 70 | + cypress: |
| 71 | + needs: prerequisites |
| 72 | + if: contains(fromJson(needs.prerequisites.outputs.json-labels), github.event.label.name) |
| 73 | + runs-on: ubuntu-latest |
| 74 | + container: cypress/browsers:node14.7.0-chrome84 |
| 75 | + strategy: |
| 76 | + fail-fast: false |
| 77 | + matrix: |
| 78 | + versions: ${{ fromJSON(needs.prerequisites.outputs.versions) }} |
| 79 | + containers: ${{ fromJSON(needs.prerequisites.outputs.matrix-containers) }} |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@v2 |
| 82 | + |
| 83 | + - uses: actions/setup-node@v1 |
| 84 | + with: |
| 85 | + node-version: 14.x |
| 86 | + |
| 87 | + - uses: actions/cache@v2 |
| 88 | + id: yarn-cache |
| 89 | + with: |
| 90 | + path: '**/node_modules' |
| 91 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 92 | + |
| 93 | + - name: Install |
| 94 | + if: steps.yarn-cache.outputs.cache-hit != 'true' |
| 95 | + run: yarn install --frozen-lockfile |
| 96 | + |
| 97 | + - name: Cypress run |
| 98 | + uses: cypress-io/github-action@v2 |
| 99 | + with: |
| 100 | + record: true |
| 101 | + parallel: true |
| 102 | + group: e2e-chrome-parallel-${{ matrix.versions }} |
| 103 | + browser: chrome |
| 104 | + start: yarn d2-app-scripts start |
| 105 | + wait-on: http://localhost:3000 |
| 106 | + wait-on-timeout: 300 |
| 107 | + env: |
| 108 | + CI: true |
| 109 | + CYPRESS_RECORD_KEY: '6b0bce0d-a4e8-417b-bbee-9157cbe9a999' |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + CYPRESS_dhis2BaseUrl: ${{ env.URL_PREFIX_INSTANCES }}${{ matrix.versions }} |
| 112 | + CYPRESS_dhis2InstanceVersion: ${{ matrix.versions }} |
| 113 | + CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }} |
| 114 | + CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }} |
| 115 | + |
| 116 | + call-e2e-tests-result: |
| 117 | + needs: cypress |
| 118 | + uses: ./.github/workflows/e2e-tests-result.yml |
| 119 | + with: |
| 120 | + result: true |
0 commit comments