ci: add Codecov bundle and test reporting

This commit is contained in:
lezi-fun committed 2026-08-13 13:58:46 +08:00
1 parent e6ac6ab03c
commit acf5d40e57
5 files changed
+1130 -10

No files matched your search

+36 -10
View File
@@ -57,17 +57,15 @@ jobs:
- name: Build application
run: npm run build
- name: Upload bundle analysis to Codecov
env:
CODECOV_BUNDLE_ANALYSIS: 'true'
run: npx next build --webpack
- name: Run integration tests with coverage
run: |
npx c8 \
--all \
--include 'app/**/*.js' \
--include 'lib/**/*.js' \
--exclude-after-remap \
--reporter lcov \
--reports-dir coverage \
--temp-directory .coverage-tmp \
node scripts/start.js > server.log 2>&1 &
mkdir -p .coverage-tmp
NODE_V8_COVERAGE="$PWD/.coverage-tmp" node scripts/start.js > server.log 2>&1 &
server_pid=$!
cleanup() {
kill "$server_pid" 2>/dev/null || true
@@ -86,12 +84,40 @@ jobs:
sleep 1
done
npm test
node --test \
--test-concurrency=1 \
--test-reporter=spec \
--test-reporter=junit \
--test-reporter-destination=stdout \
--test-reporter-destination=test-results.xml \
test/*.test.js
cleanup
trap - EXIT
npx c8 report \
--all \
--include 'app/**/*.js' \
--include 'lib/**/*.js' \
--exclude-after-remap \
--reporter lcov \
--reports-dir coverage \
--temp-directory .coverage-tmp
test -s coverage/lcov.info
test -s test-results.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
use_oidc: true
files: coverage/lcov.info
disable_search: true
fail_ci_if_error: true
verbose: true
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
with:
use_oidc: true
file: test-results.xml
disable_search: true
fail_ci_if_error: true
+1
View File
@@ -5,6 +5,7 @@ out/
*.log
coverage/
.coverage-tmp/
test-results.xml
.DS_Store
# 环境变量:.env 是用户本地环境变量(不提交),模板 .env.example 进仓库
+16
View File
@@ -1,3 +1,5 @@
const enableCodecovBundleAnalysis = process.env.CODECOV_BUNDLE_ANALYSIS === 'true';
/** @type {import('next').NextConfig} */
const nextConfig = {
// 本地开发允许的来源:默认本机;局域网/其他设备通过环境变量追加
@@ -14,6 +16,20 @@ const nextConfig = {
{ source: '/uploads/:name', destination: '/api/uploads/:name' },
];
},
...(enableCodecovBundleAnalysis ? {
webpack(config) {
const { codecovWebpackPlugin } = require('@codecov/webpack-plugin');
config.plugins.push(codecovWebpackPlugin({
enableBundleAnalysis: true,
bundleName: 'forumlify-next',
gitService: 'github',
dryRun: process.env.GITHUB_ACTIONS !== 'true',
oidc: { useGitHubOIDC: true },
}));
return config;
},
} : {}),
};
module.exports = nextConfig;
+1075
View File
File diff suppressed because it is too large. Load diff
+2
View File
@@ -27,9 +27,11 @@
"sanitize-html": "^2.17.6"
},
"devDependencies": {
"@codecov/webpack-plugin": "^2.0.1",
"@opennextjs/cloudflare": "^1.20.2",
"c8": "^10.1.3",
"puppeteer-core": "^25.5.0",
"webpack": "^5.109.2",
"wrangler": "^4.120.0"
}
}