feat(ci): integrate Playwright E2E tests into Docker build workflow

This commit is contained in:
GitHub Actions
2026-01-12 20:10:16 +00:00
parent 4e23a63d8f
commit b1b7defaae
2 changed files with 121 additions and 1 deletions

View File

@@ -793,3 +793,113 @@ jobs:
issue_number: context.issue.number,
body: body
});
# ============================================================================
# E2E Tests (Playwright) for PR Builds
# ============================================================================
# This job runs end-to-end tests using Playwright against the Docker image
# built for pull requests. It validates the application's functionality from
# the user's perspective before merging.
#
# Dependency Chain: build-and-push → e2e-tests-pr
# ============================================================================
e2e-tests-pr:
name: E2E Tests (Playwright)
needs: build-and-push
runs-on: ubuntu-latest
timeout-minutes: 15
if: |
github.event_name == 'pull_request' &&
needs.build-and-push.outputs.skip_build != 'true' &&
needs.build-and-push.result == 'success'
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Download Docker image artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: pr-image-${{ github.event.pull_request.number }}
- name: Load Docker image
run: |
echo "📦 Loading image from artifact..."
docker load -i charon-pr-image.tar
echo "✅ Image loaded successfully"
- name: Normalize image name
run: |
IMAGE_NAME=$(echo "${{ github.repository_owner }}/charon" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
- name: Verify loaded image
run: |
IMAGE_REF="ghcr.io/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}"
if ! docker image inspect "${IMAGE_REF}" >/dev/null 2>&1; then
echo "❌ ERROR: Image not found: ${IMAGE_REF}"
docker images
exit 1
fi
echo "✅ Image loaded: ${IMAGE_REF}"
- name: Start application container
run: |
IMAGE_REF="ghcr.io/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}"
docker run -d --name charon \
-p 8080:8080 \
-e CHARON_ENV=development \
-e CHARON_DEBUG=1 \
-e CHARON_ENCRYPTION_KEY=test-key-for-ci-only-not-production \
"${IMAGE_REF}"
- name: Wait for application health
run: |
echo "Waiting for application to be ready..."
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/v1/health > /dev/null; do
echo "Waiting for health endpoint..."
sleep 2
done'
echo "✅ Application is ready"
- name: Setup Node.js
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
with:
node-version: lts/*
- name: Install Playwright dependencies
run: |
npm ci
npx playwright install --with-deps chromium
- name: Run Playwright E2E tests
env:
PLAYWRIGHT_BASE_URL: http://localhost:8080
run: npx playwright test
- name: Stop application container
if: always()
run: docker stop charon && docker rm charon
- name: Upload Playwright report
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: playwright-report-pr-${{ github.event.pull_request.number }}
path: playwright-report/
retention-days: 7
- name: Create E2E Test Summary
if: always()
run: |
echo "## 🎭 E2E Test Results - PR #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image**: \`ghcr.io/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Status**: ${{ job.status == 'success' && '✅ All tests passed' || '❌ Tests failed' }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ job.status }}" != "success" ]]; then
echo "📊 [View Test Report](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}#artifacts)" >> $GITHUB_STEP_SUMMARY
fi