Skip to content

Commit dd627a9

Browse files
committed
Fix parsing of GHES pre-release versions
1 parent bcdb4ec commit dd627a9

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
@@ -372,6 +372,18 @@ test("shouldShowCombineSarifFilesDeprecationWarning when on GHES 3.14", async (t
372372
);
373373
});
374374

375+
test("shouldShowCombineSarifFilesDeprecationWarning when on GHES 3.16 pre", async (t) => {
376+
t.true(
377+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
378+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
379+
{
380+
type: GitHubVariant.GHES,
381+
version: "3.16.0.pre1",
382+
},
383+
),
384+
);
385+
});
386+
375387
test("shouldShowCombineSarifFilesDeprecationWarning with only 1 run", async (t) => {
376388
t.false(
377389
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
@@ -427,6 +439,10 @@ test("throwIfCombineSarifFilesDisabled when on dotcom with feature flag", async
427439
type: GitHubVariant.DOTCOM,
428440
},
429441
),
442+
{
443+
message:
444+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
445+
},
430446
);
431447
});
432448

@@ -491,6 +507,10 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18 pre", async (t) => {
491507
version: "3.18.0.pre1",
492508
},
493509
),
510+
{
511+
message:
512+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
513+
},
494514
);
495515
});
496516

@@ -504,6 +524,10 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18 alpha", async (t) => {
504524
version: "3.18.0-alpha.1",
505525
},
506526
),
527+
{
528+
message:
529+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
530+
},
507531
);
508532
});
509533

@@ -517,6 +541,10 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18", async (t) => {
517541
version: "3.18.0",
518542
},
519543
),
544+
{
545+
message:
546+
/The CodeQL Action does not support uploading multiple SARIF runs with the same category/,
547+
},
520548
);
521549
});
522550

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)