Run app tests directly in cypress container 🌲 #31
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: CI/CD Pipeline | ||
on: | ||
push: | ||
pull_request: | ||
types: [opened, synchronize, closed] | ||
workflow_dispatch: | ||
inputs: | ||
test: | ||
type: boolean | ||
description: 'Run tests' | ||
required: true | ||
default: true | ||
deploy: | ||
type: boolean | ||
description: 'Deploy application' | ||
required: true | ||
default: false | ||
jobs: | ||
build-api: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: docker/setup-buildx-action@v3 | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and Push API Image | ||
run: | | ||
IMAGE_NAME=ghcr.io/hackforla/homeuniteus/api:latest | ||
docker build -t $IMAGE_NAME ./api | ||
docker push $IMAGE_NAME | ||
build-app: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: docker/setup-buildx-action@v3 | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and Push Testing Image | ||
run: | | ||
IMAGE_NAME=ghcr.io/hackforla/homeuniteus/app:latest-test | ||
docker build --build-arg VITE_HUU_API_BASE_URL=http://127.0.0.1:8080/api --target development --tag $IMAGE_NAME ./app | ||
docker push $IMAGE_NAME | ||
- name: Build Production Image | ||
run: | | ||
IMAGE_NAME=ghcr.io/hackforla/homeuniteus/app:latest | ||
docker build --build-arg VITE_HUU_API_BASE_URL=http://127.0.0.1:8080/api --target production --tag $IMAGE_NAME ./app | ||
docker push $IMAGE_NAME | ||
test-api-mock: | ||
runs-on: ubuntu-latest | ||
needs: [build-api] | ||
if: >- | ||
github.event_name == 'push' || | ||
github.event.pull_request || | ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.test) | ||
steps: | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run Tests With 3rd Party Service Mocking | ||
run: docker run --no-healthcheck ghcr.io/hackforla/homeuniteus/api:latest pytest | ||
test-api-nomock: | ||
runs-on: ubuntu-latest | ||
needs: [build-api] | ||
if: >- | ||
github.event_name == 'push' || | ||
github.event.pull_request || | ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.test) | ||
env: | ||
COGNITO_REGION: ${{ secrets.COGNITO_REGION }} | ||
COGNITO_ACCESS_ID: ${{ secrets.COGNITO_ACCESS_ID }} | ||
COGNITO_ACCESS_KEY: ${{ secrets.COGNITO_ACCESS_KEY }} | ||
steps: | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run Tests Without Mocking | ||
run: docker run --no-healthcheck --env COGNITO_REGION --env COGNITO_ACCESS_ID --env COGNITO_ACCESS_KEY ghcr.io/hackforla/homeuniteus/api:latest "pytest --mode=release" | ||
test-app-mock: | ||
runs-on: ubuntu-latest | ||
needs: [build-app, build-api] | ||
if: >- | ||
github.event_name == 'push' || | ||
github.event.pull_request || | ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.test) | ||
services: | ||
frontend: | ||
image: ghcr.io/hackforla/homeuniteus/app:latest-test | ||
env: | ||
VITE_HUU_API_BASE_URL: http://127.0.0.1:8080/api | ||
steps: | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run Tests With Backend Mocking | ||
run: docker run --env CYPRESS_BASE_URL --env CYPRESS_USE_MOCK ghcr.io/hackforla/homeuniteus/app:latest-test "npx cypress run" | ||
env: | ||
CYPRESS_BASE_URL: http://frontend:4040 | ||
CYPRESS_USE_MOCK: true | ||
test-app-nomock: | ||
runs-on: ubuntu-latest | ||
needs: [build-app, build-api] | ||
if: >- | ||
github.event_name == 'push' || | ||
github.event.pull_request || | ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.test) | ||
services: | ||
backend: | ||
image: ghcr.io/hackforla/homeuniteus/api:latest | ||
env: | ||
ENV: development | ||
HOST: 0.0.0.0 | ||
frontend: | ||
image: ghcr.io/hackforla/homeuniteus/app:latest-test | ||
env: | ||
VITE_HUU_API_BASE_URL: http://backend:8080/api | ||
container: | ||
image: ghcr.io/hackforla/homeuniteus/app:latest-test | ||
env: | ||
CYPRESS_BASE_URL: http://frontend:4040 | ||
CYPRESS_USE_MOCK: false | ||
CYPRESS_REAL_EMAIL: nottarealemail@gmail.com | ||
CYPRESS_REAL_PASSWORD: alskdf454#Adfa | ||
steps: | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Add Test User | ||
run: | | ||
curl http://backend:8080/api/auth/signup/host -H "accept: application/json" -H "Content-Type: application/json" -d "{\"email\": \"nottarealemail@gmail.com\", \"password\": \"alskdf454#Adfa\"}" | ||
- name: Test without mocking | ||
run: npx cypress run | ||
deploy: | ||
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy | ||
needs: [build-api, build-app, test-api-mock, test-api-nomock, test-app-mock, test-app-nomock] | ||
# Our deployment process is not dockerized. This means we need to rebuild the API and | ||
# App as packages that can be installed onto the ec2 instance. | ||
# In the future we may consider simply pulling the api:latest and app:latest images | ||
# from the container repository and swapping the runtime containers. | ||
uses: ./.github/workflows/build-deploy-ec2.yml | ||
Check failure on line 160 in .github/workflows/CI-CD-pipeline.yml GitHub Actions / CI/CD PipelineInvalid workflow file
|