Ocelot-Social/.github/workflows/cache-verify.yml
resonic-user d31da32327 wait
2025-06-19 23:45:13 +02:00

304 lines
10 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: test_e2e_reworked
on:
push:
paths:
- '.github/workflows/cache-verify.yml'
workflow_dispatch:
jobs:
build-images:
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:
- name: Checkout repository
uses: actions/checkout@v4
- name: setup .env files
run: |
cp backend/.env.test_e2e backend/.env
cp webapp/.env.template webapp/.env
- uses: docker/setup-buildx-action@v3
- name: Build ${{ matrix.name }} image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
target: ${{ matrix.target }}
push: false
outputs: type=docker,dest=/tmp/${{ matrix.name }}.tar
- name: Upload ${{ matrix.name }} image
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}-image
path: /tmp/${{ matrix.name }}.tar
cache-environment:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-key.outputs.key }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup .env files
run: |
cp backend/.env.test_e2e backend/.env
cp webapp/.env.template webapp/.env
- name: Compute cache key
id: cache-key
run: |
ROOT_HASH=$(sha256sum yarn.lock | cut -d' ' -f1)
BACKEND_HASH=$(sha256sum backend/yarn.lock | cut -d' ' -f1)
WEBAPP_HASH=$(sha256sum webapp/yarn.lock | cut -d' ' -f1)
CYPRESS_HASH=$(find cypress cypress.config.* -type f -exec sha256sum {} \; | sort | sha256sum | cut -d' ' -f1)
KEY="ci-unified-cache-${{ runner.os }}-${ROOT_HASH}-${BACKEND_HASH}-${WEBAPP_HASH}-${CYPRESS_HASH}"
echo "key=$KEY"
echo "key=$KEY" >> $GITHUB_OUTPUT
- name: Restore unified CI cache
id: restore-cache
uses: actions/cache/restore@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
restore-keys: |
ci-unified-cache-${{ runner.os }}-
- 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
- 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
if: success()
needs: [build-images, cache-environment]
runs-on: ubuntu-latest
env:
jobs: 8
strategy:
matrix:
job: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- name: Download Docker image artifacts
uses: actions/download-artifact@v4
with:
path: /tmp
- name: Load Docker images
run: |
docker load < /tmp/backend-image/backend.tar
docker load < /tmp/webapp-image/webapp.tar
docker load < /tmp/neo4j-image/neo4j.tar
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .env files & reports dir
run: |
cp backend/.env.test_e2e backend/.env
cp webapp/.env.template webapp/.env
mkdir -p cypress/reports/json_logs
- name: Restore unified CI cache
id: restore-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
restore-keys: |
ci-unified-cache-${{ runner.os }}-
- name: Run formatter or use PATH tools
run: |
export PATH="/opt:$PATH"
cucumber-json-formatter --help
- 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"
- name: Build backend
run: cd backend && yarn build
- name: Boot system for tests
run: |
docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend mailserver webapp
- name: Wait for essential services (from .env)
run: |
wait_for() {
local name="$1"
local url="$2"
local max=20
echo "⏳ Waiting for $name ($url)..."
for i in $(seq 1 "$max"); do
if curl -sf "$url"; then
echo "✅ $name is ready"
return 0
fi
echo "Waiting for $name... ($i/$max)"
sleep 2
done
echo "❌ Timeout: $name did not respond at $url continuing anyway"
docker compose logs || echo "(docker logs failed)"
return 0
}
# Lade die kopierten .env-Dateien in Shell-Variablen
set -o allexport
source backend/.env
source webapp/.env
set +o allexport
# Verwende die URIs aus .env
wait_for "webapp" "$CLIENT_URI"
wait_for "backend" "$GRAPHQL_URI"
wait_for "mailserver" "http://localhost:1080"
wait_for "minio" "http://localhost:9000/minio/health/live"
echo "🎉 All services are up."
- name: Debug backend response
run: |
curl -i http://localhost:4000/ || echo "❌ curl failed"
curl -s -o /dev/null -w "%{http_code}" http://localhost:4000/
- name: Full stack tests | run tests
id: e2e-tests
run: |
yarn run cypress:run --spec $(cypress/parallel-features.sh ${{ matrix.job }} ${{ env.jobs }} )
- name: Full stack tests | if tests failed, compile html report
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
run: |
cd cypress/
node create-cucumber-html-report.js
- name: Full stack tests | if tests failed, upload report
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: e2e-html-report-${{ matrix.job }}
path: cypress/reports/cucumber_html_report
- name: Debug output (always)
if: always()
run: |
echo "📁 Cypress reports"
ls -l cypress/reports/json_logs || echo "❌ Missing JSON logs"