-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (106 loc) · 4.17 KB
/
Copy pathpull_request.yml
File metadata and controls
125 lines (106 loc) · 4.17 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
name: Pull Request Check
on:
pull_request:
branches: [master]
jobs:
check-and-build:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Check formatting with Prettier
id: prettier
run: |
if ! npx prettier --check .; then
echo "PRETTIER_FAILED=true" >> $GITHUB_ENV
fi
- name: Run ESLint
id: eslint
run: |
if ! npx eslint .; then
echo "ESLINT_FAILED=true" >> $GITHUB_ENV
fi
- name: Comment lint or formatter failures
if: env.PRETTIER_FAILED == 'true' || env.ESLINT_FAILED == 'true'
uses: actions/github-script@v7
with:
script: |
const messages = [];
if (process.env.PRETTIER_FAILED === 'true') {
messages.push("❌ Prettier check failed. Please format your code with `npm run format` before commiting!");
}
if (process.env.ESLINT_FAILED === 'true') {
messages.push("❌ ESLint check failed. Please fix lint issues with `npm run lint` before commiting!");
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: messages.join('\n')
});
env:
PRETTIER_FAILED: ${{ env.PRETTIER_FAILED }}
ESLINT_FAILED: ${{ env.ESLINT_FAILED }}
- name: Fail build if linting failed
if: env.PRETTIER_FAILED == 'true' || env.ESLINT_FAILED == 'true'
run: exit 1
- name: Build Docker image
run: docker build -t mastermind-vue:test .
- name: Run Docker container
run: docker run -d -p 8080:80 --name test-container mastermind-vue:test
- name: Wait for container
run: |
for i in {1..30}; do
curl -s http://localhost:8080 | grep -q '<title>Mastermind – Das klassische Logikspiel online</title>' && exit 0
echo "Waiting for container..."
sleep 2
done
echo "❌ Failed to verify running app. See logs below:"
docker logs test-container
exit 1
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Run Playwright Tests
run: BASE_URL=http://localhost:8080 npm run test:e2e:ci
- name: Upload Playwright Report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- name: Parse test results
if: always()
id: parse
run: |
passed=$(jq '[.suites[].specs[].tests[] | select(.results[].status == "passed")] | length' playwright-report/test-results.json)
failed=$(jq '[.suites[].specs[].tests[] | select(.results[].status == "failed")] | length' playwright-report/test-results.json)
total=$(jq '[.suites[].specs[].tests[]] | length' playwright-report/test-results.json)
artifact_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "summary=**Playwright Test Summary**: ✅ $passed / ❌ $failed / 🧪 $total tests%0A📊 [Complete test result]($artifact_url)" >> $GITHUB_OUTPUT
- name: Add test summary
id: tests_results_summary
if: always()
uses: actions/github-script@v7
with:
script: |
const summary = `${process.env.SUMMARY}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary.replace(/%0A/g, '\n') // Ersetze %0A durch echte Zeilenumbrüche
});
env:
SUMMARY: ${{ steps.parse.outputs.summary }}
- name: Cleanup
if: always()
run: docker rm -f test-container || true