diff --git a/ci/e2e-tests-exceptions.yml b/ci/e2e-tests-exceptions.yml new file mode 100644 index 0000000..d915fcd --- /dev/null +++ b/ci/e2e-tests-exceptions.yml @@ -0,0 +1,11 @@ +name: 'dhis2: e2e tests exceptions' + +on: + push: + +jobs: + call-e2e-tests-result: + if: github.actor == 'dhis2-bot' || contains(github.event.head_commit.message, '[skip ci]') + uses: ./.github/workflows/e2e-tests-result.yml + with: + result: true diff --git a/ci/e2e-tests-result.yml b/ci/e2e-tests-result.yml new file mode 100644 index 0000000..153bdcd --- /dev/null +++ b/ci/e2e-tests-result.yml @@ -0,0 +1,24 @@ +name: 'dhis2: result of e2e tests' + +# The job here (e2e-tests-success) will be set to true if all the tests pass. +# Setting "call-e2e-tests-result / e2e-tests-success" as a required step in your workflow is recommended. + +on: + workflow_call: + inputs: + result: + required: true + type: boolean + +defaults: + run: + shell: bash + +jobs: + e2e-tests-success: + runs-on: ubuntu-latest + steps: + - name: verify + run: if [ $result != true ]; then exit 1; fi; + env: + result: ${{ inputs.result }} diff --git a/ci/e2e-tests-skip.yml b/ci/e2e-tests-skip.yml new file mode 100644 index 0000000..ebd7d26 --- /dev/null +++ b/ci/e2e-tests-skip.yml @@ -0,0 +1,12 @@ +name: 'dhis2: skip e2e tests' + +on: + pull_request_target: + types: [labeled] + +jobs: + call-e2e-tests-result: + if: github.event.label.name == 'skip-e2e-tests' + uses: ./.github/workflows/e2e-tests-result.yml + with: + result: true diff --git a/ci/e2e-tests.yml b/ci/e2e-tests.yml new file mode 100644 index 0000000..f527cf1 --- /dev/null +++ b/ci/e2e-tests.yml @@ -0,0 +1,120 @@ +name: 'dhis2: e2e tests' + +# Requirements: +# +# - Secrets: +# GITHUB_TOKEN +# CYPRESS_DHIS2_USERNAME +# CYPRESS_DHIS2_PASSWORD +# +# - Customize environment variables: +# URL_PREFIX_INSTANCES: Set the URL prefix for your instances. +# 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. +# Example: https://test.e2e.dhis2.org/test- +# CYPRESS_CONTAINERS: Set the number of parallel Cypress job runs running for each backend version. +# TRIGGER_LABELS: Set the labels that will trigger the workflow. +# +# - Set status check as required: +# We recommend setting "call-e2e-tests-result / e2e-tests-success" as a required step in your workflow. +# This will ensure that one of the following must be true before the PR can be merged: +# 1) The tests have successfully run +# 2) The dev took a conscious decision not to run the tests (see e2e-tests-skip.yml) +# 3) They were skipped due to a special case (see e2e-tests-exception.yml) + +on: + pull_request: + types: [labeled] + +env: + URL_PREFIX_INSTANCES: [YOUR URL PREFIX] + CYPRESS_CONTAINERS: 6 + TRIGGER_LABELS: e2e-tests, testing + +defaults: + run: + shell: bash + +jobs: + prerequisites: + runs-on: ubuntu-latest + outputs: + json-labels: ${{ steps.json-labels.outputs.labels }} + matrix-containers: ${{ steps.matrix-containers.outputs.containers }} + versions: ${{ steps.legacy-versions.outputs.versions }} + steps: + - name: compute-json-labels + id: json-labels + run: | + arrLabels=(${TRIGGER_LABELS//,/ }) + for item in ${arrLabels[@]}; do labels+=\"$item\",; done + echo "::set-output name=labels::[ ${labels%,} ]" + + - name: compute-matrix-containers + id: matrix-containers + if: contains(fromJson(steps.json-labels.outputs.labels), github.event.label.name) + run: | + for (( cnt = 1; cnt <= $CYPRESS_CONTAINERS; cnt++)); do containers+=$cnt,; done + echo "::set-output name=containers::[ ${containers%,} ]" + + - if: contains(fromJson(steps.json-labels.outputs.labels), github.event.label.name) + uses: actions/checkout@v2 + + - id: legacy-versions + if: contains(fromJson(steps.json-labels.outputs.labels), github.event.label.name) + uses: dhis2/action-supported-legacy-versions@v1 + with: + instance-url-latest: ${{ env.URL_PREFIX_INSTANCES }}dev # can be removed if maxDHIS2Version has been specified + username: ${{ secrets.CYPRESS_DHIS2_USERNAME }} # can be removed if maxDHIS2Version has been specified + password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }} # can be removed if maxDHIS2Version has been specified + + cypress: + needs: prerequisites + if: contains(fromJson(needs.prerequisites.outputs.json-labels), github.event.label.name) + runs-on: ubuntu-latest + container: cypress/browsers:node14.7.0-chrome84 + strategy: + fail-fast: false + matrix: + versions: ${{ fromJSON(needs.prerequisites.outputs.versions) }} + containers: ${{ fromJSON(needs.prerequisites.outputs.matrix-containers) }} + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v1 + with: + node-version: 14.x + + - uses: actions/cache@v2 + id: yarn-cache + with: + path: '**/node_modules' + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + + - name: Install + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: yarn install --frozen-lockfile + + - name: Cypress run + uses: cypress-io/github-action@v2 + with: + record: true + parallel: true + group: e2e-chrome-parallel-${{ matrix.versions }} + browser: chrome + start: yarn d2-app-scripts start + wait-on: http://localhost:3000 + wait-on-timeout: 300 + env: + CI: true + CYPRESS_RECORD_KEY: '6b0bce0d-a4e8-417b-bbee-9157cbe9a999' + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CYPRESS_dhis2BaseUrl: ${{ env.URL_PREFIX_INSTANCES }}${{ matrix.versions }} + CYPRESS_dhis2InstanceVersion: ${{ matrix.versions }} + CYPRESS_dhis2Username: ${{ secrets.CYPRESS_DHIS2_USERNAME }} + CYPRESS_dhis2Password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }} + + call-e2e-tests-result: + needs: cypress + uses: ./.github/workflows/e2e-tests-result.yml + with: + result: true