From 34145cfa061512f889151b8c1f196ce67304e1b0 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 13:10:28 +0200 Subject: [PATCH 01/11] fix typo --- .github/workflows/test-backend.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index 84d87c770..d144928e8 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v3.3.0 - - name: Check for frontend file changes + - name: Check for backend file changes uses: dorny/paths-filter@v2.11.1 id: changes with: @@ -93,11 +93,11 @@ jobs: - name: Load Docker Image run: docker load < /tmp/neo4j.tar - - name: Download Docker Image (Backend) - uses: actions/download-artifact@v3 - with: - name: docker-backend-test - path: /tmp + # - name: Download Docker Image (Backend) + # uses: actions/download-artifact@v3 + # with: + # name: docker-backend-test + # path: /tmp - name: Load Docker Image run: docker load < /tmp/backend.tar From b15148b985ec0df4a89203dca620ce58a2cf9e04 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 13:18:35 +0200 Subject: [PATCH 02/11] replace artefact upload by caching in neo4j build test job --- .github/workflows/test-backend.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index d144928e8..e6bc213fe 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -35,11 +35,16 @@ jobs: docker build --target community -t "ocelotsocialnetwork/neo4j-community:test" neo4j/ docker save "ocelotsocialnetwork/neo4j-community:test" > /tmp/neo4j.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 + - name: Get pr number + id: pr + uses: 8BitJonny/gh-get-current-pr@2.2.0 + + - name: Cache docker images + id: cache-neo4j + uses: actions/cache/save@v3.3.1 with: - name: docker-neo4j-image path: /tmp/neo4j.tar + key: backend-neo4j-cache-pr${{ steps.pr.outputs.number }} build_test_backend: name: Docker Build Test - Backend @@ -53,13 +58,13 @@ jobs: - name: backend | Build 'test' image run: | docker build --target test -t "ocelotsocialnetwork/backend:test" backend/ - docker save "ocelotsocialnetwork/backend:test" > /tmp/backend.tar + docker save "ocelotsocialnetwork/backend:test" > /tmp/images/backend.tar - name: Upload Artifact uses: actions/upload-artifact@v3 with: name: docker-backend-test - path: /tmp/backend.tar + path: /tmp/images/backend.tar lint_backend: name: Lint Backend From 7e171fb5218911810459f1936c47245818809b42 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 13:21:02 +0200 Subject: [PATCH 03/11] replace artefact upload by caching in backend build test job --- .github/workflows/test-backend.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index e6bc213fe..c484dc702 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -58,13 +58,18 @@ jobs: - name: backend | Build 'test' image run: | docker build --target test -t "ocelotsocialnetwork/backend:test" backend/ - docker save "ocelotsocialnetwork/backend:test" > /tmp/images/backend.tar + docker save "ocelotsocialnetwork/backend:test" > /tmp/backend.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 + - name: Get pr number + id: pr + uses: 8BitJonny/gh-get-current-pr@2.2.0 + + - name: Cache docker images + id: cache-backend + uses: actions/cache/save@v3.3.1 with: - name: docker-backend-test - path: /tmp/images/backend.tar + path: /tmp/backend.tar + key: backend-cache-pr${{ steps.pr.outputs.number }} lint_backend: name: Lint Backend From 4ec4b3659041be9b250b8cbc4c977f5ed18a2734 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 13:57:53 +0200 Subject: [PATCH 04/11] replace artefact download by caching in backend unit test job --- .github/workflows/test-backend.yml | 46 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index c484dc702..c90d0e1ea 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -10,6 +10,7 @@ jobs: outputs: backend: ${{ steps.changes.outputs.backend }} docker: ${{ steps.changes.outputs.docker }} + pr-number: ${{ steps.pr.outputs.number }} steps: - uses: actions/checkout@v3.3.0 @@ -21,6 +22,10 @@ jobs: filters: .github/file-filters.yml list-files: shell + - name: Get pr number + id: pr + uses: 8BitJonny/gh-get-current-pr@2.2.0 + build_test_neo4j: name: Docker Build Test - Neo4J if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.docker == 'true' @@ -34,17 +39,13 @@ jobs: run: | docker build --target community -t "ocelotsocialnetwork/neo4j-community:test" neo4j/ docker save "ocelotsocialnetwork/neo4j-community:test" > /tmp/neo4j.tar - - - name: Get pr number - id: pr - uses: 8BitJonny/gh-get-current-pr@2.2.0 - name: Cache docker images id: cache-neo4j uses: actions/cache/save@v3.3.1 with: path: /tmp/neo4j.tar - key: backend-neo4j-cache-pr${{ steps.pr.outputs.number }} + key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }} build_test_backend: name: Docker Build Test - Backend @@ -59,17 +60,13 @@ jobs: run: | docker build --target test -t "ocelotsocialnetwork/backend:test" backend/ docker save "ocelotsocialnetwork/backend:test" > /tmp/backend.tar - - - name: Get pr number - id: pr - uses: 8BitJonny/gh-get-current-pr@2.2.0 - name: Cache docker images id: cache-backend uses: actions/cache/save@v3.3.1 with: path: /tmp/backend.tar - key: backend-cache-pr${{ steps.pr.outputs.number }} + key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }} lint_backend: name: Lint Backend @@ -94,23 +91,24 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Download Docker Image (Neo4J) - uses: actions/download-artifact@v3 + - name: Restore Neo4J cache + uses: actions/cache/restore@v3.3.1 with: - name: docker-neo4j-image - path: /tmp + path: /tmp/neo4j.tar + key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }} + fail-on-cache-miss: true - - name: Load Docker Image - run: docker load < /tmp/neo4j.tar + - name: Restore Backend cache + uses: actions/cache/restore@v3.3.1 + with: + path: /tmp/backend.tar + key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }} + fail-on-cache-miss: true - # - name: Download Docker Image (Backend) - # uses: actions/download-artifact@v3 - # with: - # name: docker-backend-test - # path: /tmp - - - name: Load Docker Image - run: docker load < /tmp/backend.tar + - name: Load Docker Images + run: | + docker load < /tmp/neo4j.tar + docker load < /tmp/backend.tar - name: backend | copy env files webapp run: cp webapp/.env.template webapp/.env From 89719b3cdad35b2de700fe869dc98c85b2de6cf3 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 14:01:14 +0200 Subject: [PATCH 05/11] merge env copy steps into single step --- .github/workflows/test-backend.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index c90d0e1ea..e293f3e99 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -110,10 +110,10 @@ jobs: docker load < /tmp/neo4j.tar docker load < /tmp/backend.tar - - name: backend | copy env files webapp - run: cp webapp/.env.template webapp/.env - - name: backend | copy env files backend - run: cp backend/.env.template backend/.env + - name: backend | copy env files + run: | + cp webapp/.env.template webapp/.env + cp backend/.env.template backend/.env - name: backend | docker-compose run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps neo4j backend From e44c3493e2a7bde4583d2efb88f0929ebfc1a232 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 14:29:00 +0200 Subject: [PATCH 06/11] add backend test worfkflow file to file filter --- .github/file-filters.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/file-filters.yml b/.github/file-filters.yml index d7f9cb6c0..1c2f4fc62 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -1,4 +1,5 @@ backend: &backend + - '.github/workflows/test-backend.yml' - 'backend/**/*' - 'neo4j/**/*' From f7e8d85b5f59c34dd00b2b427fd12cda53a1a37a Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 14:29:35 +0200 Subject: [PATCH 07/11] add webapp test worfkflow file to file filter --- .github/file-filters.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 1c2f4fc62..8d2d93fac 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -7,4 +7,5 @@ docker: &docker - 'docker-compose.*' webapp: &webapp + - '.github/workflows/test-webapp.yml' - 'webapp/**/*' From 69408007e7d943ad387335633585e90d5e735883 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 15:04:12 +0200 Subject: [PATCH 08/11] replace artefact upload by caching in webapp build test job --- .github/workflows/test-webapp.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-webapp.yml b/.github/workflows/test-webapp.yml index c1aee47cf..3e484d292 100644 --- a/.github/workflows/test-webapp.yml +++ b/.github/workflows/test-webapp.yml @@ -26,6 +26,8 @@ jobs: if: needs.files-changed.outputs.webapp == 'true' needs: files-changed runs-on: ubuntu-latest + outputs: + pr-number: ${{ steps.pr.outputs.number }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -34,7 +36,11 @@ jobs: run: | scripts/translations/sort.sh scripts/translations/missing-keys.sh - + + - name: Get pr number + id: pr + uses: 8BitJonny/gh-get-current-pr@2.2.0 + build_test_webapp: name: Docker Build Test - Webapp if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.webapp == 'true' @@ -44,16 +50,16 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: webapp | Build 'test' image + - name: Webapp | Build 'test' image run: | docker build --target test -t "ocelotsocialnetwork/webapp:test" webapp/ docker save "ocelotsocialnetwork/webapp:test" > /tmp/webapp.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 + - name: Cache docker image + uses: actions/cache/save@v3.3.1 with: - name: docker-webapp-test path: /tmp/webapp.tar + key: webapp-cache-pr${{ needs.prepare.outputs.pr-number }} lint_webapp: name: Lint Webapp From 045d13996094682908dcb7b07565b260960d585a Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 15:11:18 +0200 Subject: [PATCH 09/11] replace artefact upload by caching in webapp unit test job --- .github/workflows/test-webapp.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-webapp.yml b/.github/workflows/test-webapp.yml index 3e484d292..5d603e388 100644 --- a/.github/workflows/test-webapp.yml +++ b/.github/workflows/test-webapp.yml @@ -9,6 +9,7 @@ jobs: runs-on: ubuntu-latest outputs: docker: ${{ steps.changes.outputs.docker }} + pr-number: ${{ steps.pr.outputs.number }} webapp: ${{ steps.changes.outputs.webapp }} steps: - uses: actions/checkout@v3.3.0 @@ -21,13 +22,15 @@ jobs: filters: .github/file-filters.yml list-files: shell + - name: Get pr number + id: pr + uses: 8BitJonny/gh-get-current-pr@2.2.0 + prepare: name: Prepare if: needs.files-changed.outputs.webapp == 'true' needs: files-changed runs-on: ubuntu-latest - outputs: - pr-number: ${{ steps.pr.outputs.number }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -37,10 +40,6 @@ jobs: scripts/translations/sort.sh scripts/translations/missing-keys.sh - - name: Get pr number - id: pr - uses: 8BitJonny/gh-get-current-pr@2.2.0 - build_test_webapp: name: Docker Build Test - Webapp if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.webapp == 'true' @@ -59,7 +58,7 @@ jobs: uses: actions/cache/save@v3.3.1 with: path: /tmp/webapp.tar - key: webapp-cache-pr${{ needs.prepare.outputs.pr-number }} + key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }} lint_webapp: name: Lint Webapp @@ -84,11 +83,11 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Download Docker Image (Webapp) - uses: actions/download-artifact@v3 + - name: Restore webapp cache + uses: actions/cache/restore@v3.3.1 with: - name: docker-webapp-test - path: /tmp + path: /tmp/webapp.tar + key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }} - name: Load Docker Image run: docker load < /tmp/webapp.tar From e1374c05ac5707edaa0eaecea0f77cdb14920131 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 17 Jul 2023 15:17:58 +0200 Subject: [PATCH 10/11] add cache deletion job to backend and webapp workflow files --- .github/workflows/test-backend.yml | 16 ++++++++++++++++ .github/workflows/test-webapp.yml | 23 ++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index e293f3e99..a96cff028 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -126,3 +126,19 @@ jobs: - name: backend | Unit test incl. coverage check run: docker-compose exec -T backend yarn test + + cleanup: + name: Cleanup + if: always() + needs: [files-changed, unit_test_backend] + runs-on: ubuntu-latest + steps: + - name: Delete cache + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh extension install actions/gh-actions-cache + KEY="backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}" + gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm + KEY="backend-cache-pr${{ needs.files-changed.outputs.pr-number }}" + gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm diff --git a/.github/workflows/test-webapp.yml b/.github/workflows/test-webapp.yml index 5d603e388..772182778 100644 --- a/.github/workflows/test-webapp.yml +++ b/.github/workflows/test-webapp.yml @@ -92,11 +92,10 @@ jobs: - name: Load Docker Image run: docker load < /tmp/webapp.tar - - name: backend | copy env files webapp - run: cp webapp/.env.template webapp/.env - - - name: backend | copy env files backend - run: cp backend/.env.template backend/.env + - name: Copy env files + run: | + cp webapp/.env.template webapp/.env + cp backend/.env.template backend/.env - name: backend | docker-compose run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps webapp @@ -104,3 +103,17 @@ jobs: - name: webapp | Unit tests incl. coverage check run: docker-compose exec -T webapp yarn test + cleanup: + name: Cleanup + if: always() + needs: [files-changed, unit_test_webapp] + runs-on: ubuntu-latest + steps: + - name: Delete cache + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh extension install actions/gh-actions-cache + KEY="webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}" + gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm + From 6b7047e604b7b10d6afdd6cc969404a5aea9bbb1 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 18 Jul 2023 10:25:12 +0200 Subject: [PATCH 11/11] set workflow not to fail while deleting cache --- .github/workflows/test-backend.yml | 1 + .github/workflows/test-webapp.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index a96cff028..af53e1fbc 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -138,6 +138,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh extension install actions/gh-actions-cache + set +e KEY="backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}" gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm KEY="backend-cache-pr${{ needs.files-changed.outputs.pr-number }}" diff --git a/.github/workflows/test-webapp.yml b/.github/workflows/test-webapp.yml index 772182778..421ce5187 100644 --- a/.github/workflows/test-webapp.yml +++ b/.github/workflows/test-webapp.yml @@ -114,6 +114,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh extension install actions/gh-actions-cache + set +e KEY="webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}" gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm