-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (119 loc) · 4.32 KB
/
test.yml
File metadata and controls
137 lines (119 loc) · 4.32 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
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
# Also run when Dependabot creates PRs
pull_request_target:
branches: [main]
jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
# Important for security when using pull_request_target
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Full git history for Dependabot PRs
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Type check
id: typecheck
continue-on-error: true
run: npm run check
- name: Lint
id: lint
continue-on-error: true
run: npm run lint
- name: Build
id: build
continue-on-error: true
run: npm run build
- name: Run unit tests
id: unit-tests
continue-on-error: true
run: npm run test:unit
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Run integration tests
id: integration-tests
continue-on-error: true
run: npm run test:integration
- name: Start preview server and test endpoints
id: preview
continue-on-error: true
run: |
npm run preview &
sleep 5
# Basic health check
curl -f http://localhost:4173/
# Test API endpoints
curl -f http://localhost:4173/api/weather
- name: Comment on PR
if: github.event_name == 'pull_request_target' && always()
uses: actions/github-script@v7
with:
script: |
// Store step outcomes
const outcomes = {
typecheck: '${{ steps.typecheck.outcome }}',
lint: '${{ steps.lint.outcome }}',
build: '${{ steps.build.outcome }}',
unitTests: '${{ steps.unit-tests.outcome }}',
integrationTests: '${{ steps.integration-tests.outcome }}',
preview: '${{ steps.preview.outcome }}'
};
// Convert outcome to emoji
const getEmoji = (outcome) => {
switch(outcome) {
case 'success': return '✅';
case 'failure': return '❌';
case 'skipped': return '⏭️';
default: return '❓';
}
};
// Check if any tests failed
const hasFailures = Object.values(outcomes).includes('failure');
const header = hasFailures ? '## Test Results ❌' : '## Test Results ✅';
const message = `${header}\n\n` +
'Build and test run completed.\n\n' +
'Details:\n' +
`- Type checking: ${getEmoji(outcomes.typecheck)}\n` +
`- Linting: ${getEmoji(outcomes.lint)}\n` +
`- Build: ${getEmoji(outcomes.build)}\n` +
`- Unit tests: ${getEmoji(outcomes.unitTests)}\n` +
`- Integration tests: ${getEmoji(outcomes.integrationTests)}\n` +
`- Preview: ${getEmoji(outcomes.preview)}\n\n` +
(hasFailures ? '⚠️ Some checks failed. Please review the workflow logs for details.\n\n' : '') +
'Full results available in workflow artifacts.';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
# Make the workflow fail if any tests failed
- name: Check for test failures
if: always()
run: |
if [[ "${{ steps.typecheck.outcome }}" == "failure" ]] || \
[[ "${{ steps.lint.outcome }}" == "failure" ]] || \
[[ "${{ steps.build.outcome }}" == "failure" ]] || \
[[ "${{ steps.unit-tests.outcome }}" == "failure" ]] || \
[[ "${{ steps.integration-tests.outcome }}" == "failure" ]] || \
[[ "${{ steps.preview.outcome }}" == "failure" ]]; then
echo "Some tests failed!"
exit 1
fi