Skip to content

Commit 0a49d45

Browse files
committed
add logs to everything
1 parent 42079f4 commit 0a49d45

File tree

18 files changed

+755
-278
lines changed

18 files changed

+755
-278
lines changed

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

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ export function detect(envs: ProviderEnvs): boolean {
1111
return Boolean(envs?.CI) && Boolean(envs?.CIRCLECI);
1212
}
1313

14-
function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
14+
function _getBuild(
15+
inputs: ProviderUtilInputs,
16+
output: Output,
17+
): ProviderServiceParams["build"] {
1518
const { args, envs } = inputs;
1619
if (args?.build && args.build !== "") {
20+
debug(`Using build: ${args.build}`, { enabled: output.debug });
1721
return args.build;
1822
}
1923

20-
return envs?.CIRCLE_BUILD_NUM ?? null;
24+
const build = envs?.CIRCLE_BUILD_NUM ?? null;
25+
debug(`Using build: ${build}`, { enabled: output.debug });
26+
return build;
2127
}
2228

2329
function _getBuildURL(
2430
inputs: ProviderUtilInputs,
31+
output: Output,
2532
): ProviderServiceParams["buildURL"] {
26-
return inputs.envs?.CIRCLE_BUILD_URL ?? null;
33+
const buildURL = inputs.envs?.CIRCLE_BUILD_URL ?? null;
34+
debug(`Using buildURL: ${buildURL}`, { enabled: output.debug });
35+
return buildURL;
2736
}
2837

2938
// This is the value that gets passed to the Codecov uploader
@@ -38,13 +47,16 @@ export function getServiceName(): string {
3847

3948
function _getBranch(
4049
inputs: ProviderUtilInputs,
50+
output: Output,
4151
): ProviderServiceParams["branch"] {
4252
const { args, envs } = inputs;
4353
if (args?.branch && args.branch !== "") {
54+
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
4455
return args.branch;
4556
}
46-
47-
return envs?.CIRCLE_BRANCH ?? null;
57+
const branch = envs?.CIRCLE_BRANCH ?? null;
58+
debug(`Using branch: ${branch}`, { enabled: output.debug });
59+
return branch;
4860
}
4961

5062
function _getSHA(
@@ -61,31 +73,46 @@ function _getSHA(
6173
return envs?.CIRCLE_SHA1 ?? null;
6274
}
6375

64-
function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
76+
function _getSlug(
77+
inputs: ProviderUtilInputs,
78+
output: Output,
79+
): ProviderServiceParams["slug"] {
6580
const { args, envs } = inputs;
66-
const slug = setSlug(
81+
let slug = setSlug(
6782
args?.slug,
6883
envs?.CIRCLE_PROJECT_USERNAME,
6984
envs?.CIRCLE_PROJECT_REPONAME,
7085
);
7186

7287
if (envs?.CIRCLE_REPOSITORY_URL && envs?.CIRCLE_REPOSITORY_URL !== "") {
73-
return `${envs?.CIRCLE_REPOSITORY_URL?.split(":")[1]?.split(".git")[0]}`;
88+
slug = `${envs?.CIRCLE_REPOSITORY_URL?.split(":")[1]?.split(".git")[0]}`;
7489
}
90+
debug(`Using slug: ${slug}`, { enabled: output.debug });
7591
return slug;
7692
}
7793

78-
function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
94+
function _getPR(
95+
inputs: ProviderUtilInputs,
96+
output: Output,
97+
): ProviderServiceParams["pr"] {
7998
const { args, envs } = inputs;
8099
if (args?.pr && args.pr !== "") {
100+
debug(`Using pr: ${args.pr}`, { enabled: output.debug });
81101
return args.pr;
82102
}
83103

84-
return envs?.CIRCLE_PR_NUMBER ?? null;
104+
const pr = envs?.CIRCLE_PR_NUMBER ?? null;
105+
debug(`Using pr: ${pr}`, { enabled: output.debug });
106+
return pr;
85107
}
86108

87-
function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
88-
return envs?.CIRCLE_NODE_INDEX ?? null;
109+
function _getJob(
110+
envs: ProviderEnvs,
111+
output: Output,
112+
): ProviderServiceParams["job"] {
113+
const job = envs?.CIRCLE_NODE_INDEX ?? null;
114+
debug(`Using job: ${job}`, { enabled: output.debug });
115+
return job;
89116
}
90117

91118
// eslint-disable-next-line @typescript-eslint/require-await
@@ -94,14 +121,14 @@ export async function getServiceParams(
94121
output: Output,
95122
): Promise<ProviderServiceParams> {
96123
return {
97-
branch: _getBranch(inputs),
98-
build: _getBuild(inputs),
99-
buildURL: _getBuildURL(inputs),
124+
branch: _getBranch(inputs, output),
125+
build: _getBuild(inputs, output),
126+
buildURL: _getBuildURL(inputs, output),
100127
commit: _getSHA(inputs, output),
101-
job: _getJob(inputs.envs),
102-
pr: _getPR(inputs),
128+
job: _getJob(inputs.envs, output),
129+
pr: _getPR(inputs, output),
103130
service: _getService(),
104-
slug: _getSlug(inputs),
131+
slug: _getSlug(inputs, output),
105132
};
106133
}
107134

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,55 @@ export function detect(envs: ProviderEnvs): boolean {
1111
return Boolean(envs?.CIRRUS_CI);
1212
}
1313

14-
function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
14+
function _getBuild(
15+
inputs: ProviderUtilInputs,
16+
output: Output,
17+
): ProviderServiceParams["build"] {
1518
const { args, envs } = inputs;
1619
if (args?.build && args.build !== "") {
20+
debug(`Using build: ${args.build}`, { enabled: output.debug });
1721
return args.build;
1822
}
19-
return envs?.CIRRUS_BUILD_ID ?? null;
23+
const build = envs?.CIRRUS_BUILD_ID ?? null;
24+
debug(`Using build: ${build}`, { enabled: output.debug });
25+
return build;
2026
}
2127

22-
function _getBuildURL(): ProviderServiceParams["buildURL"] {
28+
function _getBuildURL(output: Output): ProviderServiceParams["buildURL"] {
29+
debug(`Using buildURL: ${null}`, { enabled: output.debug });
2330
return null;
2431
}
2532

2633
function _getBranch(
2734
inputs: ProviderUtilInputs,
35+
output: Output,
2836
): ProviderServiceParams["branch"] {
2937
const { args, envs } = inputs;
3038
if (args?.branch && args.branch !== "") {
39+
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
3140
return args.branch;
3241
}
33-
return envs?.CIRRUS_BRANCH ?? null;
42+
const branch = envs?.CIRRUS_BRANCH ?? null;
43+
debug(`Using branch: ${branch}`, { enabled: output.debug });
44+
return branch;
3445
}
3546

3647
function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
3748
return envs?.CIRRUS_TASK_ID ?? null;
3849
}
3950

40-
function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
51+
function _getPR(
52+
inputs: ProviderUtilInputs,
53+
output: Output,
54+
): ProviderServiceParams["pr"] {
4155
const { args, envs } = inputs;
4256
if (args?.pr && args.pr !== "") {
57+
debug(`Using pr: ${args.pr}`, { enabled: output.debug });
4358
return args.pr;
4459
}
45-
return envs?.CIRRUS_PR ?? null;
60+
const pr = envs?.CIRRUS_PR ?? null;
61+
debug(`Using pr: ${pr}`, { enabled: output.debug });
62+
return pr;
4663
}
4764

4865
function _getService(): ProviderServiceParams["service"] {
@@ -67,9 +84,18 @@ function _getSHA(
6784
return sha;
6885
}
6986

70-
function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
87+
function _getSlug(
88+
inputs: ProviderUtilInputs,
89+
output: Output,
90+
): ProviderServiceParams["slug"] {
7191
const { args, envs } = inputs;
72-
return setSlug(args?.slug, envs?.CIRRUS_REPO_OWNER, envs?.CIRRUS_REPO_NAME);
92+
const slug = setSlug(
93+
args?.slug,
94+
envs?.CIRRUS_REPO_OWNER,
95+
envs?.CIRRUS_REPO_NAME,
96+
);
97+
debug(`Using slug: ${slug}`, { enabled: output.debug });
98+
return slug;
7399
}
74100

75101
// eslint-disable-next-line @typescript-eslint/require-await
@@ -78,14 +104,14 @@ export async function getServiceParams(
78104
output: Output,
79105
): Promise<ProviderServiceParams> {
80106
return {
81-
branch: _getBranch(inputs),
82-
build: _getBuild(inputs),
83-
buildURL: _getBuildURL(),
107+
branch: _getBranch(inputs, output),
108+
build: _getBuild(inputs, output),
109+
buildURL: _getBuildURL(output),
84110
commit: _getSHA(inputs, output),
85111
job: _getJob(inputs.envs),
86-
pr: _getPR(inputs),
112+
pr: _getPR(inputs, output),
87113
service: _getService(),
88-
slug: _getSlug(inputs),
114+
slug: _getSlug(inputs, output),
89115
};
90116
}
91117

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

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,54 @@ export function detect(envs: ProviderEnvs): boolean {
1010
return Boolean(envs?.CF_PAGES);
1111
}
1212

13-
function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
13+
function _getBuild(
14+
inputs: ProviderUtilInputs,
15+
output: Output,
16+
): ProviderServiceParams["build"] {
1417
const { args } = inputs;
15-
return args?.build ?? null;
18+
if (args?.build && args.build !== "") {
19+
debug(`Using build: ${args.build}`, { enabled: output.debug });
20+
return args.build;
21+
}
22+
debug(`Using build: ${null}`, { enabled: output.debug });
23+
return null;
1624
}
1725

18-
function _getBuildURL() {
26+
function _getBuildURL(output: Output): ProviderServiceParams["buildURL"] {
27+
debug(`Using buildURL: ${null}`, { enabled: output.debug });
1928
return null;
2029
}
2130

2231
function _getBranch(
2332
inputs: ProviderUtilInputs,
33+
output: Output,
2434
): ProviderServiceParams["branch"] {
2535
const { args, envs } = inputs;
2636
if (args?.branch && args.branch !== "") {
37+
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
2738
return args.branch;
2839
}
29-
return envs?.CF_PAGES_BRANCH ?? null;
40+
41+
const branch = envs?.CF_PAGES_BRANCH ?? null;
42+
debug(`Using branch: ${branch}`, { enabled: output.debug });
43+
return branch;
3044
}
3145

32-
function _getJob(): ProviderServiceParams["job"] {
46+
function _getJob(output: Output): ProviderServiceParams["job"] {
47+
debug(`Using job: ${null}`, { enabled: output.debug });
3348
return null;
3449
}
3550

36-
function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
51+
function _getPR(
52+
inputs: ProviderUtilInputs,
53+
output: Output,
54+
): ProviderServiceParams["pr"] {
3755
const { args } = inputs;
38-
return args?.pr ?? null;
56+
if (args?.pr && args.pr !== "") {
57+
debug(`Using pr: ${args.pr}`, { enabled: output.debug });
58+
return args.pr;
59+
}
60+
return null;
3961
}
4062

4163
function _getService(): ProviderServiceParams["service"] {
@@ -62,9 +84,17 @@ function _getSHA(
6284
return envs?.CF_PAGES_COMMIT_SHA ?? null;
6385
}
6486

65-
function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
87+
function _getSlug(
88+
inputs: ProviderUtilInputs,
89+
output: Output,
90+
): ProviderServiceParams["slug"] {
6691
const { args } = inputs;
67-
return args?.slug ?? null;
92+
if (args?.slug && args.slug !== "") {
93+
debug(`Using slug: ${args.slug}`, { enabled: output.debug });
94+
return args.slug;
95+
}
96+
debug(`Using slug: ${null}`, { enabled: output.debug });
97+
return null;
6898
}
6999

70100
// eslint-disable-next-line @typescript-eslint/require-await
@@ -73,14 +103,14 @@ export async function getServiceParams(
73103
output: Output,
74104
): Promise<ProviderServiceParams> {
75105
return {
76-
branch: _getBranch(inputs),
77-
build: _getBuild(inputs),
78-
buildURL: _getBuildURL(),
106+
branch: _getBranch(inputs, output),
107+
build: _getBuild(inputs, output),
108+
buildURL: _getBuildURL(output),
79109
commit: _getSHA(inputs, output),
80-
job: _getJob(),
81-
pr: _getPR(inputs),
110+
job: _getJob(output),
111+
pr: _getPR(inputs, output),
82112
service: _getService(),
83-
slug: _getSlug(inputs),
113+
slug: _getSlug(inputs, output),
84114
};
85115
}
86116

0 commit comments

Comments
 (0)