Backend e2e tests #147
This file contains 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: Backend e2e tests | |
on: | |
workflow_run: | |
workflows: ["Continuous Integration"] | |
branches: [main] | |
types: | |
- completed | |
workflow_dispatch: | |
inputs: | |
run_backend_e2e_tests: | |
description: Run e2e tests of backend app | |
required: false | |
type: boolean | |
env: | |
FUSIONAUTH_HOST: "http://localhost:9011" | |
FUSIONAUTH_ISSUER: "http://localhost:9011" | |
FUSIONAUTH_API_KEY: "fusionauth_api_key_${{ github.run_id }}_${{ github.run_attempt }}" | |
POSTGRES_USER: "postgres" | |
POSTGRES_PASSWORD: "postgres-password-${{ github.run_id }}-${{ github.run_attempt }}" | |
FUSIONAUTH_POSTGRESQL_PASSWORD: "fusionauth-postgresql-password-${{ github.run_id }}-${{ github.run_attempt }}" | |
MONGO_INITDB_DATABASE: "you-say" | |
MONGO_INITDB_ROOT_USERNAME: "mongodb-root-user-${{ github.run_id }}-${{ github.run_attempt }}" | |
MONGO_INITDB_ROOT_PASSWORD: "mongodb-root-password-${{ github.run_id }}-${{ github.run_attempt }}" | |
OAUTH_CONFIGURATION_CLIENT_SECRET: "client_secret_${{ github.run_id }}_${{ github.run_attempt }}" | |
APP_HOST: "localhost" | |
NODE_ENV: "production" | |
SWAGGER_PATH: "docs" | |
FRONTEND_URL: "http://localhost:3000" | |
jobs: | |
build-and-test-backend-e2e: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 45 | |
if: ${{ | |
github.event.workflow_run.conclusion == 'success' || | |
github.event_name == 'workflow_dispatch' && inputs.run_backend_e2e_tests == true }} | |
steps: | |
- name: Clone you-say repo in Ubuntu | |
uses: actions/checkout@v4 | |
- name: Check if the changes were made to our backend | |
uses: dorny/paths-filter@v3 | |
id: changed-paths | |
with: | |
filters: | | |
is-backend: | |
- 'apps/backend/**' | |
- 'apps/backend-e2e/**' | |
- 'libs/backend/auth/**' | |
- '.github/workflows/backend-e2e-tests.workflow.yml' | |
- if: ${{ steps.changed-paths.outputs.is-backend == 'true' }} | |
name: Setup docker | |
uses: ./.github/actions/setup-docker-composite | |
- if: ${{ steps.changed-paths.outputs.is-backend == 'true' }} | |
name: Build and start backend application + FusionAuth | |
uses: ./.github/actions/backend-app-composite | |
with: | |
fusionauth_api_key: ${{ env.FUSIONAUTH_API_KEY }} | |
- if: ${{ steps.changed-paths.outputs.is-backend == 'true' }} | |
name: Configuring infrastructure with terraform | |
id: terraform | |
uses: ./.github/actions/terraform-composite | |
with: | |
fusionauth_host: ${{ env.FUSIONAUTH_HOST }} | |
fusionauth_issuer: ${{ env.FUSIONAUTH_ISSUER }} | |
fusionauth_api_key: ${{ env.FUSIONAUTH_API_KEY }} | |
oauth_configuration_client_secret: ${{ env.OAUTH_CONFIGURATION_CLIENT_SECRET }} | |
fusionauth_email_configuration_password: ${{ env.FUSIONAUTH_EMAIL_CONFIGURATION_PASSWORD }} | |
- if: ${{ steps.changed-paths.outputs.is-backend == 'true' }} | |
name: Starting backend service | |
run: docker compose up -d | |
env: | |
FUSIONAUTH_TENANT_ID: ${{ steps.terraform.outputs.fusionauth_tenant_id }} | |
FUSIONAUTH_APPLICATION_ID: ${{ steps.terraform.outputs.fusionauth_application_id }} | |
FUSIONAUTH_ADMIN_GROUP_ID: ${{ steps.terraform.outputs.fusionauth_admin_group_id }} | |
DATABASE_URL: "mongodb://${{ env.MONGO_INITDB_ROOT_USERNAME }}:${{ env.MONGO_INITDB_ROOT_PASSWORD }}@localhost:27017" | |
FUSIONAUTH_OAUTH_SCOPES: offline_access openid | |
- if: ${{ steps.changed-paths.outputs.is-backend == 'true' }} | |
name: Generate Open API | |
run: npx nx openapi:generate backend | |
env: | |
FUSIONAUTH_TENANT_ID: ${{ steps.terraform.outputs.fusionauth_tenant_id }} | |
FUSIONAUTH_APPLICATION_ID: ${{ steps.terraform.outputs.fusionauth_application_id }} | |
FUSIONAUTH_ADMIN_GROUP_ID: ${{ steps.terraform.outputs.fusionauth_admin_group_id }} | |
DATABASE_URL: "mongodb://${{ env.MONGO_INITDB_ROOT_USERNAME }}:${{ env.MONGO_INITDB_ROOT_PASSWORD }}@localhost:27017" | |
- if: ${{ steps.changed-paths.outputs.is-backend == 'true' }} | |
name: Execute e2e tests | |
run: npx nx test:e2e backend-e2e | |
env: | |
FUSIONAUTH_TENANT_ID: ${{ steps.terraform.outputs.fusionauth_tenant_id }} | |
FUSIONAUTH_APPLICATION_ID: ${{ steps.terraform.outputs.fusionauth_application_id }} | |
- name: Dump docker logs on failure | |
if: failure() | |
uses: jwalton/gh-docker-logs@v2 |