mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-02-06 09:56:03 +00:00
e2e
This commit is contained in:
parent
f3788b84a5
commit
b3ea024c9d
393
.github/workflows/test-e2e.yml
vendored
393
.github/workflows/test-e2e.yml
vendored
@ -1,203 +1,282 @@
|
|||||||
name: ocelot.social end-to-end test CI
|
name: ocelot.social end-to-end test CI
|
||||||
|
on:
|
||||||
on: push
|
push:
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/cache-verify.yml'
|
||||||
|
workflow_dispatch:
|
||||||
jobs:
|
jobs:
|
||||||
prepare_backend_environment:
|
build-images:
|
||||||
name: Fullstack | prepare backend environment
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: backend
|
||||||
|
context: ./backend
|
||||||
|
dockerfile: ./backend/Dockerfile
|
||||||
|
target: build
|
||||||
|
- name: webapp
|
||||||
|
context: ./webapp
|
||||||
|
dockerfile: ./webapp/Dockerfile
|
||||||
|
target: build
|
||||||
|
- name: neo4j
|
||||||
|
context: ./neo4j
|
||||||
|
dockerfile: ./neo4j/Dockerfile
|
||||||
|
target: community
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout repository
|
||||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2
|
uses: actions/checkout@v4
|
||||||
|
- name: setup .env files
|
||||||
- name: Copy backend env file
|
|
||||||
run: |
|
run: |
|
||||||
cp backend/.env.test_e2e backend/.env
|
cp backend/.env.test_e2e backend/.env
|
||||||
cp webapp/.env.template webapp/.env
|
cp webapp/.env.template webapp/.env
|
||||||
|
- uses: docker/setup-buildx-action@v3
|
||||||
- name: Build backend and dependencies
|
- name: Build ${{ matrix.name }} image
|
||||||
run: |
|
uses: docker/build-push-action@v5
|
||||||
# Build and start all required images for backend
|
|
||||||
docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend --build
|
|
||||||
|
|
||||||
# Save the build images
|
|
||||||
docker save "ghcr.io/ocelot-social-community/ocelot-social/backend:test" > /tmp/backend.tar
|
|
||||||
docker save "ghcr.io/ocelot-social-community/ocelot-social/neo4j-community:test" > /tmp/neo4j.tar
|
|
||||||
docker save "quay.io/minio/minio:latest" > /tmp/minio.tar
|
|
||||||
docker save "quay.io/minio/mc:latest" > /tmp/minio-mc.tar
|
|
||||||
docker save "maildev/maildev:latest" > /tmp/mailserver.tar
|
|
||||||
|
|
||||||
# Stop the containers
|
|
||||||
docker compose -f docker-compose.yml -f docker-compose.test.yml down
|
|
||||||
|
|
||||||
- name: Cache docker images
|
|
||||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2
|
|
||||||
with:
|
with:
|
||||||
path: |
|
context: ${{ matrix.context }}
|
||||||
/tmp/backend.tar
|
file: ${{ matrix.dockerfile }}
|
||||||
/tmp/neo4j.tar
|
target: ${{ matrix.target }}
|
||||||
/tmp/minio.tar
|
push: false
|
||||||
/tmp/minio-mc.tar
|
outputs: type=docker,dest=/tmp/${{ matrix.name }}.tar
|
||||||
/tmp/mailserver.tar
|
- name: Upload ${{ matrix.name }} image
|
||||||
key: ${{ github.run_id }}-e2e-backend-environment-cache
|
uses: actions/upload-artifact@v4
|
||||||
|
|
||||||
prepare_webapp_image:
|
|
||||||
name: Fullstack | prepare webapp image
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2
|
|
||||||
|
|
||||||
- name: Copy backend env file
|
|
||||||
run: |
|
|
||||||
cp backend/.env.test_e2e backend/.env
|
|
||||||
cp webapp/.env.template webapp/.env
|
|
||||||
|
|
||||||
- name: Build docker image
|
|
||||||
run: |
|
|
||||||
docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach webapp --build --no-deps
|
|
||||||
docker save "ghcr.io/ocelot-social-community/ocelot-social/webapp:test" > /tmp/webapp.tar
|
|
||||||
|
|
||||||
- name: Cache docker image
|
|
||||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2
|
|
||||||
with:
|
with:
|
||||||
path: /tmp/webapp.tar
|
name: ${{ matrix.name }}-image
|
||||||
key: ${{ github.run_id }}-e2e-webapp-cache
|
path: /tmp/${{ matrix.name }}.tar
|
||||||
|
|
||||||
prepare_cypress:
|
cache-environment:
|
||||||
name: Fullstack | prepare cypress
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
cache-key: ${{ steps.cache-key.outputs.key }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout repository
|
||||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@08f58d1471bff7f3a07d167b4ad7df25d5fcfcb6 # v4.4.0
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version-file: 'backend/.tool-versions'
|
node-version: '20'
|
||||||
cache: 'yarn'
|
|
||||||
|
|
||||||
- name: Copy env files
|
- name: Setup .env files
|
||||||
run: |
|
run: |
|
||||||
cp webapp/.env.template webapp/.env
|
|
||||||
cp backend/.env.test_e2e backend/.env
|
cp backend/.env.test_e2e backend/.env
|
||||||
|
cp webapp/.env.template webapp/.env
|
||||||
- name: Install cypress requirements
|
- name: Compute cache key
|
||||||
|
id: cache-key
|
||||||
run: |
|
run: |
|
||||||
wget --no-verbose -O /opt/cucumber-json-formatter "https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-linux-386"
|
ROOT_HASH=$(sha256sum yarn.lock | cut -d' ' -f1)
|
||||||
cd backend
|
BACKEND_HASH=$(sha256sum backend/yarn.lock | cut -d' ' -f1)
|
||||||
yarn install
|
WEBAPP_HASH=$(sha256sum webapp/yarn.lock | cut -d' ' -f1)
|
||||||
yarn build
|
CYPRESS_HASH=$(find cypress cypress.config.* -type f -exec sha256sum {} \; | sort | sha256sum | cut -d' ' -f1)
|
||||||
cd ..
|
KEY="ci-unified-cache-${{ runner.os }}-${ROOT_HASH}-${BACKEND_HASH}-${WEBAPP_HASH}-${CYPRESS_HASH}"
|
||||||
yarn install
|
echo "key=$KEY"
|
||||||
|
echo "key=$KEY" >> $GITHUB_OUTPUT
|
||||||
- name: Cache docker image
|
- name: Restore unified CI cache
|
||||||
|
id: restore-cache
|
||||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2
|
uses: actions/cache/restore@v4
|
||||||
with:
|
with:
|
||||||
|
key: ${{ steps.cache-key.outputs.key }}
|
||||||
path: |
|
path: |
|
||||||
|
node_modules
|
||||||
|
backend/node_modules
|
||||||
|
webapp/node_modules
|
||||||
|
backend/build
|
||||||
|
webapp/.nuxt
|
||||||
|
~/.cache/Cypress
|
||||||
/opt/cucumber-json-formatter
|
/opt/cucumber-json-formatter
|
||||||
/home/runner/.cache/Cypress
|
restore-keys: |
|
||||||
/home/runner/work/Ocelot-Social/Ocelot-Social
|
ci-unified-cache-${{ runner.os }}-
|
||||||
key: ${{ github.run_id }}-e2e-cypress
|
- name: Setup dependencies & build (if cache missed)
|
||||||
|
if: steps.restore-cache.outputs.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
|
echo "📦 Cache miss – installing & building everything"
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
cd backend && yarn install --frozen-lockfile && yarn build && cd ..
|
||||||
|
cd webapp && yarn install --frozen-lockfile && yarn build && cd ..
|
||||||
|
npx cypress verify || echo "⚠️ Cypress verify failed (non-blocking)"
|
||||||
|
if [ ! -f /opt/cucumber-json-formatter ]; then
|
||||||
|
wget --no-verbose -O /opt/cucumber-json-formatter "https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-linux-386"
|
||||||
|
chmod +x /opt/cucumber-json-formatter
|
||||||
|
fi
|
||||||
|
# verify cache
|
||||||
|
- name: Verify install output before caching
|
||||||
|
run: |
|
||||||
|
test -d node_modules && ls node_modules || (echo "❌ install failed" && exit 1)
|
||||||
|
test -d backend/node_modules || (echo "❌ backend install failed" && exit 1)
|
||||||
|
test -d webapp/node_modules || (echo "❌ webapp install failed" && exit 1)
|
||||||
|
- name: Ensure node_modules folders are always cached
|
||||||
|
run: |
|
||||||
|
mkdir -p node_modules backend/node_modules webapp/node_modules
|
||||||
|
touch node_modules/.keep backend/node_modules/.keep webapp/node_modules/.keep
|
||||||
|
- name: Save unified CI cache
|
||||||
|
if: steps.restore-cache.outputs.cache-hit != 'true'
|
||||||
|
uses: actions/cache/save@v4
|
||||||
|
with:
|
||||||
|
key: ${{ steps.cache-key.outputs.key }}
|
||||||
|
path: |
|
||||||
|
node_modules
|
||||||
|
backend/node_modules
|
||||||
|
webapp/node_modules
|
||||||
|
backend/build
|
||||||
|
webapp/.nuxt
|
||||||
|
~/.cache/Cypress
|
||||||
|
/opt/cucumber-json-formatter
|
||||||
|
verify-environment:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [cache-environment]
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
fullstack_tests:
|
- name: Restore unified CI cache
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
key: ${{ needs.cache-environment.outputs.cache-key }}
|
||||||
|
path: |
|
||||||
|
node_modules
|
||||||
|
backend/node_modules
|
||||||
|
webapp/node_modules
|
||||||
|
backend/build
|
||||||
|
webapp/.nuxt
|
||||||
|
~/.cache/Cypress
|
||||||
|
/opt/cucumber-json-formatter
|
||||||
|
- name: Check required node_modules
|
||||||
|
run: |
|
||||||
|
[ -d node_modules ] && [ -n "$(ls -A node_modules)" ] || (echo "❌ node_modules missing" && exit 1)
|
||||||
|
[ -d backend/node_modules ] && [ -n "$(ls -A backend/node_modules)" ] || (echo "❌ backend/node_modules missing" && exit 1)
|
||||||
|
[ -d webapp/node_modules ] && [ -n "$(ls -A webapp/node_modules)" ] || (echo "❌ webapp/node_modules missing" && exit 1)
|
||||||
|
- name: Check Cypress binary
|
||||||
|
run: |
|
||||||
|
npx cypress --version || (echo "❌ Cypress binary fehlt" && exit 1)
|
||||||
|
npx cypress verify
|
||||||
|
- name: Check build artifacts exist
|
||||||
|
run: |
|
||||||
|
[ -d backend/build ] || (echo "❌ backend/build fehlt" && exit 1)
|
||||||
|
[ -d webapp/.nuxt ] || (echo "❌ webapp/.nuxt fehlt" && exit 1)
|
||||||
|
- name: Check cucumber-json-formatter
|
||||||
|
run: |
|
||||||
|
[ -x /opt/cucumber-json-formatter ] || (echo "❌ Formatter fehlt" && exit 1)
|
||||||
|
/opt/cucumber-json-formatter --help || (echo "❌ Formatter nicht ausführbar" && exit 1)
|
||||||
|
consolidate-environment:
|
||||||
name: Fullstack | tests
|
name: Fullstack | tests
|
||||||
if: success()
|
if: success()
|
||||||
needs: [prepare_backend_environment, prepare_webapp_image, prepare_cypress]
|
needs: [build-images, cache-environment]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
jobs: 8
|
jobs: 8
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# run copies of the current job in parallel
|
|
||||||
job: [1, 2, 3, 4, 5, 6, 7, 8]
|
job: [1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
steps:
|
||||||
uses: actions/setup-node@08f58d1471bff7f3a07d167b4ad7df25d5fcfcb6 # v4.4.0
|
#download docker images
|
||||||
|
- name: Download Docker image artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
node-version-file: 'backend/.tool-versions'
|
path: /tmp
|
||||||
cache: 'yarn'
|
|
||||||
|
|
||||||
- name: Restore cypress cache
|
#load docker images
|
||||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2
|
- name: Load Docker images
|
||||||
with:
|
run: |
|
||||||
path: |
|
docker load < /tmp/backend-image/backend.tar
|
||||||
/opt/cucumber-json-formatter
|
docker load < /tmp/webapp-image/webapp.tar
|
||||||
/home/runner/.cache/Cypress
|
docker load < /tmp/neo4j-image/neo4j.tar
|
||||||
/home/runner/work/Ocelot-Social/Ocelot-Social
|
#checkout repository
|
||||||
key: ${{ github.run_id }}-e2e-cypress
|
- name: Checkout repository
|
||||||
restore-keys: ${{ github.run_id }}-e2e-cypress
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Restore backend environment cache
|
#setup .env files, make cypress reports dir
|
||||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2
|
- name: Setup .env files & reports dir
|
||||||
with:
|
run: |
|
||||||
path: |
|
cp backend/.env.test_e2e backend/.env
|
||||||
/tmp/backend.tar
|
cp webapp/.env.template webapp/.env
|
||||||
/tmp/neo4j.tar
|
mkdir -p cypress/reports/json_logs
|
||||||
/tmp/minio.tar
|
#restore unified cache
|
||||||
/tmp/minio-mc.tar
|
- name: Restore unified CI cache
|
||||||
/tmp/mailserver.tar
|
id: restore-cache
|
||||||
key: ${{ github.run_id }}-e2e-backend-environment-cache
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
- name: Restore webapp cache
|
key: ${{ needs.cache-environment.outputs.cache-key }}
|
||||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2
|
path: |
|
||||||
with:
|
node_modules
|
||||||
path: /tmp/webapp.tar
|
backend/node_modules
|
||||||
key: ${{ github.run_id }}-e2e-webapp-cache
|
webapp/node_modules
|
||||||
|
backend/build
|
||||||
- name: Boot up test system | docker compose
|
webapp/.nuxt
|
||||||
|
~/.cache/Cypress
|
||||||
|
/opt/cucumber-json-formatter
|
||||||
|
restore-keys: |
|
||||||
|
ci-unified-cache-${{ runner.os }}-
|
||||||
|
#setup cocumber path
|
||||||
|
- name: Run formatter or use PATH tools
|
||||||
|
run: |
|
||||||
|
export PATH="/opt:$PATH"
|
||||||
|
cucumber-json-formatter --help
|
||||||
|
#rehydrate dependencies
|
||||||
|
- name: Rehydrate dependencies
|
||||||
|
run: |
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
cd backend && yarn install --frozen-lockfile && cd ..
|
||||||
|
cd webapp && yarn install --frozen-lockfile && cd ..
|
||||||
|
npx cypress verify || echo "⚠️ Cypress not yet verified"
|
||||||
|
#build backend
|
||||||
|
- name: Build backend
|
||||||
|
run: cd backend && yarn build
|
||||||
|
|
||||||
|
#boot system for tests
|
||||||
|
- name: Boot system for tests
|
||||||
run: |
|
run: |
|
||||||
chmod +x /opt/cucumber-json-formatter
|
|
||||||
sudo ln -fs /opt/cucumber-json-formatter /usr/bin/cucumber-json-formatter
|
|
||||||
docker load < /tmp/neo4j.tar
|
|
||||||
docker load < /tmp/backend.tar
|
|
||||||
docker load < /tmp/minio.tar
|
|
||||||
docker load < /tmp/minio-mc.tar
|
|
||||||
docker load < /tmp/mailserver.tar
|
|
||||||
docker load < /tmp/webapp.tar
|
|
||||||
docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend mailserver webapp
|
docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend mailserver webapp
|
||||||
sleep 90s
|
#wait for services
|
||||||
|
- name: Wait for essential services
|
||||||
- name: Full stack tests | run tests
|
run: |
|
||||||
id: e2e-tests
|
wait_for() {
|
||||||
run: yarn run cypress:run --spec $(cypress/parallel-features.sh ${{ matrix.job }} ${{ env.jobs }} )
|
local name="$1"
|
||||||
|
local url="$2"
|
||||||
|
local max=40
|
||||||
|
echo "⏳ Waiting for $name ($url)..."
|
||||||
|
for i in $(seq 1 "$max"); do
|
||||||
|
status=$(curl -s -o /dev/null -w "%{http_code}" "$url" || echo "000")
|
||||||
|
if [[ "$status" =~ ^2|3|400$ ]]; then
|
||||||
|
echo "✅ $name responded with HTTP $status"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "Waiting for $name... ($i/$max) – last HTTP $status"
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "❌ Timeout: $name did not respond successfully at $url"
|
||||||
|
echo "Last response body:"
|
||||||
|
curl -i "$url" || echo "(curl failed)"
|
||||||
|
docker compose logs "$name" || echo "(docker logs failed)"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
# Lade die kopierten .env-Dateien in Shell-Variablen
|
||||||
|
set -o allexport
|
||||||
|
source backend/.env
|
||||||
|
source webapp/.env
|
||||||
|
set +o allexport
|
||||||
|
# Aufrufe
|
||||||
|
wait_for "webapp" "$CLIENT_URI"
|
||||||
|
wait_for "backend" "$BACKEND_HEALTH"
|
||||||
|
wait_for "mailserver" "http://localhost:1080"
|
||||||
|
wait_for "minio" "http://localhost:9000/minio/health/live"
|
||||||
|
echo "🎉 All services are up."
|
||||||
|
#starting fullstack cypress tests
|
||||||
- name: Full stack tests | if tests failed, compile html report
|
- name: Full stack tests | if tests failed, compile html report
|
||||||
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
|
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
|
||||||
run: |
|
run: |
|
||||||
cd cypress/
|
cd cypress/
|
||||||
node create-cucumber-html-report.js
|
node create-cucumber-html-report.js
|
||||||
|
|
||||||
- name: Full stack tests | if tests failed, upload report
|
- name: Full stack tests | if tests failed, upload report
|
||||||
id: e2e-report
|
|
||||||
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
|
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ocelot-e2e-test-report-pr${{ needs.docker_preparation.outputs.pr-number }}
|
name: e2e-html-report-${{ matrix.job }}
|
||||||
path: /home/runner/work/Ocelot-Social/Ocelot-Social/cypress/reports/cucumber_html_report
|
path: cypress/reports/cucumber_html_report
|
||||||
|
|
||||||
cleanup_cache:
|
- name: Debug output (always)
|
||||||
name: Cleanup Cache
|
if: always()
|
||||||
needs: fullstack_tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2
|
|
||||||
|
|
||||||
- name: Full stack tests | cleanup cache
|
|
||||||
run: |
|
run: |
|
||||||
cacheKeys=$(gh cache list --json key --jq '.[] | select(.key | startswith("${{ github.run_id }}-e2e-")) | .key')
|
echo "📁 Cypress reports"
|
||||||
set +e
|
ls -l cypress/reports/json_logs || echo "❌ Missing JSON logs"
|
||||||
echo "Deleting caches..."
|
|
||||||
for cacheKey in $cacheKeys
|
|
||||||
do
|
|
||||||
gh cache delete "$cacheKey"
|
|
||||||
done
|
|
||||||
echo "Done"
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user