Skip to content

Commit

Permalink
ci: extract e2e tests to reusable workflow file
Browse files Browse the repository at this point in the history
That it can be reused to be run multiple times to detect flaky tests.
  • Loading branch information
BacLuc committed Nov 18, 2023
1 parent 8800bc8 commit 799de3a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 105 deletions.
111 changes: 6 additions & 105 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,113 +368,14 @@ jobs:
COVERALLS_FLAG_NAME: pdf

e2e-tests-build:
name: 'Tests: End-to-end (build job)'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

# build API (using cache; provide image to docker compose)
- name: Build docker image (API/PHP)
uses: docker/build-push-action@v5
with:
file: api/Dockerfile
context: './api'
push: false
load: true
target: api_platform_php_dev
builder: ${{ steps.buildx.outputs.name }}
tags: ecamp/ecamp3-dev-api-php
cache-from: type=gha,scope=api
cache-to: type=gha,scope=api,mode=max
outputs: type=docker,dest=/tmp/ecamp3-dev-api-php.tar

# build caddy (using cache; provide image to docker compose)
- name: Build docker image (Caddy)
uses: docker/build-push-action@v5
with:
file: api/Dockerfile
context: './api'
push: false
load: true
target: api_platform_caddy
builder: ${{ steps.buildx.outputs.name }}
tags: ecamp/ecamp3-dev-api-caddy
cache-from: type=gha,scope=caddy
cache-to: type=gha,scope=caddy,mode=max
outputs: type=docker,dest=/tmp/ecamp3-dev-api-caddy.tar

- uses: actions/upload-artifact@v3
with:
name: e2e-tests-images
path: /tmp/ecamp3-dev-*.tar
name: 'Tests: End-to-end build'
uses: ./.github/workflows/reusable-e2e-tests-build.yml

e2e-tests-run:
name: 'Tests: End-to-end'
runs-on: ubuntu-latest
needs: e2e-tests-build
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
browser:
- chrome
- firefox
- edge
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- run: cp .env.ci .env

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Restore tmp folder
uses: actions/download-artifact@v3
with:
name: e2e-tests-images
path: /tmp

- name: Load images
run: |
docker load --input /tmp/ecamp3-dev-api-php.tar
docker load --input /tmp/ecamp3-dev-api-caddy.tar
docker image ls -a --digests
- name: Restore cache volumes (npm, composer)
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: .cache
key: docker-compose-${{ hashFiles('frontend/package-lock.json', 'print/package-lock.json', 'api/composer.lock') }}-${{ matrix.browser }}
restore-keys: |
docker-compose-
# start necessary containers
- run: docker compose up -d php caddy frontend pdf print browserless database docker-host

- uses: cypress-io/github-action@v5
with:
working-directory: e2e
browser: ${{ matrix.browser }}
wait-on: 'http://localhost:3000, http://localhost:3000/api, http://localhost:3000/print/health'
wait-on-timeout: 300

# store screenshots and videos on GitHub as artifacts, for downloading and debugging in case of problems
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-output-${{ matrix.browser }}
path: |
e2e/data/**/*
# print docker container logs (good for debugging; can be disabled again later on)
- run: docker compose logs --tail="all"
if: always()
name: 'Tests: End-to-end run'
needs:
- e2e-tests-build
uses: ./.github/workflows/reusable-e2e-tests-run.yml

coveralls-finished:
name: 'Finish coveralls report'
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/reusable-e2e-tests-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: '[reusable only] e2e tests build'

on:
workflow_call:

jobs:
e2e-tests-build:
name: 'Tests: End-to-end (build job)'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

# build API (using cache; provide image to docker compose)
- name: Build docker image (API/PHP)
uses: docker/build-push-action@v5
with:
file: api/Dockerfile
context: './api'
push: false
load: true
target: api_platform_php_dev
builder: ${{ steps.buildx.outputs.name }}
tags: ecamp/ecamp3-dev-api-php
cache-from: type=gha,scope=api
cache-to: type=gha,scope=api,mode=max
outputs: type=docker,dest=/tmp/ecamp3-dev-api-php.tar

# build caddy (using cache; provide image to docker compose)
- name: Build docker image (Caddy)
uses: docker/build-push-action@v5
with:
file: api/Dockerfile
context: './api'
push: false
load: true
target: api_platform_caddy
builder: ${{ steps.buildx.outputs.name }}
tags: ecamp/ecamp3-dev-api-caddy
cache-from: type=gha,scope=caddy
cache-to: type=gha,scope=caddy,mode=max
outputs: type=docker,dest=/tmp/ecamp3-dev-api-caddy.tar

- uses: actions/upload-artifact@v3
with:
name: e2e-tests-images
path: /tmp/ecamp3-dev-*.tar
67 changes: 67 additions & 0 deletions .github/workflows/reusable-e2e-tests-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: '[reusable only] e2e tests run'

on:
workflow_call:

jobs:
e2e-tests-run:
name: 'Tests: End-to-end'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
browser:
- chrome
- firefox
- edge
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- run: cp .env.ci .env

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Restore tmp folder
uses: actions/download-artifact@v3
with:
name: e2e-tests-images
path: /tmp

- name: Load images
run: |
docker load --input /tmp/ecamp3-dev-api-php.tar
docker load --input /tmp/ecamp3-dev-api-caddy.tar
docker image ls -a --digests
- name: Restore cache volumes (npm, composer)
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: .cache
key: docker-compose-${{ hashFiles('frontend/package-lock.json', 'print/package-lock.json', 'api/composer.lock') }}-${{ matrix.browser }}
restore-keys: |
docker-compose-
# start necessary containers
- run: docker compose up -d php caddy frontend pdf print browserless database docker-host

- uses: cypress-io/github-action@v5
with:
working-directory: e2e
browser: ${{ matrix.browser }}
wait-on: 'http://localhost:3000, http://localhost:3000/api, http://localhost:3000/print/health'
wait-on-timeout: 300

# store screenshots and videos on GitHub as artifacts, for downloading and debugging in case of problems
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-output-${{ matrix.browser }}
path: |
e2e/data/**/*
# print docker container logs (good for debugging; can be disabled again later on)
- run: docker compose logs --tail="all"
if: always()

0 comments on commit 799de3a

Please sign in to comment.