From debef9a66bca247ab162c9bb038e85964279a667 Mon Sep 17 00:00:00 2001 From: Kyle Mendell Date: Sun, 20 Apr 2025 11:48:46 -0500 Subject: [PATCH] ci/cd: setup caching and improve ci job performance (#465) --- .github/workflows/e2e-tests.yml | 73 +++++++++++++++++++++++++++------ backend/go.mod | 2 +- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 0f731aab..d8778e22 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -19,21 +19,28 @@ jobs: timeout-minutes: 20 runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and export uses: docker/build-push-action@v6 with: - tags: pocket-id/pocket-id:test + push: false + load: false + tags: pocket-id:test outputs: type=docker,dest=/tmp/docker-image.tar build-args: BUILD_TAGS=e2etest + cache-from: type=gha + cache-to: type=gha,mode=max - name: Upload Docker image artifact uses: actions/upload-artifact@v4 with: name: docker-image path: /tmp/docker-image.tar + retention-days: 1 test-sqlite: if: github.event.pull_request.head.ref != 'i18n_crowdin' @@ -47,13 +54,22 @@ jobs: cache: "npm" cache-dependency-path: frontend/package-lock.json + - name: Cache Playwright Browsers + uses: actions/cache@v3 + id: playwright-cache + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('frontend/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-playwright- + - name: Download Docker image artifact uses: actions/download-artifact@v4 with: name: docker-image path: /tmp - - name: Load Docker Image + - name: Load Docker image run: docker load -i /tmp/docker-image.tar - name: Install frontend dependencies @@ -62,6 +78,7 @@ jobs: - name: Install Playwright Browsers working-directory: ./frontend + if: steps.playwright-cache.outputs.cache-hit != 'true' run: npx playwright install --with-deps chromium - name: Run Docker Container with Sqlite DB @@ -69,7 +86,7 @@ jobs: docker run -d --name pocket-id-sqlite \ -p 80:80 \ -e APP_ENV=test \ - pocket-id/pocket-id:test + pocket-id:test docker logs -f pocket-id-sqlite &> /tmp/backend.log & @@ -77,16 +94,18 @@ jobs: working-directory: ./frontend run: npx playwright test - - uses: actions/upload-artifact@v4 - if: always() + - name: Upload Frontend Test Report + uses: actions/upload-artifact@v4 + if: always() && github.event.pull_request.head.ref != 'i18n_crowdin' with: name: playwright-report-sqlite path: frontend/tests/.report include-hidden-files: true retention-days: 15 - - uses: actions/upload-artifact@v4 - if: always() + - name: Upload Backend Test Report + uses: actions/upload-artifact@v4 + if: always() && github.event.pull_request.head.ref != 'i18n_crowdin' with: name: backend-sqlite path: /tmp/backend.log @@ -105,12 +124,39 @@ jobs: cache: "npm" cache-dependency-path: frontend/package-lock.json + - name: Cache Playwright Browsers + uses: actions/cache@v3 + id: playwright-cache + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('frontend/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-playwright- + + - name: Cache PostgreSQL Docker image + uses: actions/cache@v3 + id: postgres-cache + with: + path: /tmp/postgres-image.tar + key: postgres-17-${{ runner.os }} + + - name: Pull and save PostgreSQL image + if: steps.postgres-cache.outputs.cache-hit != 'true' + run: | + docker pull postgres:17 + docker save postgres:17 > /tmp/postgres-image.tar + + - name: Load PostgreSQL image from cache + if: steps.postgres-cache.outputs.cache-hit == 'true' + run: docker load < /tmp/postgres-image.tar + - name: Download Docker image artifact uses: actions/download-artifact@v4 with: name: docker-image path: /tmp - - name: Load Docker Image + + - name: Load Docker image run: docker load -i /tmp/docker-image.tar - name: Install frontend dependencies @@ -119,6 +165,7 @@ jobs: - name: Install Playwright Browsers working-directory: ./frontend + if: steps.playwright-cache.outputs.cache-hit != 'true' run: npx playwright install --with-deps chromium - name: Create Docker network @@ -153,7 +200,7 @@ jobs: -e APP_ENV=test \ -e DB_PROVIDER=postgres \ -e DB_CONNECTION_STRING=postgresql://postgres:postgres@pocket-id-db:5432/pocket-id \ - pocket-id/pocket-id:test + pocket-id:test docker logs -f pocket-id-postgres &> /tmp/backend.log & @@ -161,7 +208,8 @@ jobs: working-directory: ./frontend run: npx playwright test - - uses: actions/upload-artifact@v4 + - name: Upload Frontend Test Report + uses: actions/upload-artifact@v4 if: always() && github.event.pull_request.head.ref != 'i18n_crowdin' with: name: playwright-report-postgres @@ -169,8 +217,9 @@ jobs: include-hidden-files: true retention-days: 15 - - uses: actions/upload-artifact@v4 - if: always() + - name: Upload Backend Test Report + uses: actions/upload-artifact@v4 + if: always() && github.event.pull_request.head.ref != 'i18n_crowdin' with: name: backend-postgres path: /tmp/backend.log diff --git a/backend/go.mod b/backend/go.mod index 5dd91342..40c8d42f 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,6 +1,6 @@ module github.com/pocket-id/pocket-id/backend -go 1.24 +go 1.24.0 require ( github.com/caarlos0/env/v11 v11.3.1