Skip to content

Commit

Permalink
Refactor E2E tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
markspolakovs committed Oct 26, 2024
1 parent 6f41766 commit 4c7adee
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 68 deletions.
41 changes: 41 additions & 0 deletions .github/steps/run-test-services/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run Test Services
description: Imports built Docker images, starts docker-compose-test, and migrates database
inputs:
image-from-artifacts:
description: If true, download images from GHA artifacts
runs:
using: composite
steps:
- name: Download built images
if: ${{ inputs.image-from-artifacts == "true" }}
uses: actions/download-artifact@v4
with:
pattern: docker-*
path: /tmp
merge-multiple: true

- name: Import images
if: ${{ inputs.image-from-artifacts == "true" }}
run: for f in /tmp/*.tar; do docker load -i $f; done
shell: bash

- name: Set ref in docker-compose
run: sed -i "s/__RC_REF__/${{ github.ref_name }}/g" docker-compose-test.yml
shell: bash

- name: Docker Compose
uses: hoverkraft-tech/[email protected]
with:
compose-file: |
docker-compose.yml
docker-compose-test.yml
- name: Migrate database
run: |
yarn prisma:migrateProd
shell: bash

- name: Restart services
run: |
docker compose -f docker-compose.yml -f docker-compose-test.yml restart server jobrunner
shell: bash
21 changes: 21 additions & 0 deletions .github/workflows/build_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ on:
type: boolean
default: false
description: Build multi-arch docker images
export_artifacts:
type: boolean
default: true
# https://docs.docker.com/build/ci/github-actions/share-image-jobs/
description: Export images to GitHub Actions artifacts

permissions:
contents: read
Expand Down Expand Up @@ -116,8 +121,16 @@ jobs:
platforms: ${{ inputs.multi_arch && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: ${{ inputs.export_artifacts && 'type=docker,dest=/tmp/server.tar' || '' }}
file: Dockerfile.server

- name: Upload to artifacts
if: ${{ inputs.export_artifacts }}
uses: actions/upload-artifact@v4
with:
name: docker-server
path: /tmp/server.tar

build-docker-jobrunner:
runs-on: ubuntu-latest
if: ${{ inputs.push_docker == true }}
Expand Down Expand Up @@ -160,4 +173,12 @@ jobs:
platforms: ${{ inputs.multi_arch && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: ${{ inputs.export_artifacts && 'type=docker,dest=/tmp/jobrunner.tar' || '' }}
file: Dockerfile.jobrunner

- name: Upload to artifacts
if: ${{ inputs.export_artifacts }}
uses: actions/upload-artifact@v4
with:
name: docker-jobrunner
path: /tmp/jobrunner.tar
16 changes: 1 addition & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,12 @@ jobs:
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Set ref in docker-compose
run: sed -i "s/__RC_REF__/${{ github.ref_name }}/g" docker-compose-rc-test.yml

- name: Start services
run: docker compose -f docker-compose.yml -f docker-compose-rc-test.yml up -d

- run: yarn install --immutable --inline-builds
- uses: ./.github/steps/run-test-services

- uses: ./.github/steps/setup-playwright
with:
working-directory: ./server

- name: Migrate database
run: |
yarn prisma:migrateProd
- name: Retart services
run: |
docker compose -f docker-compose.yml -f docker-compose-rc-test.yml restart server jobrunner
- name: Run Playwright tests
run: yarn ${{ runner.debug && 'test:e2e:debug' || 'test:e2e' }}
working-directory: ./server
Expand Down
69 changes: 16 additions & 53 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,19 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./server/coverage/coverage-final.json,./jobrunner/coverage/coverage-final.json

build:
uses: ./.github/workflows/build_shared.yml
with:
ref: ${{ github.ref }}
tag: ${{ github.ref_name }}
multi_arch: false
push_docker: false
export_artifacts: true

test-e2e-server:
timeout-minutes: 60
runs-on: ubuntu-latest
needs: [build]
env:
NODE_ENV: test
E2E_TEST: "true"
Expand All @@ -144,33 +154,17 @@ jobs:
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Docker Compose
uses: hoverkraft-tech/[email protected]

- name: Install dependencies
run: yarn install --immutable --inline-builds

- name: Build server
run: |
yarn build
cp -r public .next/standalone/server/public
mkdir -p .next/standalone/server/.next
cp -r .next/static .next/standalone/server/.next/static
working-directory: ./server

- name: Build Jobrunner
run: |
yarn build
cp ../utility/prisma/schema.prisma .
working-directory: ./jobrunner
- uses: ./.github/steps/run-test-services
with:
image-from-artifacts: "true"

- uses: ./.github/steps/setup-playwright
with:
working-directory: ./server

- name: Migrate database
run: yarn prisma:migrateProd

- name: Run Playwright tests
run: yarn ${{ runner.debug && 'test:e2e:debug' || 'test:e2e' }}
working-directory: ./server
Expand Down Expand Up @@ -231,6 +225,7 @@ jobs:
test-e2e-desktop-complete:
timeout-minutes: 60
runs-on: ubuntu-latest
needs: [build]
env:
NODE_ENV: test
E2E_TEST: "true"
Expand All @@ -245,52 +240,20 @@ jobs:
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Docker Compose
uses: hoverkraft-tech/[email protected]

- name: Install dependencies
run: yarn install --immutable --inline-builds

- uses: FedericoCarboni/setup-ffmpeg@v3
- uses: ./.github/steps/run-test-services
with:
ffmpeg-version: "release"

- name: Build server
run: |
yarn build
cp -r public .next/standalone/server/public
mkdir -p .next/standalone/server/.next
cp -r .next/static .next/standalone/server/.next/static
working-directory: ./server

- name: Build Jobrunner
run: |
yarn build
cp ../utility/prisma/schema.prisma .
working-directory: ./jobrunner
image-from-artifacts: "true"

- name: Build desktop
run: yarn build
working-directory: ./desktop

- name: Migrate database
run: yarn prisma:migrateProd

- name: Make logs folder
run: mkdir -p ${{ runner.temp }}/logs

- name: Start Jobrunner
run: |
node --enable-source-maps dist/index.cjs --watch --pidFile ${{ runner.temp }}/jobrunner.pid > ${{ runner.temp }}/logs/jobrunner.log 2>&1 &
npx -y wait-on file:/${{ runner.temp }}/jobrunner.pid
working-directory: ./jobrunner

- name: Start server
run: |
HOSTNAME=localhost node server/server.js > ${{ runner.temp }}/logs/server.log 2>&1 &
npx -y wait-on -v -t 120000 http://localhost:3000/api/healthz
working-directory: ./server/.next/standalone

- name: Run Playwright tests
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn ${{ runner.debug && 'test:e2e:debug' || 'test:e2e' }} --project complete
working-directory: ./desktop
Expand Down
File renamed without changes.

0 comments on commit 4c7adee

Please sign in to comment.