EHR E2E Tests #3513
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: EHR E2E Tests | |
| env: | |
| NODE_VERSION: 22 | |
| TEST_RESULTS_CACHE_RETENTION_DAYS: 30 | |
| SECRETS_REPOSITORY: ${{ vars.SECRETS_REPOSITORY }} # Secrets repository for configuration files | |
| PLAYWRIGHT_CACHE_PATH: ~/.cache/ms-playwright | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to run tests on' | |
| required: true | |
| type: choice | |
| options: | |
| - e2e | |
| - e2e2 | |
| - e2e3 | |
| - local | |
| - testing | |
| - development | |
| - staging | |
| - demo | |
| default: 'local' | |
| mode: | |
| description: 'Tests running mode' | |
| required: false | |
| type: choice | |
| options: | |
| - normal | |
| - smoke | |
| default: 'normal' | |
| workflow_call: | |
| inputs: | |
| environment: | |
| required: false | |
| type: string | |
| jobs: | |
| check-changes: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 2 | |
| outputs: | |
| should-run: ${{ steps.check.outputs.should-run }} | |
| skip-reason: ${{ steps.check.outputs.skip-reason }} | |
| environment: ${{ steps.env.outputs.environment }} | |
| steps: | |
| - name: Determine Environment | |
| id: env | |
| run: | | |
| INPUT_ENV="${{ inputs.environment }}" | |
| if [ -n "$INPUT_ENV" ]; then | |
| echo "environment=$INPUT_ENV" >> $GITHUB_OUTPUT | |
| elif [ "${{ github.repository }}" == "masslight/ottehr" ]; then | |
| echo "environment=e2e" >> $GITHUB_OUTPUT | |
| else | |
| echo "environment=local" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Checkout repository | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| fetch-depth: 0 # Need full history for diffs in all scenarios | |
| - name: Check if EHR changes are relevant | |
| id: check | |
| run: | | |
| # For workflow_call or workflow_dispatch, check event type | |
| # If strictly workflow_dispatch, run unconditionally | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "should-run=true" >> $GITHUB_OUTPUT | |
| echo "skip-reason=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Check for force run command in PR description | |
| if [ "${{ contains(github.event.pull_request.body || '', '/run-ehr-e2e') }}" == "true" ]; then | |
| echo "Force run enabled via PR command /run-ehr-e2e" | |
| echo "should-run=true" >> $GITHUB_OUTPUT | |
| echo "skip-reason=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Check for skip command in PR description | |
| if [ "${{ contains(github.event.pull_request.body || '', '/skip-ehr-e2e') }}" == "true" ]; then | |
| echo "EHR E2E tests skipped via /skip-ehr-e2e command" | |
| echo "should-run=false" >> $GITHUB_OUTPUT | |
| echo "skip-reason=Skipped via /skip-ehr-e2e command" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # For other events, check changed files | |
| TRACKED_FILES=$(node -e " | |
| const config = require('./.github/trigger-paths.js'); | |
| console.log(config.getE2EPaths('ehr').join(' ')); | |
| ") | |
| node .github/check-changed-files.js $TRACKED_FILES | |
| ehr-e2e-tests-run: | |
| needs: check-changes | |
| if: always() && !cancelled() && needs.check-changes.outputs.should-run == 'true' | |
| runs-on: ubuntu-latest-8-cores | |
| timeout-minutes: 40 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: Restore node modules | |
| id: npm-cache-restore | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| with: | |
| path: | | |
| node_modules | |
| packages/*/node_modules | |
| apps/*/node_modules | |
| deploy/node_modules | |
| key: ${{ runner.os }}-npm-cache-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-npm-cache- | |
| - name: Install dependencies | |
| if: steps.npm-cache-restore.outputs.cache-hit != 'true' | |
| run: npm ci | |
| - name: Restore Playwright browsers | |
| id: playwright-cache-restore | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| with: | |
| path: ${{ env.PLAYWRIGHT_CACHE_PATH }} | |
| key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-playwright- | |
| - name: Install Playwright browsers | |
| run: npx playwright install chromium | |
| - name: Check out secrets repo | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| repository: ${{ env.SECRETS_REPOSITORY }} | |
| ssh-key: ${{ secrets.DEPLOY_OTTEHR_KEY }} | |
| path: 'secrets' | |
| - name: Setup environment | |
| run: | | |
| setup_env() { | |
| mkdir -p "packages/zambdas/.env" | |
| cp secrets/zambdas/* "packages/zambdas/.env" | |
| mkdir -p "apps/$app/env" | |
| cp "secrets/$app/app/tests."*.json "apps/$app/env/" | |
| cp "secrets/$app/app/.env"* "apps/$app/env/" | |
| } | |
| for app in ehr intake; do | |
| setup_env "$app" | |
| done | |
| - name: Restore seed data cache | |
| if: needs.check-changes.outputs.environment == 'local' || needs.check-changes.outputs.environment == 'e2e' || needs.check-changes.outputs.environment == 'e2e2' || needs.check-changes.outputs.environment == 'e2e3' | |
| uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| with: | |
| path: apps/ehr/tests/e2e-utils/seed-data/resources/ | |
| key: seed-data-${{ needs.check-changes.outputs.environment }}-${{ github.sha }}-${{ github.run_id }} | |
| fail-on-cache-miss: true | |
| - name: Run E2E tests | |
| run: | | |
| ENV="${{ needs.check-changes.outputs.environment }}" | |
| if [ "$ENV" == "local" ] || [ "$ENV" == "e2e" ] || [ "$ENV" == "e2e2" ] || [ "$ENV" == "e2e3" ]; then | |
| npm run ehr:e2e:$ENV:integration | |
| else | |
| MODE="${{ inputs.mode }}" | |
| if [ "$MODE" == "smoke" ]; then | |
| npm run ehr:e2e:$ENV:smoke | |
| else | |
| npm run ehr:e2e:$ENV | |
| fi | |
| fi | |
| env: | |
| CI: true | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: playwright-report-ehr-${{ needs.check-changes.outputs.environment }} | |
| path: | | |
| apps/ehr/playwright-report/ | |
| apps/ehr/test-results/ | |
| retention-days: ${{ env.TEST_RESULTS_CACHE_RETENTION_DAYS }} | |
| # This job always runs and satisfies branch protection rules | |
| ehr-e2e-tests: | |
| needs: [check-changes, ehr-e2e-tests-run] | |
| if: always() && !cancelled() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Report status | |
| run: | | |
| if [ "${{ needs.check-changes.outputs.should-run }}" == "false" ]; then | |
| echo "EHR E2E tests skipped: ${{ needs.check-changes.outputs.skip-reason }}" | |
| exit 0 | |
| elif [ "${{ needs.ehr-e2e-tests-run.result }}" == "success" ]; then | |
| echo "EHR E2E tests passed" | |
| exit 0 | |
| elif [ "${{ needs.ehr-e2e-tests-run.result }}" == "failure" ]; then | |
| echo "EHR E2E tests failed" | |
| exit 1 | |
| elif [ "${{ needs.ehr-e2e-tests-run.result }}" == "cancelled" ]; then | |
| echo "EHR E2E tests cancelled" | |
| exit 1 | |
| elif [ "${{ needs.ehr-e2e-tests-run.result }}" == "skipped" ]; then | |
| echo "EHR E2E tests skipped (execution job skipped)" | |
| exit 0 | |
| else | |
| echo "EHR E2E tests status unknown: ${{ needs.ehr-e2e-tests-run.result }}" | |
| exit 1 | |
| fi |