Skip to content

Commit 6f936b5

Browse files
authored
Merge pull request #2969 from github/koesie10/fix-ghes-version-parsing
Fix parsing of GHES pre-release versions
2 parents 4e20239 + c6a6c14 commit 6f936b5

File tree

9 files changed

+88
-11
lines changed

9 files changed

+88
-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: 17 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,23 @@ export function checkActionVersion(
11321132
}
11331133
}
11341134

1135+
/**
1136+
* This will parse a GitHub Enterprise Server version string into a SemVer object.
1137+
*
1138+
* GHES versions are usually in a semver-compatible format, so usually this will
1139+
* just call the SemVer constructor. However, for GHES pre-release versions,
1140+
* the version string is in the format "3.18.0.pre1", which is not a valid semver
1141+
* version since the pre-release part of the version should be separated by a
1142+
* hyphen. This function will replace the ".pre" part of the version with "-pre"
1143+
* to make it a valid semver version.
1144+
*/
1145+
export function parseGhesVersion(version: string): semver.SemVer {
1146+
if (version.includes(".pre")) {
1147+
version = version.replace(".pre", "-pre");
1148+
}
1149+
return new semver.SemVer(version);
1150+
}
1151+
11351152
/**
11361153
* Supported build modes.
11371154
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy