diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 332d77553..3503bad4b 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -1,4 +1,4 @@ -name: ocelot.social end-to-end test CI +name: Realistic E2E CI on: push: @@ -10,83 +10,101 @@ on: - '.github/workflows/test-e2e.yml' jobs: - build_images: - name: Build Docker Images + prepare_backend_environment: + name: Fullstack | prepare backend environment runs-on: ubuntu-latest - strategy: - matrix: - include: - - service: backend - dockerfile: backend/Dockerfile - context: backend - target: build - - service: webapp - dockerfile: webapp/Dockerfile - context: webapp - target: build - - service: neo4j - dockerfile: neo4j/Dockerfile - context: neo4j - target: community steps: - - uses: actions/checkout@v4 - - uses: docker/setup-buildx-action@v3 + - name: Checkout code + uses: actions/checkout@v4 - - name: Build ${{ matrix.service }} image - uses: docker/build-push-action@v5 + - name: Copy env files + run: | + cp backend/.env.test_e2e backend/.env || true + cp webapp/.env.template webapp/.env || true + + - name: Build backend and dependencies + run: | + docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend --build + + - name: Save docker images to disk + run: | + docker save ocelotsocialnetwork/backend:test > /tmp/backend.tar + docker save ocelotsocialnetwork/neo4j:test > /tmp/neo4j.tar + docker save ocelotsocialnetwork/webapp:test > /tmp/webapp.tar + + - name: Cache docker images + uses: actions/cache@v4 with: - context: ./${{ matrix.context }} - file: ./${{ matrix.dockerfile }} - target: ${{ matrix.target }} - tags: ocelotsocialnetwork/${{ matrix.service }}:test - outputs: type=docker,dest=/tmp/${{ matrix.service }}.tar + path: | + /tmp/backend.tar + /tmp/neo4j.tar + /tmp/webapp.tar + key: ${{ github.run_id }}-e2e-images - prepare_env: - name: Prepare Environment + - name: Shutdown services after image save + run: docker compose -f docker-compose.yml -f docker-compose.test.yml down + + run_tests: + name: Run Cypress Tests Against Docker Setup runs-on: ubuntu-latest + needs: prepare_backend_environment steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Checkout code + uses: actions/checkout@v4 + + - name: Restore docker image cache + uses: actions/cache@v4 with: - node-version: '20' + path: | + /tmp/backend.tar + /tmp/neo4j.tar + /tmp/webapp.tar + key: ${{ github.run_id }}-e2e-images - - name: Setup .env and deps + - name: Load Docker Images 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) + docker load -i /tmp/backend.tar + docker load -i /tmp/neo4j.tar + docker load -i /tmp/webapp.tar - fullstack_tests: - name: Run Fullstack E2E Tests - needs: [build_images, prepare_env] - runs-on: ubuntu-latest - strategy: - matrix: - job: [1, 2, 3, 4, 5, 6, 7, 8] - env: - jobs: 8 - steps: - - uses: actions/checkout@v4 - - - name: Load Docker images + - name: Prepare env files run: | - docker load < /tmp/neo4j.tar || true - docker load < /tmp/backend.tar || true - docker load < /tmp/webapp.tar || true + cp backend/.env.test_e2e backend/.env || true + cp webapp/.env.template webapp/.env || true - - name: Start system + - name: Restore Cypress cache + uses: actions/cache@v4 + with: + path: | + ~/.cache/Cypress + ./cypress + /opt/cucumber-json-formatter + key: ${{ runner.os }}-cypress-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies run: | - docker compose -f docker-compose.yml -f docker-compose.test.yml up --build --detach webapp mailserver + cd backend && yarn install && yarn build + cd .. && yarn install - - name: Wait for webapp + - name: Start selected services via Compose run: | - for i in {1..30}; do curl -sf http://localhost:3000 && exit 0 || sleep 2; done; exit 1 + docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach backend mailserver webapp - - name: Run Cypress tests - run: yarn run cypress:run --spec $(cypress/parallel-features.sh ${{ matrix.job }} ${{ env.jobs }}) + - name: Wait for webapp to be ready + uses: jakejarvis/wait-action@v0.1.0 + with: + url: http://localhost:3000 + timeout: 120000 + + - name: Run Cypress Tests + run: yarn run cypress:run --spec $(cypress/parallel-features.sh 1 1) + + - name: Show service logs on failure + if: failure() + run: | + docker compose -f docker-compose.yml -f docker-compose.test.yml logs backend + docker compose -f docker-compose.yml -f docker-compose.test.yml logs webapp + + - name: Shutdown Docker Compose + if: always() + run: docker compose -f docker-compose.yml -f docker-compose.test.yml down