Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/serious-olives-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@codecov/bundler-plugin-core": minor
"@codecov/bundle-analyzer": minor
"@codecov/nextjs-webpack-plugin": minor
"@codecov/nuxt-plugin": minor
"@codecov/remix-vite-plugin": minor
"@codecov/rollup-plugin": minor
"@codecov/solidstart-plugin": minor
"@codecov/sveltekit-plugin": minor
"@codecov/vite-plugin": minor
"@codecov/webpack-plugin": minor
---

Add in debug logs for each param for each provider for better debugging.
78 changes: 57 additions & 21 deletions packages/bundler-plugin-core/src/utils/providers/AppVeyorCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,87 @@ export function detect(envs: ProviderEnvs): boolean {
);
}

function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
function _getBuild(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["build"] {
const { args, envs } = inputs;
if (args?.build && args.build !== "") {
debug(`Using build: ${args.build}`, { enabled: output.debug });
return args.build;
}
return envs?.APPVEYOR_JOB_ID ?? null;

const build = envs?.APPVEYOR_BUILD_ID ?? null;
debug(`Using build: ${build}`, { enabled: output.debug });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not needed right now but devs that are debugging may find it helpful in the future if we log the source as well (as in from args or env).


return build;
}

function _getBuildURL(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["buildURL"] {
const { envs } = inputs;
let buildUrl: string | null = null;

if (
envs?.APPVEYOR_URL &&
envs?.APPVEYOR_REPO_NAME &&
envs?.APPVEYOR_BUILD_ID &&
envs?.APPVEYOR_JOB_ID
) {
return `${envs?.APPVEYOR_URL}/project/${envs?.APPVEYOR_REPO_NAME}/builds/${envs?.APPVEYOR_BUILD_ID}/job/${envs?.APPVEYOR_JOB_ID}`;
buildUrl = `${envs?.APPVEYOR_URL}/project/${envs?.APPVEYOR_REPO_NAME}/builds/${envs?.APPVEYOR_BUILD_ID}/job/${envs?.APPVEYOR_JOB_ID}`;
}
return null;

debug(`Using build URL: ${buildUrl}`, { enabled: output.debug });
return buildUrl;
}

function _getBranch(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["branch"] {
const { args, envs } = inputs;
if (args?.branch && args.branch !== "") {
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
return args.branch;
}
return envs?.APPVEYOR_REPO_BRANCH ?? null;
const branch = envs?.APPVEYOR_REPO_BRANCH ?? null;
debug(`Using branch: ${branch}`, { enabled: output.debug });
return branch;
}

function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
function _getJob(
envs: ProviderEnvs,
output: Output,
): ProviderServiceParams["job"] {
let job: string | null = null;

if (
envs?.APPVEYOR_ACCOUNT_NAME &&
envs?.APPVEYOR_PROJECT_SLUG &&
envs?.APPVEYOR_BUILD_VERSION
) {
return `${envs?.APPVEYOR_ACCOUNT_NAME}/${envs?.APPVEYOR_PROJECT_SLUG}/${envs?.APPVEYOR_BUILD_VERSION}`;
job = `${envs.APPVEYOR_ACCOUNT_NAME}/${envs.APPVEYOR_PROJECT_SLUG}/${envs.APPVEYOR_BUILD_VERSION}`;
}
return null;

debug(`Using job: ${job}`, { enabled: output.debug });
return job;
}

function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
function _getPR(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["pr"] {
const { args, envs } = inputs;
if (args?.pr && args.pr !== "") {
debug(`Using PR number: ${args.pr}`, { enabled: output.debug });
return args.pr;
}
return envs?.APPVEYOR_PULL_REQUEST_NUMBER ?? null;

const pr = envs?.APPVEYOR_PULL_REQUEST_NUMBER ?? null;
debug(`Using PR number: ${pr}`, { enabled: output.debug });
return pr;
}

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

debug(`Using commit: ${commitSha ?? ""}`, {
enabled: output.debug,
});
debug(`Using commit: ${commitSha}`, { enabled: output.debug });

return commitSha ?? null;
}

function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
function _getSlug(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["slug"] {
const { args, envs } = inputs;
if (args?.slug && args.slug !== "") {
debug(`Using slug: ${args.slug}`, { enabled: output.debug });
return args.slug;
}
return envs?.APPVEYOR_REPO_NAME ?? null;

const slug = envs?.APPVEYOR_REPO_NAME ?? null;
debug(`Using slug: ${slug}`, { enabled: output.debug });
return slug;
}

// eslint-disable-next-line @typescript-eslint/require-await
Expand All @@ -107,14 +143,14 @@ export async function getServiceParams(
output: Output,
): Promise<ProviderServiceParams> {
return {
branch: _getBranch(inputs),
build: _getBuild(inputs),
buildURL: _getBuildURL(inputs),
branch: _getBranch(inputs, output),
Copy link
Contributor

@suejung-sentry suejung-sentry Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally found the arg name output a bit confusing since if that is passed as an arg I'd wonder if that's something passed by reference expecting to get mutated.

Fine to leave as is since the pattern is already well-established across the rest of the code, just a passing musing

build: _getBuild(inputs, output),
buildURL: _getBuildURL(inputs, output),
commit: _getSHA(inputs, output),
job: _getJob(inputs.envs),
pr: _getPR(inputs),
job: _getJob(inputs.envs, output),
pr: _getPR(inputs, output),
service: _getService(),
slug: _getSlug(inputs),
slug: _getSlug(inputs, output),
};
}

Expand Down
78 changes: 53 additions & 25 deletions packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,78 @@ export function detect(envs: ProviderEnvs): boolean {
return Boolean(envs?.SYSTEM_TEAMFOUNDATIONSERVERURI);
}

function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
function _getBuild(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["build"] {
const { args, envs } = inputs;
if (args?.build && args.build !== "") {
debug(`Using build: ${args.build}`, { enabled: output.debug });
return args.build;
}
return envs?.BUILD_BUILDNUMBER ?? null;

const build = envs?.BUILD_BUILDNUMBER ?? null;
debug(`Using build: ${build}`, { enabled: output.debug });
return build;
}

function _getBuildURL(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["buildURL"] {
const { envs } = inputs;
let buildURL: string | null = null;
if (envs?.SYSTEM_TEAMPROJECT && envs?.BUILD_BUILDID) {
return `${envs?.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs?.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs?.BUILD_BUILDID}`;
buildURL = `${envs?.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs?.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs?.BUILD_BUILDID}`;
}
return null;
debug(`Using build URL: ${buildURL}`, { enabled: output.debug });
return buildURL;
}

function _getBranch(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["branch"] {
const { args, envs } = inputs;
if (args?.branch && args.branch !== "") {
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
return args.branch;
}

let branch: string | null = null;
if (envs?.BUILD_SOURCEBRANCH) {
return envs?.BUILD_SOURCEBRANCH.toString().replace("refs/heads/", "");
branch = envs?.BUILD_SOURCEBRANCH.toString().replace("refs/heads/", "");
}

return null;
debug(`Using branch: ${branch}`, { enabled: output.debug });
return branch;
}

function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
return envs?.BUILD_BUILDID ?? null;
function _getJob(
envs: ProviderEnvs,
output: Output,
): ProviderServiceParams["job"] {
const job = envs?.BUILD_BUILDID ?? null;
debug(`Using job: ${job}`, { enabled: output.debug });
return job;
}

function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
function _getPR(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["pr"] {
const { args, envs } = inputs;
if (args?.pr && args.pr !== "") {
debug(`Using PR: ${args.pr}`, { enabled: output.debug });
return args.pr;
}

return (
const pr =
envs?.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER ??
envs?.SYSTEM_PULLREQUEST_PULLREQUESTID ??
null
);
null;
debug(`Using PR: ${pr}`, { enabled: output.debug });
return pr;
}

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

let commit = envs?.BUILD_SOURCEVERSION ?? null;

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

debug(`Using commit: ${commit}`, {
enabled: output.debug,
});

debug(`Using commit: ${commit}`, { enabled: output.debug });
return commit;
}

function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
function _getSlug(
inputs: ProviderUtilInputs,
output: Output,
): ProviderServiceParams["slug"] {
const { args, envs } = inputs;
if (args?.slug && args.slug !== "") {
debug(`Using slug: ${args.slug}`, { enabled: output.debug });
return args.slug;
}

return envs?.BUILD_REPOSITORY_NAME ?? parseSlugFromRemoteAddr("") ?? null;
const slug =
envs?.BUILD_REPOSITORY_NAME ?? parseSlugFromRemoteAddr("") ?? null;
debug(`Using slug: ${slug}`, { enabled: output.debug });
return slug;
}

// eslint-disable-next-line @typescript-eslint/require-await
Expand All @@ -127,14 +155,14 @@ export async function getServiceParams(
output: Output,
): Promise<ProviderServiceParams> {
return {
branch: _getBranch(inputs),
build: _getBuild(inputs),
buildURL: _getBuildURL(inputs),
branch: _getBranch(inputs, output),
build: _getBuild(inputs, output),
buildURL: _getBuildURL(inputs, output),
commit: _getSHA(inputs, output),
job: _getJob(inputs.envs),
pr: _getPR(inputs),
job: _getJob(inputs.envs, output),
pr: _getPR(inputs, output),
service: _getService(),
slug: _getSlug(inputs),
slug: _getSlug(inputs, output),
};
}

Expand Down
Loading
Loading