From 2aa0b1be2dcb968d23f89452a020fe206d8cee35 Mon Sep 17 00:00:00 2001 From: aasim Date: Tue, 23 Apr 2024 18:37:27 -0400 Subject: [PATCH] trying another approach for docker compose service --- .github/workflows/pr_ci_frontend.yaml | 72 ++++++++++++++++++--------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/.github/workflows/pr_ci_frontend.yaml b/.github/workflows/pr_ci_frontend.yaml index 59d023550..bdc1c1841 100644 --- a/.github/workflows/pr_ci_frontend.yaml +++ b/.github/workflows/pr_ci_frontend.yaml @@ -6,9 +6,6 @@ on: - main types: [opened, reopened, synchronize] -env: - NODE_VERSION: '14' - jobs: frontend: name: Run PR Frontend Check @@ -16,39 +13,54 @@ jobs: environment: dev services: - app: # This is the service for the web server needed for Playwright tests - image: docker-compose.yml + postgres: # Database service example + image: postgres:15 env: - FRONTEND_PORT: ${{ secrets.FRONTEND_PORT }} - BACKEND_PORT: ${{ secrets.BACKEND_PORT }} - DATABASE_PORT: ${{ secrets.DATABASE_PORT }} - DATABASE_HOST: ${{ secrets.DATABASE_HOST }} - DATABASE_NAME: ${{ secrets.DATABASE_NAME }} - DATABASE_USER: ${{ secrets.DATABASE_USER }} - DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} - DJANGO_ALLOWED_HOSTS: ${{ secrets.DJANGO_ALLOWED_HOSTS }} - DEBUG: ${{ secrets.DEBUG }} - SECRET_KEY: ${{ secrets.SECRET_KEY }} + POSTGRES_DB: ${{ secrets.DATABASE_NAME }} + POSTGRES_USER: ${{ secrets.DATABASE_USER }} + POSTGRES_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} ports: - - 5432:5432 - options: --env-file .env.dev up --build + - 5432:5432 # Using the default PostgreSQL port steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Docker Compose + run: | + echo "FRONTEND_PORT=${{ secrets.FRONTEND_PORT }}" >> .env + echo "BACKEND_PORT=${{ secrets.BACKEND_PORT }}" >> .env + echo "DATABASE_PORT=${{ secrets.DATABASE_PORT }}" >> .env + echo "DATABASE_HOST=postgres" >> .env # Using the service name from the services section + echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env + echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env + echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env + echo "DJANGO_ALLOWED_HOSTS=${{ secrets.DJANGO_ALLOWED_HOSTS }}" >> .env + echo "DEBUG=${{ secrets.DEBUG }}" >> .env + echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env + + - name: Run Docker Compose + run: docker-compose -f docker-compose.yml up -d + - name: Setup Node environment uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: '16' + + - name: Install Yarn + uses: borales/actions-yarn@v5 + with: + cmd: install + dir: "frontend" - - name: Install Yarn and dependencies + - name: Install Prettier working-directory: ./frontend - run: yarn install + run: yarn add prettier - name: Run Prettier - Formatting check working-directory: ./frontend - run: yarn prettier . --check --config ../.prettierrc --ignore-path ../.prettierignore + run: | + yarn prettier . --check --config ../.prettierrc --ignore-path ../.prettierignore - name: Run Type Check working-directory: ./frontend @@ -56,15 +68,23 @@ jobs: - name: Run eslint - Linting working-directory: ./frontend - run: yarn eslint . --ext .js,.vue + run: | + yarn eslint . --ext .js,.vue - name: Install Playwright Browsers working-directory: ./frontend - run: yarn playwright install --with-deps + run: | + yarn playwright install --with-deps + + - name: Wait for web server to be ready + working-directory: ./frontend + run: | + curl --retry 5 --retry-delay 5 --retry-all-errors http://localhost:${{ secrets.FRONTEND_PORT }} - name: Run Playwright tests working-directory: ./frontend - run: yarn playwright test + run: | + yarn playwright test - name: Upload Playwright report if: always() @@ -73,3 +93,7 @@ jobs: name: playwright-report path: frontend/playwright-report/ retention-days: 30 + + - name: Shutdown Docker Compose + if: always() + run: docker-compose down