name: ocelot.social end-to-end test CI on: push jobs: build-images: runs-on: ubuntu-latest strategy: matrix: target: [backend, webapp, neo4j] steps: - name: Checkout repository uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2 - name: Setup .env files run: | cp backend/.env.test_e2e backend/.env cp webapp/.env.template webapp/.env - name: Set up Docker Buildx uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 - name: Build ${{ matrix.target }} image using docker-compose.test.yml uses: docker/bake-action@d576212e5b026b5ea0cead59d15616980df02388 # v6.8.0 with: source: . files: | docker-compose.yml docker-compose.test.yml targets: ${{ matrix.target }} load: false set: | ${{ matrix.target }}.output=type=docker,dest=/tmp/${{ matrix.target }}.tar - name: Upload ${{ matrix.target }} image uses: actions/upload-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: name: ${{ matrix.target }}-image path: /tmp/${{ matrix.target }}.tar initialize-backend-environment: name: Initialize backend environment needs: [build-images] runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2 - name: Setup .env files run: | cp backend/.env.test_e2e backend/.env cp webapp/.env.template webapp/.env - name: Download backend image uses: actions/download-artifact@448e3f862ab3ef47aa50ff917776823c9946035b # v4.3.0 with: name: backend-image path: /tmp - name: Download neo4j image uses: actions/download-artifact@448e3f862ab3ef47aa50ff917776823c9946035b # v4.3.0 with: name: neo4j-image path: /tmp - name: Load built images run: | docker load < /tmp/backend.tar docker load < /tmp/neo4j.tar - name: Initialize backend environment (like master branch) run: | # Start neo4j and backend together to allow proper initialization docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach --build neo4j backend # Save only the initialized backend and neo4j images docker save "ghcr.io/ocelot-social-community/ocelot-social/backend:test" > /tmp/backend-initialized.tar docker save "ghcr.io/ocelot-social-community/ocelot-social/neo4j:community" > /tmp/neo4j-initialized.tar # Clean shutdown docker compose -f docker-compose.yml -f docker-compose.test.yml down - name: Upload initialized backend environment uses: actions/upload-artifact@de65e23aa2b7e23d713bb51fbfcb6d502f8667d8 # v4.6.2 with: name: backend-environment-initialized path: | /tmp/backend-initialized.tar /tmp/neo4j-initialized.tar cache-environment: runs-on: ubuntu-latest outputs: cache-key: ${{ steps.cache-key.outputs.key }} steps: - name: Checkout repository uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2 - name: Setup Node.js uses: actions/setup-node@7e24a656e1c7a0d6f3eaef8d8e84ae379a5b035b # v4.4.0 with: node-version-file: 'backend/.tool-versions' cache: 'yarn' - 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@640a1c2554105b57832a23eea0b4672fc7a790d5 # v4.2.3 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@640a1c2554105b57832a23eea0b4672fc7a790d5 # v4.2.3 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@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2 - name: Restore unified CI cache uses: actions/cache/restore@640a1c2554105b57832a23eea0b4672fc7a790d5 # v4.2.3 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: [initialize-backend-environment, cache-environment] runs-on: ubuntu-latest env: jobs: 8 strategy: matrix: job: [1, 2, 3, 4, 5, 6, 7, 8] steps: #download docker images - name: Download initialized backend environment uses: actions/download-artifact@448e3f862ab3ef47aa50ff917776823c9946035b # v4.3.0 with: name: backend-environment-initialized path: /tmp - name: Download webapp image uses: actions/download-artifact@448e3f862ab3ef47aa50ff917776823c9946035b # v4.3.0 with: name: webapp-image path: /tmp #load docker images - name: Load Docker images run: | docker load < /tmp/backend-initialized.tar docker load < /tmp/webapp.tar docker load < /tmp/neo4j-initialized.tar # minio, minio-mc, and mailserver images will be pulled fresh by docker compose #checkout repository - name: Checkout repository uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f # v4.2.2 #setup .env files, make cypress reports dir - 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 #restore unified cache - name: Restore unified CI cache id: restore-cache uses: actions/cache/restore@640a1c2554105b57832a23eea0b4672fc7a790d5 # v4.2.3 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 }}- #setup cucumber 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 (using pre-initialized backend environment) run: | # Start all services using pre-initialized backend and neo4j images docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach neo4j backend minio minio-mc mailserver webapp #wait for services - name: Wait for essential services run: | wait_for() { 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 | 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@de65e23aa2b7e23d713bb51fbfcb6d502f8667d8 # v4.6.2 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"