-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (143 loc) · 5.11 KB
/
test.yml
File metadata and controls
164 lines (143 loc) · 5.11 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
name: Test Suite
# ============================================================================
# Test Suite & Build Verification
# ============================================================================
# Runs tests with coverage and builds the Next.js application.
# This workflow works OUT-OF-THE-BOX without requiring any secrets.
#
# OPTIONAL: Codecov Integration (commented out by default)
# - CODECOV_TOKEN: Token from codecov.io
# ============================================================================
on:
workflow_call:
workflow_dispatch:
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
checks: write
strategy:
matrix:
node-version: [20.x]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 10
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Cache Next.js build
uses: actions/cache@v5
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run tests with coverage
run: pnpm test:coverage
- name: Generate coverage summary
if: always()
run: |
echo "## Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
tail -n 10 coverage/lcov-report/index.html | grep -oP '(?<=<div class="pad1">).*?(?=</div>)' | head -1 || echo "Coverage report generated" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
# Optional: Upload coverage to Codecov (requires CODECOV_TOKEN secret)
# Uncomment the following steps to enable Codecov integration:
#
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# if: ${{ (github.event_name == 'pull_request' || github.ref == 'refs/heads/master') && env.CODECOV_TOKEN != '' }}
# with:
# token: ${{ env.CODECOV_TOKEN }}
# files: ./coverage/lcov.info
# flags: unittests
# name: codecov-umbrella
# fail_ci_if_error: false
# continue-on-error: true
#
# - name: Code Coverage Report
# uses: irongut/CodeCoverageSummary@v1.3.0
# if: github.event_name == 'pull_request'
# with:
# filename: coverage/cobertura-coverage.xml
# badge: true
# fail_below_min: false
# format: markdown
# hide_branch_rate: false
# hide_complexity: true
# indicators: true
# output: both
# thresholds: '60 80'
# continue-on-error: true
#
# - name: Add Coverage PR Comment
# uses: marocchino/sticky-pull-request-comment@v2
# if: github.event_name == 'pull_request'
# with:
# recreate: true
# path: code-coverage-results.md
# continue-on-error: true
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results
path: coverage/junit.xml
retention-days: 30
- name: Upload coverage report
uses: actions/upload-artifact@v7
if: always()
with:
name: coverage-report
path: coverage/
retention-days: 30
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() && github.event_name == 'pull_request'
with:
files: |
coverage/junit.xml
check_name: Test Results
comment_title: Test Results
continue-on-error: true
- name: Build Next.js application
run: pnpm build
- name: Check bundle size
if: github.event_name == 'pull_request'
run: |
echo "## Bundle Size Analysis" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output Directory Size" >> $GITHUB_STEP_SUMMARY
du -sh out/ >> $GITHUB_STEP_SUMMARY || echo "Build output size check skipped" >> $GITHUB_STEP_SUMMARY
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: nextjs-build
path: out/
retention-days: 7
- name: Store build size
if: github.ref == 'refs/heads/master'
run: |
mkdir -p .github/size-snapshot
du -sb out/ | cut -f1 > .github/size-snapshot/build-size.txt
continue-on-error: true