From 6e836142ede00a6f524be499396fa5119a49aee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Schr=C3=B6ter?= Date: Sun, 2 Feb 2025 22:53:27 +0100 Subject: [PATCH] feat: consolidate E2E testing workflow into Docker build process and remove legacy workflow --- .github/workflows/docker-build-and-push.yml | 63 +++++++++++++++---- .github/workflows/e2e-tests.yml | 70 --------------------- web-app/e2e/test-environment.ts | 4 +- 3 files changed, 53 insertions(+), 84 deletions(-) delete mode 100644 .github/workflows/e2e-tests.yml diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index f252f71..018eb15 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -16,29 +16,22 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Go uses: actions/setup-go@v5 with: go-version: 1.22 - - name: Install mupdf run: sudo apt-get install -y mupdf - - name: Set library path run: echo "/usr/lib" | sudo tee -a /etc/ld.so.conf.d/mupdf.conf && sudo ldconfig - - name: Install dependencies run: go mod download - - name: Run Go tests run: go test ./... - - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 20 - - name: Cache npm dependencies uses: actions/cache@v4 with: @@ -46,11 +39,9 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - - name: Install frontend dependencies run: npm install working-directory: web-app - - name: Run frontend tests run: npm test working-directory: web-app @@ -60,13 +51,13 @@ jobs: needs: test outputs: digest: ${{ steps.build_amd64.outputs.digest }} + image_tag: ${{ steps.set_image_tag.outputs.image_tag }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - if: ${{ github.event_name != 'pull_request' }} uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} @@ -74,7 +65,9 @@ jobs: - name: Set Docker tags id: set_tags run: | - if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then + if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then + echo "TAGS=icereed/paperless-gpt:pr-${GITHUB_SHA}-amd64" >> $GITHUB_ENV + elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then VERSION=${GITHUB_REF#refs/tags/} echo "TAGS=icereed/paperless-gpt:${VERSION}-amd64" >> $GITHUB_ENV else @@ -86,7 +79,7 @@ jobs: with: context: . platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} + push: true cache-from: type=gha cache-to: type=gha,mode=max tags: ${{ env.TAGS }} @@ -94,6 +87,9 @@ jobs: VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }} COMMIT=${{ github.sha }} BUILD_DATE=${{ github.event.repository.pushed_at }} + - name: Set image tag output + id: set_image_tag + run: echo "image_tag=${TAGS}" >> $GITHUB_OUTPUT - name: Export digest for amd64 run: | mkdir -p ${{ runner.temp }}/digests @@ -203,4 +199,45 @@ jobs: docker buildx imagetools inspect ${DOCKERHUB_REPO}:${VERSION} if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then docker buildx imagetools inspect ${DOCKERHUB_REPO}:latest - fi \ No newline at end of file + fi + + e2e-tests: + name: E2E Tests + needs: build-amd64 + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./web-app + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: './web-app/package-lock.json' + - name: Install dependencies + run: npm ci + - name: Install Playwright browsers + run: npx playwright install chromium --with-deps + - name: Run Playwright tests + run: npm run test:e2e + env: + CI: true + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + PAPERLESS_GPT_IMAGE: ${{ needs.build-amd64.outputs.image_tag }} + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: playwright-report + path: web-app/playwright-report/ + retention-days: 30 + - name: Upload test screenshots + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: web-app/test-results/ + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml deleted file mode 100644 index f642ca4..0000000 --- a/.github/workflows/e2e-tests.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: E2E Tests - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - name: E2E Tests - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./web-app - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - cache: 'npm' - cache-dependency-path: './web-app/package-lock.json' - - - name: Install dependencies - run: npm ci - - - name: Install Playwright browsers - run: npx playwright install chromium --with-deps - - - name: Build app - run: npm run build - - - name: Create test env file - run: | - echo "PAPERLESS_GPT_URL=http://localhost:8080" > .env.test - echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env.test - - - name: Start test containers - run: npm run docker:test:up - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - - - name: Run Playwright tests - run: npm run test:e2e - env: - CI: true - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v4 - with: - name: playwright-report - path: web-app/playwright-report/ - retention-days: 30 - - - name: Upload test screenshots - if: always() - uses: actions/upload-artifact@v4 - with: - name: test-results - path: web-app/test-results/ - retention-days: 30 - - - name: Stop test containers - if: always() - run: npm run docker:test:down diff --git a/web-app/e2e/test-environment.ts b/web-app/e2e/test-environment.ts index c3cd23f..5fbf211 100644 --- a/web-app/e2e/test-environment.ts +++ b/web-app/e2e/test-environment.ts @@ -76,7 +76,9 @@ export async function setupTestEnvironment(): Promise { } console.log('Starting Paperless-gpt container...'); - const paperlessGpt = await new GenericContainer('icereed/paperless-gpt:e2e') + const paperlessGptImage = process.env.PAPERLESS_GPT_IMAGE || 'icereed/paperless-gpt:e2e'; + console.log(`Using image: ${paperlessGptImage}`); + const paperlessGpt = await new GenericContainer(paperlessGptImage) .withNetwork(network) .withEnvironment({ PAPERLESS_BASE_URL: `http://paperless-ngx:${paperlessPort}`,