Skip to content

Commit 168610b

Browse files
authored
chore: Add in debug logs for all upload params (#179)
1 parent 7e99416 commit 168610b

30 files changed

+1018
-378
lines changed

.changeset/serious-olives-add.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@codecov/bundler-plugin-core": minor
3+
"@codecov/bundle-analyzer": minor
4+
"@codecov/nextjs-webpack-plugin": minor
5+
"@codecov/nuxt-plugin": minor
6+
"@codecov/remix-vite-plugin": minor
7+
"@codecov/rollup-plugin": minor
8+
"@codecov/solidstart-plugin": minor
9+
"@codecov/sveltekit-plugin": minor
10+
"@codecov/vite-plugin": minor
11+
"@codecov/webpack-plugin": minor
12+
---
13+
14+
Add in debug logs for each param for each provider for better debugging.

examples/bundle-analyzer-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"type": "module",
2020
"scripts": {
21-
"build": "rollup -c && pnpm bundle-analyzer ./dist --bundle-name=@codecov/example-bundle-analyzer-cli --upload-token=$BUNDLE_ANALYZER_UPLOAD_TOKEN --config-file=./baconfig.json"
21+
"build": "rollup -c && pnpm bundle-analyzer ./dist -v --bundle-name=@codecov/example-bundle-analyzer-cli --upload-token=$BUNDLE_ANALYZER_UPLOAD_TOKEN --api-url=$BUNDLE_ANALYZER_API_URL --config-file=./baconfig.json"
2222
},
2323
"devDependencies": {
2424
"@codecov/bundle-analyzer": "workspace:^",

examples/bundle-analyzer-lib-cjs/analyze.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const coreOpts = {
66
dryRun: false,
77
uploadToken: process.env.BUNDLE_ANALYZER_UPLOAD_TOKEN,
88
retryCount: 3,
9-
apiUrl: "https://api.codecov.io",
9+
apiUrl: process.env.BUNDLE_ANALYZER_API_URL,
1010
bundleName: "@codecov/example-bundle-analyzer-cjs",
1111
enableBundleAnalysis: true,
1212
debug: true,

examples/bundle-analyzer-lib-esm/analyze.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const coreOpts: Options = {
1010
dryRun: false,
1111
uploadToken: process.env.BUNDLE_ANALYZER_UPLOAD_TOKEN,
1212
retryCount: 3,
13-
apiUrl: "https://api.codecov.io",
13+
apiUrl: process.env.BUNDLE_ANALYZER_API_URL,
1414
bundleName: "@codecov/example-bundle-analyzer-esm",
1515
enableBundleAnalysis: true,
1616
debug: true,

packages/bundler-plugin-core/src/utils/fetchWithRetry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const fetchWithRetry = async ({
2222
try {
2323
debug(`Attempting to fetch ${name}, attempt: ${i + 1}`);
2424
await delay(DEFAULT_RETRY_DELAY * i);
25+
2526
response = await fetch(url, requestData);
2627

2728
if (!response.ok) {
@@ -33,7 +34,7 @@ export const fetchWithRetry = async ({
3334
const isLastAttempt = i + 1 === retryCount;
3435

3536
if (isLastAttempt) {
36-
red(`${name} failed after ${i} attempts`);
37+
red(`${name} failed after ${i + 1} attempts`);
3738

3839
if (!(err instanceof BadResponseError)) {
3940
throw err;

packages/bundler-plugin-core/src/utils/getPreSignedURL.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ export const getPreSignedURL = async ({
9595

9696
let response: Response;
9797
try {
98+
const body = preProcessBody(requestBody);
9899
response = await fetchWithRetry({
99100
retryCount,
100101
url: `${apiUrl}${API_ENDPOINT}`,
101102
name: "`get-pre-signed-url`",
102103
requestData: {
103104
method: "POST",
104105
headers: headers,
105-
body: JSON.stringify(preProcessBody(requestBody)),
106+
body: JSON.stringify(body),
106107
},
107108
});
108109
} catch (e) {

packages/bundler-plugin-core/src/utils/providers/AppVeyorCI.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,87 @@ export function detect(envs: ProviderEnvs): boolean {
1313
);
1414
}
1515

16-
function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
16+
function _getBuild(
17+
inputs: ProviderUtilInputs,
18+
output: Output,
19+
): ProviderServiceParams["build"] {
1720
const { args, envs } = inputs;
1821
if (args?.build && args.build !== "") {
22+
debug(`Using build: ${args.build}`, { enabled: output.debug });
1923
return args.build;
2024
}
21-
return envs?.APPVEYOR_JOB_ID ?? null;
25+
26+
const build = envs?.APPVEYOR_BUILD_ID ?? null;
27+
debug(`Using build: ${build}`, { enabled: output.debug });
28+
29+
return build;
2230
}
2331

2432
function _getBuildURL(
2533
inputs: ProviderUtilInputs,
34+
output: Output,
2635
): ProviderServiceParams["buildURL"] {
2736
const { envs } = inputs;
37+
let buildUrl: string | null = null;
38+
2839
if (
2940
envs?.APPVEYOR_URL &&
3041
envs?.APPVEYOR_REPO_NAME &&
3142
envs?.APPVEYOR_BUILD_ID &&
3243
envs?.APPVEYOR_JOB_ID
3344
) {
34-
return `${envs?.APPVEYOR_URL}/project/${envs?.APPVEYOR_REPO_NAME}/builds/${envs?.APPVEYOR_BUILD_ID}/job/${envs?.APPVEYOR_JOB_ID}`;
45+
buildUrl = `${envs?.APPVEYOR_URL}/project/${envs?.APPVEYOR_REPO_NAME}/builds/${envs?.APPVEYOR_BUILD_ID}/job/${envs?.APPVEYOR_JOB_ID}`;
3546
}
36-
return null;
47+
48+
debug(`Using build URL: ${buildUrl}`, { enabled: output.debug });
49+
return buildUrl;
3750
}
3851

3952
function _getBranch(
4053
inputs: ProviderUtilInputs,
54+
output: Output,
4155
): ProviderServiceParams["branch"] {
4256
const { args, envs } = inputs;
4357
if (args?.branch && args.branch !== "") {
58+
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
4459
return args.branch;
4560
}
46-
return envs?.APPVEYOR_REPO_BRANCH ?? null;
61+
const branch = envs?.APPVEYOR_REPO_BRANCH ?? null;
62+
debug(`Using branch: ${branch}`, { enabled: output.debug });
63+
return branch;
4764
}
4865

49-
function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
66+
function _getJob(
67+
envs: ProviderEnvs,
68+
output: Output,
69+
): ProviderServiceParams["job"] {
70+
let job: string | null = null;
71+
5072
if (
5173
envs?.APPVEYOR_ACCOUNT_NAME &&
5274
envs?.APPVEYOR_PROJECT_SLUG &&
5375
envs?.APPVEYOR_BUILD_VERSION
5476
) {
55-
return `${envs?.APPVEYOR_ACCOUNT_NAME}/${envs?.APPVEYOR_PROJECT_SLUG}/${envs?.APPVEYOR_BUILD_VERSION}`;
77+
job = `${envs.APPVEYOR_ACCOUNT_NAME}/${envs.APPVEYOR_PROJECT_SLUG}/${envs.APPVEYOR_BUILD_VERSION}`;
5678
}
57-
return null;
79+
80+
debug(`Using job: ${job}`, { enabled: output.debug });
81+
return job;
5882
}
5983

60-
function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
84+
function _getPR(
85+
inputs: ProviderUtilInputs,
86+
output: Output,
87+
): ProviderServiceParams["pr"] {
6188
const { args, envs } = inputs;
6289
if (args?.pr && args.pr !== "") {
90+
debug(`Using PR number: ${args.pr}`, { enabled: output.debug });
6391
return args.pr;
6492
}
65-
return envs?.APPVEYOR_PULL_REQUEST_NUMBER ?? null;
93+
94+
const pr = envs?.APPVEYOR_PULL_REQUEST_NUMBER ?? null;
95+
debug(`Using PR number: ${pr}`, { enabled: output.debug });
96+
return pr;
6697
}
6798

6899
function _getService(): ProviderServiceParams["service"] {
@@ -86,19 +117,24 @@ function _getSHA(
86117
const commitSha =
87118
envs?.APPVEYOR_PULL_REQUEST_HEAD_COMMIT ?? envs?.APPVEYOR_REPO_COMMIT;
88119

89-
debug(`Using commit: ${commitSha ?? ""}`, {
90-
enabled: output.debug,
91-
});
120+
debug(`Using commit: ${commitSha}`, { enabled: output.debug });
92121

93122
return commitSha ?? null;
94123
}
95124

96-
function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
125+
function _getSlug(
126+
inputs: ProviderUtilInputs,
127+
output: Output,
128+
): ProviderServiceParams["slug"] {
97129
const { args, envs } = inputs;
98130
if (args?.slug && args.slug !== "") {
131+
debug(`Using slug: ${args.slug}`, { enabled: output.debug });
99132
return args.slug;
100133
}
101-
return envs?.APPVEYOR_REPO_NAME ?? null;
134+
135+
const slug = envs?.APPVEYOR_REPO_NAME ?? null;
136+
debug(`Using slug: ${slug}`, { enabled: output.debug });
137+
return slug;
102138
}
103139

104140
// eslint-disable-next-line @typescript-eslint/require-await
@@ -107,14 +143,14 @@ export async function getServiceParams(
107143
output: Output,
108144
): Promise<ProviderServiceParams> {
109145
return {
110-
branch: _getBranch(inputs),
111-
build: _getBuild(inputs),
112-
buildURL: _getBuildURL(inputs),
146+
branch: _getBranch(inputs, output),
147+
build: _getBuild(inputs, output),
148+
buildURL: _getBuildURL(inputs, output),
113149
commit: _getSHA(inputs, output),
114-
job: _getJob(inputs.envs),
115-
pr: _getPR(inputs),
150+
job: _getJob(inputs.envs, output),
151+
pr: _getPR(inputs, output),
116152
service: _getService(),
117-
slug: _getSlug(inputs),
153+
slug: _getSlug(inputs, output),
118154
};
119155
}
120156

packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,78 @@ export function detect(envs: ProviderEnvs): boolean {
1212
return Boolean(envs?.SYSTEM_TEAMFOUNDATIONSERVERURI);
1313
}
1414

15-
function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
15+
function _getBuild(
16+
inputs: ProviderUtilInputs,
17+
output: Output,
18+
): ProviderServiceParams["build"] {
1619
const { args, envs } = inputs;
1720
if (args?.build && args.build !== "") {
21+
debug(`Using build: ${args.build}`, { enabled: output.debug });
1822
return args.build;
1923
}
20-
return envs?.BUILD_BUILDNUMBER ?? null;
24+
25+
const build = envs?.BUILD_BUILDNUMBER ?? null;
26+
debug(`Using build: ${build}`, { enabled: output.debug });
27+
return build;
2128
}
2229

2330
function _getBuildURL(
2431
inputs: ProviderUtilInputs,
32+
output: Output,
2533
): ProviderServiceParams["buildURL"] {
2634
const { envs } = inputs;
35+
let buildURL: string | null = null;
2736
if (envs?.SYSTEM_TEAMPROJECT && envs?.BUILD_BUILDID) {
28-
return `${envs?.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs?.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs?.BUILD_BUILDID}`;
37+
buildURL = `${envs?.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs?.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs?.BUILD_BUILDID}`;
2938
}
30-
return null;
39+
debug(`Using build URL: ${buildURL}`, { enabled: output.debug });
40+
return buildURL;
3141
}
3242

3343
function _getBranch(
3444
inputs: ProviderUtilInputs,
45+
output: Output,
3546
): ProviderServiceParams["branch"] {
3647
const { args, envs } = inputs;
3748
if (args?.branch && args.branch !== "") {
49+
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
3850
return args.branch;
3951
}
4052

53+
let branch: string | null = null;
4154
if (envs?.BUILD_SOURCEBRANCH) {
42-
return envs?.BUILD_SOURCEBRANCH.toString().replace("refs/heads/", "");
55+
branch = envs?.BUILD_SOURCEBRANCH.toString().replace("refs/heads/", "");
4356
}
4457

45-
return null;
58+
debug(`Using branch: ${branch}`, { enabled: output.debug });
59+
return branch;
4660
}
4761

48-
function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
49-
return envs?.BUILD_BUILDID ?? null;
62+
function _getJob(
63+
envs: ProviderEnvs,
64+
output: Output,
65+
): ProviderServiceParams["job"] {
66+
const job = envs?.BUILD_BUILDID ?? null;
67+
debug(`Using job: ${job}`, { enabled: output.debug });
68+
return job;
5069
}
5170

52-
function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
71+
function _getPR(
72+
inputs: ProviderUtilInputs,
73+
output: Output,
74+
): ProviderServiceParams["pr"] {
5375
const { args, envs } = inputs;
5476
if (args?.pr && args.pr !== "") {
77+
debug(`Using PR: ${args.pr}`, { enabled: output.debug });
5578
return args.pr;
5679
}
5780

58-
return (
81+
const pr =
5982
envs?.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER ??
6083
envs?.SYSTEM_PULLREQUEST_PULLREQUESTID ??
61-
null
62-
);
84+
null;
85+
debug(`Using PR: ${pr}`, { enabled: output.debug });
86+
return pr;
6387
}
6488

6589
function _getService(): ProviderServiceParams["service"] {
@@ -84,7 +108,7 @@ function _getSHA(
84108

85109
let commit = envs?.BUILD_SOURCEVERSION ?? null;
86110

87-
if (_getPR(inputs)) {
111+
if (_getPR(inputs, output)) {
88112
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
89113
const mergeCommitMessage = childProcess
90114
.execFileSync("git", ["show", "--no-patch", "--format=%P"])
@@ -105,20 +129,24 @@ function _getSHA(
105129
}
106130
}
107131

108-
debug(`Using commit: ${commit}`, {
109-
enabled: output.debug,
110-
});
111-
132+
debug(`Using commit: ${commit}`, { enabled: output.debug });
112133
return commit;
113134
}
114135

115-
function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
136+
function _getSlug(
137+
inputs: ProviderUtilInputs,
138+
output: Output,
139+
): ProviderServiceParams["slug"] {
116140
const { args, envs } = inputs;
117141
if (args?.slug && args.slug !== "") {
142+
debug(`Using slug: ${args.slug}`, { enabled: output.debug });
118143
return args.slug;
119144
}
120145

121-
return envs?.BUILD_REPOSITORY_NAME ?? parseSlugFromRemoteAddr("") ?? null;
146+
const slug =
147+
envs?.BUILD_REPOSITORY_NAME ?? parseSlugFromRemoteAddr("") ?? null;
148+
debug(`Using slug: ${slug}`, { enabled: output.debug });
149+
return slug;
122150
}
123151

124152
// eslint-disable-next-line @typescript-eslint/require-await
@@ -127,14 +155,14 @@ export async function getServiceParams(
127155
output: Output,
128156
): Promise<ProviderServiceParams> {
129157
return {
130-
branch: _getBranch(inputs),
131-
build: _getBuild(inputs),
132-
buildURL: _getBuildURL(inputs),
158+
branch: _getBranch(inputs, output),
159+
build: _getBuild(inputs, output),
160+
buildURL: _getBuildURL(inputs, output),
133161
commit: _getSHA(inputs, output),
134-
job: _getJob(inputs.envs),
135-
pr: _getPR(inputs),
162+
job: _getJob(inputs.envs, output),
163+
pr: _getPR(inputs, output),
136164
service: _getService(),
137-
slug: _getSlug(inputs),
165+
slug: _getSlug(inputs, output),
138166
};
139167
}
140168

0 commit comments

Comments
 (0)