Skip to content

Commit 6b31ff1

Browse files
authored
feat: Add bundle analysis workflow and enhance test analytics configuration (#45)
1 parent 75729a6 commit 6b31ff1

File tree

5 files changed

+374
-13
lines changed

5 files changed

+374
-13
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Bundle Analysis
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'frontend/**'
7+
branches: [ main, master ]
8+
push:
9+
paths:
10+
- 'frontend/**'
11+
branches: [ main, master ]
12+
13+
jobs:
14+
bundle-analysis:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '18'
26+
cache: 'npm'
27+
cache-dependency-path: frontend/package-lock.json
28+
29+
- name: Install Dependencies
30+
run: |
31+
cd frontend
32+
npm ci
33+
34+
- name: Build for Bundle Analysis
35+
run: |
36+
cd frontend
37+
# Create a production build for analysis
38+
if npm run build --dry-run 2>/dev/null; then
39+
npm run build
40+
else
41+
# Use Expo's build process
42+
npx expo export:web
43+
fi
44+
45+
- name: Analyze Bundle Size
46+
run: |
47+
cd frontend
48+
# Install bundle analyzer
49+
npm install --no-save webpack-bundle-analyzer
50+
51+
# Generate bundle stats (adjust path based on your build output)
52+
if [ -d "web-build" ]; then
53+
# Expo web build
54+
npx webpack-bundle-analyzer web-build/static/js/*.js --report --mode static --report-filename bundle-report.html
55+
elif [ -d "dist" ]; then
56+
# Standard React build
57+
npx webpack-bundle-analyzer dist/static/js/*.js --report --mode static --report-filename bundle-report.html
58+
else
59+
echo "No build output found for bundle analysis"
60+
fi
61+
62+
- name: Upload Bundle Analysis to Codecov
63+
uses: codecov/codecov-action@v4
64+
if: github.actor != 'dependabot[bot]'
65+
with:
66+
token: ${{ secrets.CODECOV_TOKEN }}
67+
flags: bundle,frontend,javascript
68+
name: "Bundle Analysis"
69+
fail_ci_if_error: false
70+
71+
- name: Bundle Analysis Skipped
72+
if: github.actor == 'dependabot[bot]'
73+
run: echo "📦 Bundle analysis skipped for Dependabot PR"

.github/workflows/run-tests.yml

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Tests
1+
name: Run Tests & Analytics
22

33
on:
44
pull_request:
@@ -12,6 +12,8 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Full history for better diff analysis
1517

1618
- name: Set up Python
1719
uses: actions/setup-python@v5
@@ -24,21 +26,87 @@ jobs:
2426
cd backend
2527
pip install -r requirements.txt
2628
27-
- name: Run tests
29+
- name: Run Backend Tests with Coverage
2830
run: |
2931
cd $GITHUB_WORKSPACE
3032
export PYTHONPATH=$GITHUB_WORKSPACE:$GITHUB_WORKSPACE/backend
31-
pytest --cov=./backend --cov-report=xml:coverage.xml backend/tests/
32-
33-
- name: Upload coverage to Codecov
33+
# Generate coverage with detailed flags
34+
pytest \
35+
--cov=./backend \
36+
--cov-report=xml:coverage.xml \
37+
--cov-report=json:coverage.json \
38+
--cov-report=lcov:coverage.lcov \
39+
--junit-xml=test-results.xml \
40+
--tb=short \
41+
-v \
42+
backend/tests/
43+
44+
- name: Run Test Analytics Upload
45+
uses: codecov/test-results-action@v1
46+
if: github.actor != 'dependabot[bot]'
47+
with:
48+
token: ${{ secrets.CODECOV_TOKEN }}
49+
files: test-results.xml
50+
flags: backend,test-analytics
51+
name: "Backend Test Results"
52+
53+
- name: Upload Coverage to Codecov with Flags
3454
uses: codecov/codecov-action@v4
55+
if: github.actor != 'dependabot[bot]'
3556
with:
3657
token: ${{ secrets.CODECOV_TOKEN }}
37-
files: ./coverage.xml
58+
files: ./coverage.xml,./coverage.json,./coverage.lcov
59+
flags: backend,python,api
60+
name: "Backend Coverage"
3861
fail_ci_if_error: false
39-
# Skip codecov upload for Dependabot PRs since they don't have access to secrets
40-
if: github.actor != 'dependabot[bot]'
41-
62+
verbose: true
63+
4264
- name: Codecov upload skipped for Dependabot
4365
if: github.actor == 'dependabot[bot]'
4466
run: echo "📊 Codecov upload skipped for Dependabot PR - tests still run and pass!"
67+
68+
test-frontend:
69+
runs-on: ubuntu-latest
70+
71+
steps:
72+
- uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
75+
76+
- name: Set up Node.js
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: '18'
80+
cache: 'npm'
81+
cache-dependency-path: frontend/package-lock.json
82+
83+
- name: Install Frontend Dependencies
84+
run: |
85+
cd frontend
86+
npm ci
87+
88+
- name: Run Frontend Tests (if available)
89+
run: |
90+
cd frontend
91+
# Check if test script exists
92+
if npm run test --dry-run 2>/dev/null; then
93+
npm run test -- --coverage --watchAll=false --testResultsProcessor=jest-junit
94+
else
95+
echo "No frontend tests configured yet"
96+
# Create a placeholder test result for analytics
97+
mkdir -p test-results
98+
echo '<?xml version="1.0"?><testsuites><testsuite name="frontend-placeholder" tests="1" failures="0" errors="0"><testcase name="placeholder" /></testsuite></testsuites>' > test-results/frontend-results.xml
99+
fi
100+
101+
- name: Upload Frontend Test Analytics
102+
uses: codecov/test-results-action@v1
103+
if: github.actor != 'dependabot[bot]'
104+
with:
105+
token: ${{ secrets.CODECOV_TOKEN }}
106+
files: frontend/test-results/frontend-results.xml
107+
flags: frontend,javascript,react-native
108+
name: "Frontend Test Results"
109+
110+
- name: Frontend Analytics Upload Skipped
111+
if: github.actor == 'dependabot[bot]'
112+
run: echo "📊 Frontend test analytics skipped for Dependabot PR"

backend/pytest.ini

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,23 @@ python_files = test_*.py tests_*.py *_test.py *_tests.py
99
python_classes = Test* Tests*
1010
python_functions = test_*
1111

12-
# Optional: Add default command line options if desired
13-
# addopts = --verbose
12+
# Enhanced options for better test analytics and coverage
13+
addopts =
14+
--verbose
15+
--tb=short
16+
--strict-markers
17+
--disable-warnings
18+
--durations=10
19+
--cov-branch
20+
--cov-fail-under=0
21+
22+
# Test markers for categorization
23+
markers =
24+
unit: Unit tests
25+
integration: Integration tests
26+
auth: Authentication related tests
27+
expenses: Expense management tests
28+
groups: Group management tests
29+
user: User management tests
30+
slow: Slow running tests
31+
api: API endpoint tests

codecov.yml

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,101 @@
11
# Codecov configuration for SplitWiser
22
# Documentation: https://docs.codecov.com/docs/codecov-yaml
3+
# Features: Test Analytics, Flags, Components, Bundle Analysis
34

45
coverage:
56
status:
67
project:
78
default:
89
target: auto
910
threshold: 1%
10-
# Allow slight coverage drops for dependency updates
1111
if_ci_failed: error
12+
backend:
13+
target: auto
14+
threshold: 1%
15+
flags:
16+
- backend
17+
paths:
18+
- backend/
19+
frontend:
20+
target: auto
21+
threshold: 1%
22+
flags:
23+
- frontend
24+
paths:
25+
- frontend/
1226
patch:
1327
default:
1428
target: auto
1529
threshold: 1%
16-
# More lenient for dependency-only changes
1730
if_ci_failed: error
1831

32+
# Flags for different parts of the codebase
33+
flag_management:
34+
default_rules:
35+
carryforward: true
36+
statuses:
37+
- type: project
38+
target: auto
39+
threshold: 1%
40+
- type: patch
41+
target: auto
42+
threshold: 1%
43+
44+
# Components for modular coverage tracking
45+
component_management:
46+
default_rules:
47+
statuses:
48+
- type: project
49+
target: auto
50+
- type: patch
51+
target: auto
52+
individual_components:
53+
- component_id: backend-auth
54+
name: "Authentication System"
55+
paths:
56+
- backend/app/auth/
57+
- backend/tests/auth/
58+
flag_regexes:
59+
- backend
60+
- component_id: backend-expenses
61+
name: "Expense Management"
62+
paths:
63+
- backend/app/expenses/
64+
- backend/tests/expenses/
65+
flag_regexes:
66+
- backend
67+
- component_id: backend-groups
68+
name: "Group Management"
69+
paths:
70+
- backend/app/groups/
71+
- backend/tests/groups/
72+
flag_regexes:
73+
- backend
74+
- component_id: backend-user
75+
name: "User Management"
76+
paths:
77+
- backend/app/user/
78+
- backend/tests/user/
79+
flag_regexes:
80+
- backend
81+
- component_id: frontend-core
82+
name: "Frontend Core"
83+
paths:
84+
- frontend/
85+
flag_regexes:
86+
- frontend
87+
88+
# Test Analytics configuration
89+
test_analytics:
90+
# Track test performance and flakiness
91+
notify:
92+
after_n_builds: 5
93+
slack:
94+
url: "https://hooks.slack.com/services/your/slack/webhook"
95+
threshold: 5%
96+
message: "Test suite analytics show concerning trends"
97+
only_pulls: false
98+
1999
# Ignore files that don't need coverage
20100
ignore:
21101
- "**/__pycache__/**"

0 commit comments

Comments
 (0)