-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (162 loc) · 5.53 KB
/
e2e.yml
File metadata and controls
190 lines (162 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# E2E Tests CI/CD Workflow
#
# Runs Playwright E2E tests automatically on:
# - Pull requests to main branch
# - Pushes to main branch
# - Manual workflow dispatch
#
# Features:
# - Matrix testing across browsers (Chromium, Firefox, WebKit)
# - Test artifacts (videos, screenshots) on failure
# - Test results summary in PR comments
# - Slack notifications on failure
name: E2E Tests
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
env:
NODE_VERSION: '18'
PLAYWRIGHT_VERSION: '1.56.0'
jobs:
e2e-tests:
name: E2E Tests (${{ matrix.browser }})
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox, webkit]
steps:
- name: 📥 Checkout code
uses: actions/checkout@v6
- name: 🔧 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: 📦 Install dependencies
run: npm ci
- name: 🗄️ Setup test database
run: |
npx prisma generate
npx prisma db push --skip-generate
npx prisma db seed
env:
DATABASE_URL: file:./test.db
- name: 🎭 Install Playwright browsers
run: npx playwright install --with-deps ${{ matrix.browser }}
- name: 🏗️ Build application
run: npm run build
env:
NEXTAUTH_SECRET: test-secret-for-ci
NEXTAUTH_URL: http://localhost:3000
- name: 🚀 Start application
run: npm run start &
env:
PORT: 3000
NEXTAUTH_SECRET: test-secret-for-ci
NEXTAUTH_URL: http://localhost:3000
DATABASE_URL: file:./test.db
- name: ⏳ Wait for application to be ready
run: npx wait-on http://localhost:3000 --timeout 30000
- name: 🧪 Run Playwright tests
run: npx playwright test --project=${{ matrix.browser }}
env:
PLAYWRIGHT_TEST_BASE_URL: http://localhost:3000
- name: 📊 Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report-${{ matrix.browser }}
path: playwright-report/
retention-days: 7
- name: 📹 Upload test videos
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-videos-${{ matrix.browser }}
path: test-results/**/*.webm
retention-days: 7
- name: 📸 Upload test screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-screenshots-${{ matrix.browser }}
path: test-results/**/*.png
retention-days: 7
notify:
name: Notify on Failure
runs-on: ubuntu-latest
needs: [e2e-tests]
if: failure() && github.event_name == 'push'
steps:
- name: 📢 Send Slack notification
uses: slackapi/slack-github-action@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "❌ E2E Tests Failed",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*E2E Tests Failed* :x:\n\n*Repository:* ${{ github.repository }}\n*Branch:* ${{ github.ref_name }}\n*Commit:* ${{ github.sha }}\n*Author:* ${{ github.actor }}"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow Run"
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
comment:
name: Comment Test Results
runs-on: ubuntu-latest
needs: [e2e-tests]
if: always() && github.event_name == 'pull_request'
permissions:
pull-requests: write
steps:
- name: 💬 Comment PR with test results
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const status = '${{ needs.e2e-tests.result }}';
const icon = status === 'success' ? '✅' : '❌';
const message = status === 'success' ? 'All E2E tests passed!' : 'Some E2E tests failed.';
const body = `## ${icon} E2E Test Results
${message}
- **Status**: ${status}
- **Workflow**: [View run](${context.payload.repository.html_url}/actions/runs/${context.runId})
- **Commit**: ${context.sha.substring(0, 7)}
<details>
<summary>Test Configuration</summary>
- **Browsers**: Chromium, Firefox, WebKit
- **Node Version**: ${process.env.NODE_VERSION}
- **Playwright Version**: ${process.env.PLAYWRIGHT_VERSION}
</details>
`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});