Skip to content

Commit

Permalink
Refactor e2e to increase speed and reliability (#5970)
Browse files Browse the repository at this point in the history
Co-authored-by: Rin Concordia <93527746+rin-skylight@users.noreply.github.com>
  • Loading branch information
zdeveloper and rin-skylight authored Jul 14, 2023
1 parent f795e6b commit d95685e
Show file tree
Hide file tree
Showing 125 changed files with 437 additions and 344 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Ignore the following directories
backend/build/
backend/.gradle/
frontend/build/
frontend/node_modules/
nginx/
ops/**/.terraform/
ops/services/app_functions/report_stream_batched_publisher/functions/node_modules/
docs/
.github/
.run/
node_modules/
cypress/node_modules/
cypress/screenshots/
cypress/videos/
4 changes: 2 additions & 2 deletions .env.cypress.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COMPOSE_HTTP_TIMEOUT=180

# Backend settings
SPRING_PROFILES_ACTIVE=e2e,db-dockerized
WIREMOCK_URL=http://cypress:8088
WIREMOCK_URL=http://wiremock:8088
SPRING_LIQUIBASE_ENABLED="true"
OKTA_TESTING_DISABLEHTTPSCHECK="true"

Expand All @@ -28,7 +28,7 @@ REACT_APP_BACKEND_URL=https://localhost.simplereport.gov/api
PUBLIC_URL=/app/
REACT_APP_OKTA_ENABLED=true
REACT_APP_DISABLE_MAINTENANCE_BANNER=true
REACT_APP_OKTA_URL=http://cypress:8088
REACT_APP_OKTA_URL=http://wiremock:8088
REACT_APP_BASE_URL=https://localhost.simplereport.gov

REACT_APP_OKTA_CLIENT_ID=
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/buildBackendImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: backend
context: ./
file: ./backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/buildFrontendImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: frontend
context: ./
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"REACT_APP_OKTA_URL=http://wiremock:8088"
"REACT_APP_OKTA_CLIENT_ID=0oa1k0163nAwfVxNW1d7"
"REACT_APP_BASE_URL=https://localhost.simplereport.gov"
"REACT_APP_BACKEND_URL=https://localhost.simplereport.gov/api"
"PUBLIC_URL=/app/"
"REACT_APP_OKTA_ENABLED=true"
"REACT_APP_DISABLE_MAINTENANCE_BANNER=true"
- name: Set version output
shell: bash
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/buildFrontendLighthouseImage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build frontend docker image with okta disabled

on:
workflow_dispatch:
workflow_call:
inputs:
force_build:
description: Force build
required: false
default: false
type: boolean
outputs:
version:
description: docker image version
value: ${{ jobs.build_and_push_frontend_image.outputs.version }}

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/frontend-lighthouse

jobs:

frontend_changes:
with:
what_to_check: frontend
uses: ./.github/workflows/checkForChanges.yml

build_and_push_frontend_image:
# We want to build the image if there are changes in the frontend folder, or if we are forcing a build, or if we are on the main branch
if: needs.frontend_changes.outputs.has_changes == 'true' || inputs.force_build == true || github.ref == 'refs/heads/main'
needs: [frontend_changes]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.set.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"REACT_APP_BASE_URL=https://localhost.simplereport.gov"
"REACT_APP_BACKEND_URL=https://localhost.simplereport.gov/api"
"PUBLIC_URL=/app/"
"REACT_APP_OKTA_ENABLED=false"
"REACT_APP_DISABLE_MAINTENANCE_BANNER=true"
- name: Set version output
shell: bash
id: set
run: echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> "$GITHUB_OUTPUT"
2 changes: 1 addition & 1 deletion .github/workflows/checkForChanges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
value: ${{ jobs.check_for_changes.outputs.has_changes }}
jobs:
check_for_changes:
runs-on: 'ubuntu-20.04'
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check_for_changes.outputs.has_changes }}
steps:
Expand Down
33 changes: 7 additions & 26 deletions .github/workflows/e2eLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ jobs:
with:
swap-size-gb: 10

- name: Generate certs
run: |
echo "::group::Generate ssl certs"
sudo apt update
sudo apt install libnss3-tools
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install mkcert
mkcert -install
mkdir -p certs
cd certs
mkcert localhost.simplereport.gov
mv localhost.simplereport.gov.pem localhost.simplereport.gov.crt
mv localhost.simplereport.gov-key.pem localhost.simplereport.gov.key
cd ..
echo "::endgroup::"
- name: Update files permissions
# Even though we don't use it, we need the .env file created here due to an issue similar to this one: https://github.com/mutagen-io/mutagen/issues/265
run: |
Expand Down Expand Up @@ -104,16 +88,17 @@ jobs:
SMARTY_AUTH_TOKEN: ${{ secrets.SMARTY_AUTH_TOKEN }}
SPRING_LIQUIBASE_ENABLED: "true"
GIT_DISCOVERY_ACROSS_FILESYSTEM: 1
WIREMOCK_URL: "http://wiremock:8088"
# cypress settings
CYPRESS_OKTA_REDIRECT_URI: "https%3A%2F%2Flocalhost.simplereport.gov%2Fapp"
CYPRESS_OKTA_USERNAME: ${{ secrets.CYPRESS_OKTA_USERNAME }}
CYPRESS_OKTA_PASSWORD: ${{ secrets.CYPRESS_OKTA_PASSWORD }}
CYPRESS_OKTA_SECRET: ${{ secrets.CYPRESS_OKTA_SECRET }}
CYPRESS_BACKEND_URL: "https://localhost.simplereport.gov/api"
WIREMOCK_URL: "http://cypress:8088"
SPEC_PATH: "cypress/e2e/**"
TEST_ENV: "https://localhost.simplereport.gov"
# frontend settings
REACT_APP_OKTA_URL: "http://cypress:8088"
REACT_APP_OKTA_URL: "http://wiremock:8088"
REACT_APP_OKTA_CLIENT_ID: 0oa1k0163nAwfVxNW1d7
REACT_APP_BASE_URL: https://localhost.simplereport.gov
REACT_APP_BACKEND_URL: https://localhost.simplereport.gov/api
Expand All @@ -135,12 +120,8 @@ jobs:
if: always()
shell: bash
run: |
CONTAINERS=$(docker ps -a --format '{{.Names}}')
for container in $CONTAINERS
do
echo "Saving $container logs"
docker logs $container >& cypress/${container}.log
done
echo "Saving $container logs"
docker compose -f docker-compose.yml -f docker-compose.cypress.yml logs --timestamps >& cypress-run.log
- name: Stop containers
if: always()
Expand All @@ -151,7 +132,7 @@ jobs:
echo "::endgroup::"
- name: Archive cypress failures
if: failure()
if: always()
uses: actions/upload-artifact@v3
with:
name: cypress-results
Expand All @@ -164,4 +145,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: logs
path: cypress/*.log
path: cypress-run.log
50 changes: 27 additions & 23 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
name: "Run Lighthouse Audit"
name: Run Lighthouse Audit
on:
workflow_dispatch:
pull_request:
branches:
- "**"
workflow_call:
inputs:
DOCKER_BACKEND_IMAGE_VERSION:
required: false
type: string
DOCKER_DATABASE_IMAGE_VERSION:
required: false
type: string
DOCKER_NGINX_IMAGE_VERSION:
required: false
type: string
DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION:
required: false
type: string

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -23,22 +33,6 @@ jobs:
with:
swap-size-gb: 10

- name: Generate certs
run: |
echo "::group::Generate ssl certs"
sudo apt update
sudo apt install libnss3-tools
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install mkcert
mkcert -install
mkdir -p certs
cd certs
mkcert localhost.simplereport.gov
mv localhost.simplereport.gov.pem localhost.simplereport.gov.crt
mv localhost.simplereport.gov-key.pem localhost.simplereport.gov.key
cd ..
echo "::endgroup::"
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 localhost.simplereport.gov" | sudo tee -a /etc/hosts
Expand Down Expand Up @@ -66,11 +60,21 @@ jobs:
# docker settings
DOCKER_CLIENT_TIMEOUT: 180
COMPOSE_HTTP_TIMEOUT: 180
DOCKER_BACKEND_IMAGE_VERSION: ${{ inputs.DOCKER_BACKEND_IMAGE_VERSION }}
DOCKER_DATABASE_IMAGE_VERSION: ${{ inputs.DOCKER_DATABASE_IMAGE_VERSION }}
DOCKER_NGINX_IMAGE_VERSION: ${{ inputs.DOCKER_NGINX_IMAGE_VERSION }}
DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION: ${{ inputs.DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION }}
shell: bash
run: |
echo "::group::Running containers"
echo "Backend branch tag (or latest): ${{ inputs.DOCKER_BACKEND_IMAGE_VERSION }}"
echo "Database branch tag (or latest): ${{ inputs.DOCKER_DATABASE_IMAGE_VERSION }}"
echo "Nginx branch tag (or latest): ${{ inputs.DOCKER_NGINX_IMAGE_VERSION }}"
echo "Frontend branch tag (or latest): ${{ inputs.DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION }}"
echo "::endgroup::"
echo "::group::Run Lighthouse locally"
npm install -g @lhci/cli@0.9.x
lhci autorun
bash lighthouse.sh
echo "::endgroup::"
- name: Archive Lighthouse results
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/testingWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
build_frontend_image:
uses: ./.github/workflows/buildFrontendImage.yml

build_frontend_lighthouse_image:
uses: ./.github/workflows/buildFrontendLighthouseImage.yml

build_nginx_image:
uses: ./.github/workflows/buildNginxImage.yml

Expand All @@ -47,7 +50,18 @@ jobs:
DOCKER_DATABASE_IMAGE_VERSION: ${{ needs.build_database_image.outputs.version }}
DOCKER_FRONTEND_IMAGE_VERSION: ${{ needs.build_frontend_image.outputs.version }}
DOCKER_NGINX_IMAGE_VERSION: ${{ needs.build_nginx_image.outputs.version }}

lighthouse:
needs:
- build_backend_image
- build_database_image
- build_nginx_image
- build_frontend_lighthouse_image
uses: ./.github/workflows/lighthouse.yml
with:
DOCKER_BACKEND_IMAGE_VERSION: ${{ needs.build_backend_image.outputs.version }}
DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION: ${{ needs.build_frontend_lighthouse_image.outputs.version }}
DOCKER_DATABASE_IMAGE_VERSION: ${{ needs.build_database_image.outputs.version }}
DOCKER_NGINX_IMAGE_VERSION: ${{ needs.build_nginx_image.outputs.version }}
tests:
needs:
- build_database_image
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ node_modules
*.orig
*.rej
/.env
/.env.local
certs/
yarn-error.log
backend/locust/__pycache__/
wiremock*.jar
cypress/cypress.env.json
frontend/src/.env.local
.run/Backend.run.xml
Expand Down
12 changes: 12 additions & 0 deletions .run/e2e local headless.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="e2e local headless" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/cypress/package.json" />
<command value="run" />
<scripts>
<script value="e2e:local:run" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
12 changes: 12 additions & 0 deletions .run/e2e local open.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="e2e local open" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/cypress/package.json" />
<command value="run" />
<scripts>
<script value="e2e:local" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>
Loading

0 comments on commit d95685e

Please sign in to comment.