From 4c7adee9e5647c8e742b42b7c7ed7f77f71adb2d Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Sat, 26 Oct 2024 12:45:03 +0100 Subject: [PATCH] Refactor E2E tests in CI --- .github/steps/run-test-services/action.yml | 41 +++++++++++ .github/workflows/build_shared.yml | 21 ++++++ .github/workflows/release.yml | 16 +---- .github/workflows/tests.yml | 69 +++++-------------- ...ose-rc-test.yml => docker-compose-test.yml | 0 5 files changed, 79 insertions(+), 68 deletions(-) create mode 100644 .github/steps/run-test-services/action.yml rename docker-compose-rc-test.yml => docker-compose-test.yml (100%) diff --git a/.github/steps/run-test-services/action.yml b/.github/steps/run-test-services/action.yml new file mode 100644 index 000000000..71c59a63a --- /dev/null +++ b/.github/steps/run-test-services/action.yml @@ -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/compose-action@v2.0.2 + 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 diff --git a/.github/workflows/build_shared.yml b/.github/workflows/build_shared.yml index 0b1a990bc..b94220635 100644 --- a/.github/workflows/build_shared.yml +++ b/.github/workflows/build_shared.yml @@ -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 @@ -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 }} @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 182782ca9..3ec21755a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2870103e4..aebee9fd8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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" @@ -144,33 +154,17 @@ jobs: cache: "yarn" cache-dependency-path: "yarn.lock" - - name: Docker Compose - uses: hoverkraft-tech/compose-action@v2.0.2 - - 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 @@ -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" @@ -245,52 +240,20 @@ jobs: cache: "yarn" cache-dependency-path: "yarn.lock" - - name: Docker Compose - uses: hoverkraft-tech/compose-action@v2.0.2 - - 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 diff --git a/docker-compose-rc-test.yml b/docker-compose-test.yml similarity index 100% rename from docker-compose-rc-test.yml rename to docker-compose-test.yml