From 3b78ca8d3af351c402704f419ddce3c514473387 Mon Sep 17 00:00:00 2001 From: jnsereko Date: Fri, 17 May 2024 08:10:37 +0300 Subject: [PATCH] Add openmrs e2e tests to test both LIME demo --- .github/workflows/run-e2e-tests.yml | 158 ++++++++++++++++++ distro/e2e_test_support_files/README.md | 3 +- .../docker-compose-build.yml | 6 +- .../extract_tag_numbers.sh | 13 +- 4 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/run-e2e-tests.yml diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml new file mode 100644 index 0000000..ef4ae9f --- /dev/null +++ b/.github/workflows/run-e2e-tests.yml @@ -0,0 +1,158 @@ +name: Run E2E Tests on Release PRs + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + outputs: + patient_management_ref: ${{steps.refs.outputs.patient_management}} + patient_chart_ref: ${{steps.refs.outputs.patient_chart}} + esm_core_ref: ${{steps.refs.outputs.esm_core}} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build and Run Containers + run: docker-compose -f distro/e2e_test_support_files/docker-compose-build.yml up -d + + - name: Wait for the backend to start + run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost/openmrs/login.htm)" != "200" ]]; do sleep 10; done + + - name: Commit and export Containers + run: sh distro/e2e_test_support_files/commit_and_export_images.sh + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: e2e_release_env_images + path: e2e_release_env_images.tar.gz + retention-days: 1 + + run-patient-management-e2e-tests: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - name: Create Temporary Directory to Download Docker Images + id: tempdir + run: echo "tmpdir=$(mktemp -d)" >> "$GITHUB_OUTPUT" + + - name: Download Docker Images + uses: actions/download-artifact@v3 + with: + name: e2e_release_env_images + path: ${{ steps.tempdir.outputs.tmpdir }} + + - name: Load Docker Images + run: | + gzip -d ${{ steps.tempdir.outputs.tmpdir }}/e2e_release_env_images.tar.gz + docker load --input ${{ steps.tempdir.outputs.tmpdir }}/e2e_release_env_images.tar + docker image ls -a + + - name: Spin up an OpenMRS Instance + run: docker-compose up -d + working-directory: distro/e2e_test_support_files + + - name: Checkout to the Repo's Tag + uses: actions/checkout@v4 + with: + repository: openmrs/openmrs-esm-patient-management + ref: ${{ needs.build.outputs.patient_management_ref }} + path: e2e_repo + + - name: Copy test environment variables + run: cp example.env .env + working-directory: e2e_repo + + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: yarn install --immutable + working-directory: e2e_repo + + - name: Install Playwright Browsers + run: npx playwright install chromium --with-deps + working-directory: e2e_repo + + - name: Wait for the OpenMRS instance to start + run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/openmrs/login.htm)" != "200" ]]; do sleep 10; done + + - name: Run E2E tests + run: yarn playwright test + working-directory: e2e_repo + + - name: Upload Report + uses: actions/upload-artifact@v3 + if: always() + with: + name: report-patient-management + path: e2e_repo/playwright-report/ + retention-days: 30 + + run-patient-chart-e2e-tests: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - name: Create Temporary Directory to Download Docker Images + id: tempdir + run: echo "tmpdir=$(mktemp -d)" >> "$GITHUB_OUTPUT" + + - name: Download Docker Images + uses: actions/download-artifact@v3 + with: + name: e2e_release_env_images + path: ${{ steps.tempdir.outputs.tmpdir }} + + - name: Load Docker Images + run: | + gzip -d ${{ steps.tempdir.outputs.tmpdir }}/e2e_release_env_images.tar.gz + docker load --input ${{ steps.tempdir.outputs.tmpdir }}/e2e_release_env_images.tar + docker image ls -a + + - name: Spin up an OpenMRS Instance + run: docker-compose up -d + working-directory: distro/e2e_test_support_files + + - name: Checkout to the Repo's Tag + uses: actions/checkout@v4 + with: + repository: openmrs/openmrs-esm-patient-chart + ref: ${{ needs.build.outputs.patient_chart_ref }} + path: e2e_repo + + - name: Copy test environment variables + run: cp example.env .env + working-directory: e2e_repo + + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: yarn install --immutable + working-directory: e2e_repo + + - name: Install Playwright Browsers + run: npx playwright install chromium --with-deps + working-directory: e2e_repo + + - name: Wait for the OpenMRS instance to start + run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/openmrs/login.htm)" != "200" ]]; do sleep 10; done + + - name: Run E2E tests + run: yarn playwright test + working-directory: e2e_repo + + - name: Upload Report + uses: actions/upload-artifact@v3 + if: always() + with: + name: report-patient-chart + path: e2e_repo/playwright-report/ + retention-days: 30 diff --git a/distro/e2e_test_support_files/README.md b/distro/e2e_test_support_files/README.md index 6afbc3a..39d633d 100644 --- a/distro/e2e_test_support_files/README.md +++ b/distro/e2e_test_support_files/README.md @@ -48,4 +48,5 @@ component. It then downloads Docker images from a previous "build" job, loads th The workflow checks out a specific tagged version of the component's repository, the tag is imported from the previous " build" job. This is necessary because the goal is to perform end-to-end tests on the codebase that corresponds to a -particular release version, rather than the code at the head of the repository. +particular release version, rather than the code at the head of the repository. In case of using pre-releases, it checkouts +to the main branch as we don't create tags for pre-releases. diff --git a/distro/e2e_test_support_files/docker-compose-build.yml b/distro/e2e_test_support_files/docker-compose-build.yml index a4527ce..9db2a0d 100644 --- a/distro/e2e_test_support_files/docker-compose-build.yml +++ b/distro/e2e_test_support_files/docker-compose-build.yml @@ -3,7 +3,7 @@ version: "3.7" services: gateway: build: - context: ../gateway + context: ../../gateway container_name: gateway restart: "unless-stopped" depends_on: @@ -14,7 +14,7 @@ services: frontend: build: - context: ../frontend + context: ../../frontend container_name: frontend restart: "unless-stopped" environment: @@ -30,7 +30,7 @@ services: backend: build: - context: ../ + context: ../../ container_name: backend depends_on: - db diff --git a/distro/e2e_test_support_files/extract_tag_numbers.sh b/distro/e2e_test_support_files/extract_tag_numbers.sh index f29decd..e607ad4 100644 --- a/distro/e2e_test_support_files/extract_tag_numbers.sh +++ b/distro/e2e_test_support_files/extract_tag_numbers.sh @@ -5,9 +5,16 @@ get_repository_tag() { local file="$1" local repo_name="$2" local app="$3" - local value - value=$(awk -F'"' -v app="$app" '$0 ~ app {print $4}' "$file") - echo "$repo_name=$value" + + local version=$(awk -F'"' -v app="$app" '$0 ~ app {print $4}' "$file") + local ref="refs/tags/v$version" + + # Check if the version number contains "pre" and modify the ref to main branch + if [[ $version == *"pre"* ]]; then + ref="main" + fi + + echo "$repo_name=$ref" } file_path="frontend/spa-build-config.json"