Skip to content

Commit 59d67fc

Browse files
committed
Fix parsing of GHES pre-release versions
1 parent f53ec7c commit 59d67fc

File tree

9 files changed

+70
-11
lines changed

9 files changed

+70
-11
lines changed

lib/upload-lib.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.test.js

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,18 @@ test("shouldShowCombineSarifFilesDeprecationWarning when on GHES 3.14", async (t
399399
);
400400
});
401401

402+
test("shouldShowCombineSarifFilesDeprecationWarning when on GHES 3.16 pre", async (t) => {
403+
t.true(
404+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
405+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
406+
{
407+
type: GitHubVariant.GHES,
408+
version: "3.16.0.pre1",
409+
},
410+
),
411+
);
412+
});
413+
402414
test("shouldShowCombineSarifFilesDeprecationWarning with only 1 run", async (t) => {
403415
t.false(
404416
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
@@ -454,6 +466,10 @@ test("throwIfCombineSarifFilesDisabled when on dotcom with feature flag", async
454466
type: GitHubVariant.DOTCOM,
455467
},
456468
),
469+
{
470+
message:
471+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
472+
},
457473
);
458474
});
459475

@@ -518,6 +534,10 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18 pre", async (t) => {
518534
version: "3.18.0.pre1",
519535
},
520536
),
537+
{
538+
message:
539+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
540+
},
521541
);
522542
});
523543

@@ -531,6 +551,10 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18 alpha", async (t) => {
531551
version: "3.18.0-alpha.1",
532552
},
533553
),
554+
{
555+
message:
556+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
557+
},
534558
);
535559
});
536560

@@ -544,6 +568,10 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18", async (t) => {
544568
version: "3.18.0",
545569
},
546570
),
571+
{
572+
message:
573+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
574+
},
547575
);
548576
});
549577

src/upload-lib.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
getRequiredEnvParam,
3131
GitHubVariant,
3232
GitHubVersion,
33+
parseGhesVersion,
3334
SarifFile,
3435
SarifRun,
3536
} from "./util";
@@ -132,7 +133,7 @@ export async function shouldShowCombineSarifFilesDeprecationWarning(
132133
// Do not show this warning on GHES versions before 3.14.0
133134
if (
134135
githubVersion.type === GitHubVariant.GHES &&
135-
semver.lt(githubVersion.version, "3.14.0")
136+
semver.lt(parseGhesVersion(githubVersion.version), "3.14.0")
136137
) {
137138
return false;
138139
}
@@ -177,7 +178,7 @@ async function shouldDisableCombineSarifFiles(
177178
) {
178179
if (githubVersion.type === GitHubVariant.GHES) {
179180
// Never block on GHES versions before 3.18.
180-
if (semver.lt(githubVersion.version, "3.18.0-0")) {
181+
if (semver.lt(parseGhesVersion(githubVersion.version), "3.18.0-0")) {
181182
return false;
182183
}
183184
} else {

src/util.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,14 @@ export function checkActionVersion(
11321132
}
11331133
}
11341134

1135+
export function parseGhesVersion(version: string): semver.SemVer {
1136+
// GHES pre-release versions are in the format "3.18.0.pre1", which is not a valid semver version.
1137+
if (version.includes(".pre")) {
1138+
version = version.replace(".pre", "-pre");
1139+
}
1140+
return new semver.SemVer(version);
1141+
}
1142+
11351143
/**
11361144
* Supported build modes.
11371145
*

0 commit comments

Comments
 (0)