From fd4241cf2c50dbe6ebbae5fab01498ea0bf3f1a2 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 02:53:09 +0100 Subject: [PATCH 1/7] add a github action to test the docker compose app --- .github/workflows/startup-tests.yml | 50 +++++++++++++++++++++++++---- frontend/playwright.config.ts | 5 +-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index ae3244bf7..af023b145 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -1,4 +1,4 @@ -name: Startup Functional Tests +name: Startup Tests on: pull_request: @@ -6,13 +6,12 @@ on: env: GITHUB_WORKFLOW: github_actions + backend-directory: ./backend + working-directory: ./frontend jobs: - startup-tests: + startup-functional-test: runs-on: ubuntu-latest - env: - backend-directory: ./backend - working-directory: ./frontend services: postgres: @@ -88,8 +87,45 @@ jobs: - uses: actions/upload-artifact@v4 if: always() with: - name: startup-tests-report + name: startup-functional-test-report + path: | + ${{ env.working-directory }}/tests/reports/ + ${{ env.working-directory }}/tests/results/ + retention-days: 30 + startup-docker-compose-test: + runs-on: ubuntu-latest + env: + DJANGO_SUPERUSER_EMAIL: admin@tests.com + DJANGO_SUPERUSER_PASSWORD: 1234 + DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }} + COMPOSE_TEST: True + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: latest + - name: Install dependencies + working-directory: ${{ env.working-directory }} + run: | + npm install + npm ci + - name: Install Playwright Browsers + working-directory: ${{ env.working-directory }} + run: npx playwright install --with-deps + - name: Build the Docker app + run: docker compose up -d --build + - name: Config the Docker app + run: | + docker compose exec backend python manage.py migrate + docker compose exec backend python manage.py createsuperuser --noinput + - name: Run tests + working-directory: ${{ env.working-directory }} + run: npx playwright test tests/functional/startup.test.ts + - uses: actions/upload-artifact@v4 + if: always() + with: + name: startup-docker-test-report path: | ${{ env.working-directory }}/tests/reports/ ${{ env.working-directory }}/tests/results/ - retention-days: 30 \ No newline at end of file + retention-days: 5 \ No newline at end of file diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 46d833396..639ac2066 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -3,8 +3,9 @@ import { devices } from '@playwright/test'; const config: PlaywrightTestConfig = { webServer: { - command: 'npm run build && npm run preview', - port: 4173 + command: process.env.COMPOSE_TEST ? 'echo "The docker compose frontend server didn\'t start correctly"' : 'npm run build && npm run preview', + port: process.env.COMPOSE_TEST ? 3000 : 4173, + reuseExistingServer: process.env.COMPOSE_TEST }, testDir: 'tests', outputDir: 'tests/results', From 8132ce1b607a13a8910237d49ecc577a6050373d Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 03:08:35 +0100 Subject: [PATCH 2/7] try to fix superuser creation fail in startup test workflow --- .github/workflows/startup-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index af023b145..dc41343ab 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -117,7 +117,6 @@ jobs: - name: Config the Docker app run: | docker compose exec backend python manage.py migrate - docker compose exec backend python manage.py createsuperuser --noinput - name: Run tests working-directory: ${{ env.working-directory }} run: npx playwright test tests/functional/startup.test.ts From 0d5e341046ea89bea24b6544a108804c37ad6c75 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 03:23:47 +0100 Subject: [PATCH 3/7] export env variables inside a .env file in the docker-startup-test workflow --- .github/workflows/startup-tests.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index dc41343ab..345424131 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -95,9 +95,6 @@ jobs: startup-docker-compose-test: runs-on: ubuntu-latest env: - DJANGO_SUPERUSER_EMAIL: admin@tests.com - DJANGO_SUPERUSER_PASSWORD: 1234 - DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }} COMPOSE_TEST: True steps: - uses: actions/checkout@v4 @@ -114,9 +111,18 @@ jobs: run: npx playwright install --with-deps - name: Build the Docker app run: docker compose up -d --build + - name: Create backend environment variables file + working-directory: ${{ env.backend-directory }} + run: | + touch .env + echo DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }} >> .env + echo DJANGO_SUPERUSER_EMAIL=admin@tests.com >> .env + echo DJANGO_SUPERUSER_PASSWORD=1234 >> .env + export $(grep -v '^#' .env | xargs) - name: Config the Docker app run: | docker compose exec backend python manage.py migrate + docker compose exec backend python manage.py createsuperuser --noinput - name: Run tests working-directory: ${{ env.working-directory }} run: npx playwright test tests/functional/startup.test.ts From f4c3a6562f4e1908c11a836f181061ccee42b58c Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 03:37:01 +0100 Subject: [PATCH 4/7] export env variable inside the backend docker --- .github/workflows/startup-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index 345424131..a9e0bbab0 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -116,12 +116,12 @@ jobs: run: | touch .env echo DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }} >> .env - echo DJANGO_SUPERUSER_EMAIL=admin@tests.com >> .env - echo DJANGO_SUPERUSER_PASSWORD=1234 >> .env export $(grep -v '^#' .env | xargs) - name: Config the Docker app run: | docker compose exec backend python manage.py migrate + docker compose exec backend export DJANGO_SUPERUSER_EMAIL=admin@tests.com + docker compose exec backend export DJANGO_SUPERUSER_PASSWORD=1234 docker compose exec backend python manage.py createsuperuser --noinput - name: Run tests working-directory: ${{ env.working-directory }} From 15a349dfbd98f63f497d1d3692afa8efb15820f1 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 04:00:40 +0100 Subject: [PATCH 5/7] export docker startup test variable --- .github/workflows/startup-tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index bdc613472..e9e37d982 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -119,9 +119,7 @@ jobs: - name: Config the Docker app run: | docker compose exec backend python manage.py migrate - docker compose exec backend export DJANGO_SUPERUSER_EMAIL=admin@tests.com - docker compose exec backend export DJANGO_SUPERUSER_PASSWORD=1234 - docker compose exec backend python manage.py createsuperuser --noinput + docker compose exec backend python bash -c "DJANGO_SUPERUSER_EMAIL=admin@tests.com DJANGO_SUPERUSER_PASSWORD=1234 manage.py createsuperuser --noinput" - name: Run tests working-directory: ${{ env.working-directory }} run: npx playwright test tests/functional/startup.test.ts From 0c869cbc730dec26f54b5b3128b8efacdfecc398 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 04:04:30 +0100 Subject: [PATCH 6/7] hotfix bash startup test --- .github/workflows/startup-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index e9e37d982..d239e409e 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -119,7 +119,7 @@ jobs: - name: Config the Docker app run: | docker compose exec backend python manage.py migrate - docker compose exec backend python bash -c "DJANGO_SUPERUSER_EMAIL=admin@tests.com DJANGO_SUPERUSER_PASSWORD=1234 manage.py createsuperuser --noinput" + docker compose exec backend python /bin/bash -c "DJANGO_SUPERUSER_EMAIL=admin@tests.com DJANGO_SUPERUSER_PASSWORD=1234 manage.py createsuperuser --noinput" - name: Run tests working-directory: ${{ env.working-directory }} run: npx playwright test tests/functional/startup.test.ts From e081c577f820cbeacdda2aebed1b90548d956f41 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 04:06:15 +0100 Subject: [PATCH 7/7] fix compose exec command in the docker startup test workflow --- .github/workflows/startup-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index d239e409e..560c20539 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -119,7 +119,7 @@ jobs: - name: Config the Docker app run: | docker compose exec backend python manage.py migrate - docker compose exec backend python /bin/bash -c "DJANGO_SUPERUSER_EMAIL=admin@tests.com DJANGO_SUPERUSER_PASSWORD=1234 manage.py createsuperuser --noinput" + docker compose exec backend /bin/bash -c "DJANGO_SUPERUSER_EMAIL=admin@tests.com DJANGO_SUPERUSER_PASSWORD=1234 python manage.py createsuperuser --noinput" - name: Run tests working-directory: ${{ env.working-directory }} run: npx playwright test tests/functional/startup.test.ts