Skip to content

Commit bbecd16

Browse files
committed
refactor: format warning message
1 parent d7f4b66 commit bbecd16

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

src/cli/commands/start.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ export async function start(startContext: string, options: SWACLIConfig) {
8686
userWorkflowConfig,
8787
});
8888
} catch (err) {
89-
logger.warn(`Error reading workflow configuration:`);
90-
logger.warn((err as any).message);
91-
logger.warn(``);
89+
logger.warn(``, "swa");
90+
logger.warn(`Error reading workflow configuration:`, "swa");
91+
logger.warn((err as any).message, "swa");
9292
logger.warn(
93-
`See https://docs.microsoft.com/azure/static-web-apps/build-configuration?tabs=github-actions#build-configuration for more information.`
93+
`See https://docs.microsoft.com/azure/static-web-apps/build-configuration?tabs=github-actions#build-configuration for more information.`,
94+
"swa"
9495
);
9596
}
9697

src/core/utils/workflow-config.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ describe("readWorkflowFile()", () => {
2929
});
3030

3131
describe("checking workflow properties", () => {
32-
it("missing property 'jobs' should throw", () => {
32+
it(`missing property "jobs" should throw`, () => {
3333
mockFs({
3434
".github/workflows/azure-static-web-apps__not-valid.yml": `name: Azure Static Web Apps CI/CD`,
3535
});
3636

37-
expect(() => readWorkflowFile()).toThrow(/missing property 'jobs'/);
37+
expect(() => readWorkflowFile()).toThrow(/missing property "jobs"/);
3838
});
3939

40-
it("missing property 'jobs.build_and_deploy_job' should throw", () => {
40+
it(`missing property "jobs.build_and_deploy_job" should throw`, () => {
4141
mockFs({
4242
".github/workflows/azure-static-web-apps.yml": `
4343
jobs:
4444
invalid_property:
4545
`,
4646
});
47-
expect(() => readWorkflowFile()).toThrow(/missing property 'jobs.build_and_deploy_job'/);
47+
expect(() => readWorkflowFile()).toThrow(/missing property "jobs.build_and_deploy_job"/);
4848
});
4949

50-
it("missing property 'jobs.build_and_deploy_job.steps' should throw", () => {
50+
it(`missing property "jobs.build_and_deploy_job.steps" should throw`, () => {
5151
mockFs({
5252
".github/workflows/azure-static-web-apps.yml": `
5353
jobs:
@@ -56,21 +56,21 @@ jobs:
5656
`,
5757
});
5858

59-
expect(() => readWorkflowFile()).toThrow(/missing property 'jobs.build_and_deploy_job.steps'/);
59+
expect(() => readWorkflowFile()).toThrow(/missing property "jobs.build_and_deploy_job.steps"/);
6060
});
6161

62-
it("invalid property 'jobs.build_and_deploy_job.steps' should throw", () => {
62+
it(`invalid property"jobs.build_and_deploy_job.steps" should throw`, () => {
6363
mockFs({
6464
".github/workflows/azure-static-web-apps.yml": `
6565
jobs:
6666
build_and_deploy_job:
6767
steps:
6868
`,
6969
});
70-
expect(() => readWorkflowFile()).toThrow(/missing property 'jobs.build_and_deploy_job.steps'/);
70+
expect(() => readWorkflowFile()).toThrow(/missing property "jobs.build_and_deploy_job.steps"/);
7171
});
7272

73-
it("invalid property 'jobs.build_and_deploy_job.steps[]' should throw", () => {
73+
it(`invalid property "jobs.build_and_deploy_job.steps[]" should throw`, () => {
7474
mockFs({
7575
".github/workflows/azure-static-web-apps.yml": `
7676
jobs:
@@ -80,10 +80,10 @@ jobs:
8080
`,
8181
});
8282

83-
expect(() => readWorkflowFile()).toThrow(/invalid property 'jobs.build_and_deploy_job.steps\[\]'/);
83+
expect(() => readWorkflowFile()).toThrow(/invalid property "jobs.build_and_deploy_job.steps\[\]"/);
8484
});
8585

86-
it("missing property 'jobs.build_and_deploy_job.steps[].with' should throw", () => {
86+
it(`missing property "jobs.build_and_deploy_job.steps[].with" should throw`, () => {
8787
mockFs({
8888
".github/workflows/azure-static-web-apps.yml": `
8989
jobs:
@@ -94,7 +94,7 @@ jobs:
9494
`,
9595
});
9696

97-
expect(() => readWorkflowFile()).toThrow(/missing property 'jobs.build_and_deploy_job.steps\[\].with'/);
97+
expect(() => readWorkflowFile()).toThrow(/missing property "jobs.build_and_deploy_job.steps\[\].with"/);
9898
});
9999
});
100100

src/core/utils/workflow-config.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,30 @@ export function readWorkflowFile({ userWorkflowConfig }: { userWorkflowConfig?:
6060
const swaYaml = YAML.parse(githubActionContent);
6161

6262
if (!swaYaml) {
63-
throw Error(`could not parse the SWA workflow file "${githubActionFile}". Make sure it's a valid YAML file`);
63+
throw Error(`could not parse the SWA workflow file "${githubActionFile}".`);
6464
}
6565

6666
if (!swaYaml.jobs) {
67-
throw Error(`missing property 'jobs' in the SWA workflow file "${githubActionFile}". Make sure it's a valid SWA workflow file`);
67+
throw Error(`missing property "jobs" in the SWA workflow file "${githubActionFile}".`);
6868
}
6969

7070
if (!swaYaml.jobs.build_and_deploy_job) {
71-
throw Error(
72-
`missing property 'jobs.build_and_deploy_job' in the SWA workflow file "${githubActionFile}". Make sure it's a valid SWA workflow file.`
73-
);
71+
throw Error(`missing property "jobs.build_and_deploy_job" in the SWA workflow file "${githubActionFile}".`);
7472
}
7573

7674
if (!swaYaml.jobs.build_and_deploy_job.steps) {
77-
throw Error(
78-
`missing property 'jobs.build_and_deploy_job.steps' in the SWA workflow file "${githubActionFile}". Make sure it's a valid SWA workflow file.`
79-
);
75+
throw Error(`missing property "jobs.build_and_deploy_job.steps" in the SWA workflow file "${githubActionFile}".`);
8076
}
8177

8278
// hacking this to have an `any` on the type in .find, mainly because a typescript definition for the YAML file is painful...
8379
const swaBuildConfig = swaYaml.jobs.build_and_deploy_job.steps.find((step: any) => step.uses && step.uses.includes("static-web-apps-deploy"));
8480

8581
if (!swaBuildConfig) {
86-
throw Error(
87-
`invalid property 'jobs.build_and_deploy_job.steps[]' in the SWA workflow file "${githubActionFile}". Make sure it's a valid SWA workflow file.`
88-
);
82+
throw Error(`invalid property "jobs.build_and_deploy_job.steps[]" in the SWA workflow file "${githubActionFile}".`);
8983
}
9084

9185
if (!swaBuildConfig.with) {
92-
throw Error(
93-
`missing property 'jobs.build_and_deploy_job.steps[].with' in the SWA workflow file "${githubActionFile}". Make sure it's a valid SWA workflow file.`
94-
);
86+
throw Error(`missing property "jobs.build_and_deploy_job.steps[].with" in the SWA workflow file "${githubActionFile}".`);
9587
}
9688

9789
// extract the user's config and set defaults

0 commit comments

Comments
 (0)