Skip to content

Commit

Permalink
(test) Use local shell to assemble E2E environment and run all E2E te…
Browse files Browse the repository at this point in the history
…sts from other repos (#1139)

* Use local shell to assemble and build E2E environment

* Commit and export images

* Name the db container

* Uncomment the export script

* Uncomment the export script

* Update the spinup command

* Remove the exporting

* Remove the job dependancy

* fix the build

* install dependancies

* Install browsers

* Add matrix stratergy

* Add other apps

* Fix typo

* Final touches
  • Loading branch information
jayasanka-sack authored Sep 5, 2024
1 parent 4397f11 commit d3a5bf3
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 14 deletions.
96 changes: 86 additions & 10 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- 'example.env'
- '.github/workflows/e2e.yml'
main:
run-e2e-on-esm-core:
needs: changes
if: ${{ needs.changes.outputs.test-changes == 'true' }}

Expand Down Expand Up @@ -74,35 +74,111 @@ jobs:
- name: Install dependencies
run: yarn install --immutable

- name: Setup local cache server for Turborepo
uses: felixmosh/turborepo-gh-artifacts@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
server-token: ${{ env.TURBO_TOKEN }}

- name: Build apps
run: yarn turbo run build --color --concurrency=5

- name: Run dev server
run: bash e2e/support/github/run-e2e-docker-env.sh

- name: Copy test environment variables
run: cp example.env .env

- name: Install Playwright Browsers
run: yarn playwright install chromium --with-deps
run: npx playwright install chromium --with-deps

- 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

- name: Upload Report
uses: actions/upload-artifact@v4
if: always()
with:
name: report-esm-core
path: playwright-report/
retention-days: 30


run-e2e-on-other-repos:
needs: changes
if: ${{ needs.changes.outputs.test-changes == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
repo:
- openmrs-esm-patient-management
- openmrs-esm-patient-chart
- openmrs-esm-form-builder

steps:
- name: Checkout esm-core repo
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache dependencies
id: cache
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Setup local cache server for Turborepo
uses: felixmosh/turborepo-gh-artifacts@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
server-token: ${{ env.TURBO_TOKEN }}

- name: Install dependencies
run: yarn install --immutable

- name: Build apps
run: yarn turbo run build --color --concurrency=5

- name: Run dev server
run: bash e2e/support/github/run-e2e-docker-env.sh

- name: Wait for OpenMRS instance to start
- name: Checkout to the ${{ matrix.repo }} main branch
uses: actions/checkout@v4
with:
repository: openmrs/${{ matrix.repo }}
ref: main
path: e2e_repo

- name: Copy test environment variables
run: cp example.env .env
working-directory: e2e_repo

- name: Install dependencies
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: Stop dev server
if: '!cancelled()'
run: docker stop $(docker ps -a -q)

- name: Upload report
- name: Upload Report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
name: report-${{ matrix.repo }}
path: e2e_repo/playwright-report/
retention-days: 30
2 changes: 2 additions & 0 deletions e2e/support/github/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# .dockerignore
node_modules
7 changes: 5 additions & 2 deletions e2e/support/github/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ WORKDIR /app

COPY . .

RUN npm_config_legacy_peer_deps=true npm install -g openmrs@${APP_SHELL_VERSION:-next}
ARG CACHE_BUST
RUN npm_config_legacy_peer_deps=true openmrs assemble --manifest --mode config --config spa-assemble-config.json --target ./spa

RUN yarn install
RUN npm_config_legacy_peer_deps=true node packages/tooling/openmrs/dist/cli.js assemble --manifest --mode config --config spa-assemble-config.json --target ./spa
RUN npm_config_legacy_peer_deps=true node packages/tooling/openmrs/dist/cli.js build --target ./spa


FROM --platform=$BUILDPLATFORM openmrs/openmrs-reference-application-3-frontend:nightly as frontend
FROM nginx:1.23-alpine
Expand Down
17 changes: 17 additions & 0 deletions e2e/support/github/commit_and_export_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

backend_container_id=$(docker ps --filter "name=backend" --format "{{.ID}}")
db_container_id=$(docker ps --filter "name=db" --format "{{.ID}}")
frontend_container_id=$(docker ps --filter "name=frontend" --format "{{.ID}}")
gateway_container_id=$(docker ps --filter "name=gateway" --format "{{.ID}}")

docker commit $frontend_container_id frontend
docker commit $gateway_container_id gateway
docker commit $backend_container_id backend
docker commit $db_container_id db

docker save frontend > e2e_release_env_images.tar
docker save frontend gateway backend db > e2e_release_env_images.tar

# compress the file (to decrease the upload file size)
gzip -c e2e_release_env_images.tar > e2e_release_env_images.tar.gz
4 changes: 4 additions & 0 deletions e2e/support/github/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ version: "3.7"

services:
gateway:
container_name: gateway
image: openmrs/openmrs-reference-application-3-gateway:${TAG:-nightly}
ports:
- "8080:80"

frontend:
container_name: frontend
build:
context: .
environment:
SPA_PATH: /openmrs/spa
API_URL: /openmrs

backend:
container_name: backend
image: openmrs/openmrs-reference-application-3-backend:nightly-with-data
depends_on:
- db

db:
container_name: db
image: openmrs/openmrs-reference-application-3-db:nightly-with-data
53 changes: 51 additions & 2 deletions e2e/support/github/run-e2e-docker-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

# get the dir containing the script
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
repository_root="$script_dir/../../../."
# create a temporary working directory
working_dir=$(mktemp -d "${TMPDIR:-/tmp/}openmrs-e2e-frontends.XXXXXXXXXX")
echo $working_dir
# get a list of all the apps in this workspace
apps=$(yarn workspaces list --json | jq -r 'if .location | test("-app$") then .name else empty end')
# this array will hold all of the packed app names
Expand All @@ -20,7 +22,7 @@ do
# run yarn pack for our app and add it to the working directory
yarn workspace "$app" pack -o "$working_dir/$app_name.tgz" >/dev/null;
done;
echo "Created packed app archives"
echo "Created packed app archives"

echo "Creating dynamic spa-assemble-config.json..."
# dynamically assemble our list of frontend modules, prepending the
Expand All @@ -29,17 +31,64 @@ echo "Creating dynamic spa-assemble-config.json..."
jq -n \
--arg apps "$apps" \
--arg app_names "$(echo ${app_names[@]})" \
'(
'{
"@openmrs/esm-active-visits-app": "next",
"@openmrs/esm-appointments-app": "next",
"@openmrs/esm-cohort-builder-app": "next",
"@openmrs/esm-devtools-app": "next",
"@openmrs/esm-dispensing-app": "next",
"@openmrs/esm-fast-data-entry-app": "next",
"@openmrs/esm-form-builder-app": "next",
"@openmrs/esm-form-engine-app": "next",
"@openmrs/esm-generic-patient-widgets-app": "next",
"@openmrs/esm-home-app": "next",
"@openmrs/esm-laboratory-app": "next",
"@openmrs/esm-openconceptlab-app": "next",
"@openmrs/esm-patient-allergies-app": "next",
"@openmrs/esm-patient-attachments-app": "next",
"@openmrs/esm-patient-banner-app": "next",
"@openmrs/esm-patient-chart-app": "next",
"@openmrs/esm-patient-conditions-app": "next",
"@openmrs/esm-patient-flags-app": "next",
"@openmrs/esm-patient-forms-app": "next",
"@openmrs/esm-patient-immunizations-app": "next",
"@openmrs/esm-patient-labs-app": "next",
"@openmrs/esm-patient-list-management-app": "next",
"@openmrs/esm-patient-lists-app": "next",
"@openmrs/esm-patient-medications-app": "next",
"@openmrs/esm-patient-notes-app": "next",
"@openmrs/esm-patient-orders-app": "next",
"@openmrs/esm-patient-programs-app": "next",
"@openmrs/esm-patient-registration-app": "next",
"@openmrs/esm-patient-search-app": "next",
"@openmrs/esm-patient-vitals-app": "next",
"@openmrs/esm-service-queues-app": "next",
"@openmrs/esm-system-admin-app": "next"
} + (
($apps | split("\n")) as $apps | ($app_names | split(" ") | map("/app/" + .)) as $app_files
| [$apps, $app_files]
| transpose
| map({"key": .[0], "value": .[1]})
| from_entries
)' | jq '{"frontendModules": .}' > "$working_dir/spa-assemble-config.json"

echo "Created dynamic spa-assemble-config.json"

echo "Copying tooling, shell and framework..."
mkdir -p "$working_dir/packages"
mkdir -p "$working_dir/packages/tooling"

cp -r "$repository_root/.yarn" "$working_dir/.yarn"
cp -r "$repository_root/.yarnrc.yml" "$working_dir/.yarnrc.yml"
cp -r "$repository_root/packages/tooling" "$working_dir/packages"
cp -r "$repository_root/packages/shell" "$working_dir/packages"
cp -r "$repository_root/packages/framework" "$working_dir/packages"
cp "$repository_root/package.json" "$working_dir/package.json"
cp "$repository_root/yarn.lock" "$working_dir/yarn.lock"

echo "Copying Docker configuration..."
cp "$script_dir/Dockerfile" "$working_dir/Dockerfile"
cp "$script_dir/.dockerignore" "$working_dir/.dockerignore"
cp "$script_dir/docker-compose.yml" "$working_dir/docker-compose.yml"

cd $working_dir
Expand Down

0 comments on commit d3a5bf3

Please sign in to comment.