From 78ce035298a8bed7bf0b8aaa7abd2527d003752f Mon Sep 17 00:00:00 2001 From: resonic-user Date: Sun, 15 Jun 2025 20:29:29 +0000 Subject: [PATCH] e2e --- .github/workflows/test-e2e.yml | 168 +++++++++------------------------ 1 file changed, 42 insertions(+), 126 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 2e4f581f2..332d77553 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -1,6 +1,13 @@ name: ocelot.social end-to-end test CI -on: push +on: + push: + paths: + - 'webapp/**' + - 'backend/**' + - 'neo4j/**' + - 'cypress/**' + - '.github/workflows/test-e2e.yml' jobs: build_images: @@ -22,8 +29,7 @@ jobs: context: neo4j target: community steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - uses: docker/setup-buildx-action@v3 - name: Build ${{ matrix.service }} image @@ -32,145 +38,55 @@ jobs: context: ./${{ matrix.context }} file: ./${{ matrix.dockerfile }} target: ${{ matrix.target }} - tags: ghcr.io/ocelot-social-community/ocelot-social/${{ matrix.service }}:test - push: false + tags: ocelotsocialnetwork/${{ matrix.service }}:test outputs: type=docker,dest=/tmp/${{ matrix.service }}.tar - - name: Upload Docker image tarball - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.service }}-image - path: /tmp/${{ matrix.service }}.tar - - prepare_cypress: - name: Fullstack | prepare cypress + prepare_env: + name: Prepare Environment runs-on: ubuntu-latest - steps: - - - name: Checkout code - uses: actions/checkout@v4 - - - name: Copy env files - run: | - cp webapp/.env.template webapp/.env - cp backend/.env.test_e2e backend/.env - - - name: Install cypress requirements - 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" - cd backend - yarn install - yarn build - cd .. - yarn install - - - name: Cache cypress - uses: actions/cache@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - path: | - /opt/cucumber-json-formatter - /home/runner/.cache/Cypress - /home/runner/work/Ocelot-Social/Ocelot-Social - key: ${{ github.run_id }}-e2e-cypress + node-version: '20' + + - name: Setup .env and deps + run: | + cp webapp/.env.template webapp/.env || touch webapp/.env + cp backend/.env.test_e2e backend/.env || touch backend/.env + yarn --version || npm install -g yarn + mkdir -p /tmp/bin && curl -sL https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-linux-386 -o /tmp/bin/cucumber-json-formatter + chmod +x /tmp/bin/cucumber-json-formatter + export PATH="/tmp/bin:$PATH" + yarn install || true + (cd backend && yarn install || true) + (cd webapp && yarn install || true) fullstack_tests: - name: Fullstack | tests - if: success() - needs: [build_images, prepare_cypress] + name: Run Fullstack E2E Tests + needs: [build_images, prepare_env] runs-on: ubuntu-latest - env: - jobs: 8 strategy: matrix: job: [1, 2, 3, 4, 5, 6, 7, 8] + env: + jobs: 8 steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Download Docker image tarballs - uses: actions/download-artifact@v4 - with: - path: /tmp - - - name: Restore cypress cache - uses: actions/cache@v4 - with: - path: | - /opt/cucumber-json-formatter - /home/runner/.cache/Cypress - /home/runner/work/Ocelot-Social/Ocelot-Social - key: ${{ github.run_id }}-e2e-cypress - restore-keys: ${{ github.run_id }}-e2e-cypress - - - name: Restore backend environment cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2 - with: - path: | - /tmp/backend.tar - /tmp/neo4j.tar - /tmp/minio.tar - /tmp/minio-mc.tar - /tmp/mailserver.tar - key: ${{ github.run_id }}-e2e-backend-environment-cache - - - name: Restore webapp cache - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.0.2 - with: - path: /tmp/webapp.tar - key: ${{ github.run_id }}-e2e-webapp-cache - - - name: Boot up test system | docker compose + - name: Load Docker images run: | - chmod +x /opt/cucumber-json-formatter - sudo ln -fs /opt/cucumber-json-formatter /usr/bin/cucumber-json-formatter - docker load -i /tmp/neo4j-image/neo4j.tar - docker load -i /tmp/backend-image/backend.tar - docker load -i /tmp/webapp-image/webapp.tar - docker load -i /tmp/minio.tar || true - docker load -i /tmp/minio-mc.tar || true - docker load -i /tmp/mailserver.tar || true - docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend mailserver webapp + docker load < /tmp/neo4j.tar || true + docker load < /tmp/backend.tar || true + docker load < /tmp/webapp.tar || true + + - name: Start system + run: | + docker compose -f docker-compose.yml -f docker-compose.test.yml up --build --detach webapp mailserver - name: Wait for webapp run: | for i in {1..30}; do curl -sf http://localhost:3000 && exit 0 || sleep 2; done; exit 1 - - - 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 - id: e2e-report - if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }} - uses: actions/upload-artifact@v4 - with: - name: ocelot-e2e-test-report-pr${{ needs.docker_preparation.outputs.pr-number }} - path: /home/runner/work/Ocelot-Social/Ocelot-Social/cypress/reports/cucumber_html_report - - cleanup_cache: - name: Cleanup Cache - needs: fullstack_tests - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.1.7 - - - name: Full stack tests | cleanup cache - run: | - cacheKeys=$(gh cache list --json key --jq '.[] | select(.key | startswith("${{ github.run_id }}-e2e-")) | .key') - set +e - echo "Deleting caches..." - for cacheKey in $cacheKeys - do - gh cache delete "$cacheKey" - done - echo "Done" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + - name: Run Cypress tests + run: yarn run cypress:run --spec $(cypress/parallel-features.sh ${{ matrix.job }} ${{ env.jobs }})