From 5ca1e9e648f5d34b8127234455522a4dac9ac144 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 07:35:20 +0200 Subject: [PATCH 1/6] add docker image building step to e2e test workflow --- .github/workflows/test-e2e.yml | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 74ebd1c43..87fdb2bf0 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -2,8 +2,46 @@ name: ocelot.social end-to-end test CI on: push jobs: + docker_preparation: + name: Fullstack test preparation + runs-on: ubuntu-latest + outputs: + pr-number: ${{ steps.pr.outputs.number }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Copy env files + run: | + cp webapp/.env.template webapp/.env + cp backend/.env.template backend/.env + + - name: Build docker images + run: | + mkdir /tmp/images + docker build --target community -t "ocelotsocialnetwork/neo4j-community:test" neo4j/ + docker save "ocelotsocialnetwork/neo4j-community:test" > /tmp/images/neo4j.tar + docker build --target test -t "ocelotsocialnetwork/backend:test" backend/ + docker save "ocelotsocialnetwork/backend:test" > /tmp/images/backend.tar + docker build --target test -t "ocelotsocialnetwork/webapp:test" webapp/ + docker save "ocelotsocialnetwork/webapp:test" > /tmp/images/webapp.tar + + - name: Get pr number + id: pr + uses: 8BitJonny/gh-get-current-pr@2.2.0 + + - name: Cache docker images + id: cache + uses: actions/cache/save@v3.3.1 + with: + path: | + /tmp/images/ + key: e2e-preparation-cache-pr${{ steps.pr.outputs.number }} + fullstack_tests: name: Fullstack tests + if: success() + needs: docker_preparation runs-on: ubuntu-latest env: jobs: 8 From 690021fcb6eb3f575470e15d969267b3a5d7d9ad Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 07:39:57 +0200 Subject: [PATCH 2/6] move cypress requirement installation to preparation step --- .github/workflows/test-e2e.yml | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 87fdb2bf0..9d4a7d1a5 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -26,6 +26,15 @@ jobs: docker build --target test -t "ocelotsocialnetwork/webapp:test" webapp/ docker save "ocelotsocialnetwork/webapp:test" > /tmp/images/webapp.tar + - 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: Get pr number id: pr uses: 8BitJonny/gh-get-current-pr@2.2.0 @@ -35,6 +44,9 @@ jobs: uses: actions/cache/save@v3.3.1 with: path: | + /opt/cucumber-json-formatter + /home/runner/.cache/Cypress + /home/runner/work/Ocelot-Social/Ocelot-Social /tmp/images/ key: e2e-preparation-cache-pr${{ steps.pr.outputs.number }} @@ -50,29 +62,9 @@ jobs: # run copies of the current job in parallel job: [1, 2, 3, 4, 5, 6, 7, 8] steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: webapp | copy env file - run: cp webapp/.env.template webapp/.env - - - name: backend | copy env file - run: cp backend/.env.template backend/.env - - name: boot up test system | docker-compose run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps webapp neo4j backend - - name: Full stack tests | prepare - 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" - chmod +x /opt/cucumber-json-formatter - sudo ln -fs /opt/cucumber-json-formatter /usr/bin/cucumber-json-formatter - cd backend - yarn install - yarn build - cd .. - yarn install - - name: Full stack tests | run tests id: e2e-tests run: yarn run cypress:run --spec $(cypress/parallel-features.sh ${{ matrix.job }} ${{ env.jobs }} ) From 9ba873648e04203a518b4cb1efdd47f259ab9662 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 07:42:58 +0200 Subject: [PATCH 3/6] add cache restoring in e2e test step --- .github/workflows/test-e2e.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 9d4a7d1a5..426b2450c 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -62,8 +62,27 @@ jobs: # run copies of the current job in parallel job: [1, 2, 3, 4, 5, 6, 7, 8] steps: - - name: boot up test system | docker-compose - run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps webapp neo4j backend + - name: Restore cache + uses: actions/cache/restore@v3.3.1 + id: cache + with: + path: | + /opt/cucumber-json-formatter + /home/runner/.cache/Cypress + /home/runner/work/Ocelot-Social/Ocelot-Social + /tmp/images/ + key: e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }} + fail-on-cache-miss: true + + - name: Boot up test system | docker-compose + run: | + chmod +x /opt/cucumber-json-formatter + sudo ln -fs /opt/cucumber-json-formatter /usr/bin/cucumber-json-formatter + docker load < /tmp/images/neo4j.tar + docker load < /tmp/images/backend.tar + docker load < /tmp/images/webapp.tar + docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps webapp neo4j backend + sleep 90s - name: Full stack tests | run tests id: e2e-tests From 545eb04d6cb60a7bccf9423e82890c0b78fb3849 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 07:43:54 +0200 Subject: [PATCH 4/6] adapt step namings --- .github/workflows/test-e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 426b2450c..9235d9f27 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -94,12 +94,12 @@ jobs: cd cypress/ node create-cucumber-html-report.js - - name: End-to-end tests | if tests failed, get pr number + - name: Full stack tests | if tests failed, get pr number id: pr if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }} uses: 8BitJonny/gh-get-current-pr@2.2.0 - - name: End-to-end 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' }} uses: actions/upload-artifact@v3 From fe8d4a4cfa3d477c78f9188682405ea1eefa498a Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 07:46:01 +0200 Subject: [PATCH 5/6] reuse pr number from preparation step in e2e test step --- .github/workflows/test-e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 9235d9f27..e68f2992f 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -104,6 +104,6 @@ jobs: if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }} uses: actions/upload-artifact@v3 with: - name: ocelot-e2e-test-report-pr${{ steps.pr.outputs.number }} + 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 From 6ab1d24c36bbfb6c574f9f873b0f1800dad40471 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 07:47:49 +0200 Subject: [PATCH 6/6] remove pr number step fpm e2e test job --- .github/workflows/test-e2e.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index e68f2992f..2e6986722 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -93,11 +93,6 @@ jobs: run: | cd cypress/ node create-cucumber-html-report.js - - - name: Full stack tests | if tests failed, get pr number - id: pr - if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }} - uses: 8BitJonny/gh-get-current-pr@2.2.0 - name: Full stack tests | if tests failed, upload report id: e2e-report @@ -107,3 +102,16 @@ jobs: 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: + name: Cleanup + if: always() + needs: [docker_preparation, fullstack_tests] + runs-on: ubuntu-latest + steps: + - name: Delete cache + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh extension install actions/gh-actions-cache + KEY="e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }}" + gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm \ No newline at end of file