Skip to content

Commit 81d8011

Browse files
committed
Add defaultIfInvalid argument to satisfiesGHESVersion
1 parent e4f079c commit 81d8011

File tree

9 files changed

+44
-13
lines changed

9 files changed

+44
-13
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: 6 additions & 0 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: 9 additions & 3 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,19 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18", async (t) => {
575575
);
576576
});
577577

578+
test("throwIfCombineSarifFilesDisabled with an invalid GHES version", async (t) => {
579+
await t.notThrowsAsync(
580+
uploadLib.throwIfCombineSarifFilesDisabled(
581+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
582+
createFeatures([]),
583+
{
584+
type: GitHubVariant.GHES,
585+
version: "foobar",
586+
},
587+
),
588+
);
589+
});
590+
578591
test("throwIfCombineSarifFilesDisabled with only 1 run", async (t) => {
579592
await t.notThrowsAsync(
580593
uploadLib.throwIfCombineSarifFilesDisabled(

src/upload-lib.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export async function shouldShowCombineSarifFilesDeprecationWarning(
132132
// Do not show this warning on GHES versions before 3.14.0
133133
if (
134134
githubVersion.type === GitHubVariant.GHES &&
135-
satisfiesGHESVersion(githubVersion, "<3.14")
135+
satisfiesGHESVersion(githubVersion, "<3.14", true)
136136
) {
137137
return false;
138138
}
@@ -177,7 +177,7 @@ async function shouldDisableCombineSarifFiles(
177177
) {
178178
if (githubVersion.type === GitHubVariant.GHES) {
179179
// Never block on GHES versions before 3.18.
180-
if (satisfiesGHESVersion(githubVersion, "<3.18")) {
180+
if (satisfiesGHESVersion(githubVersion, "<3.18", true)) {
181181
return false;
182182
}
183183
} else {

src/util.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,17 +1136,23 @@ export function checkActionVersion(
11361136
* This will check whether the given GitHub version satisfies the given range,
11371137
* taking into account that a range like >=3.18 will also match the GHES 3.18
11381138
* pre-release/RC versions.
1139+
*
1140+
* When the given `githubVersion` is not a GHES version, or if the version
1141+
* is invalid, this will return `defaultIfInvalid`.
11391142
*/
11401143
export function satisfiesGHESVersion(
11411144
githubVersion: GitHubVersion,
11421145
range: string,
1146+
defaultIfInvalid = false,
11431147
): boolean {
11441148
if (githubVersion.type !== GitHubVariant.GHES) {
1145-
return false;
1149+
return defaultIfInvalid;
11461150
}
11471151

1148-
const semverVersion =
1149-
semver.coerce(githubVersion.version) ?? new semver.SemVer("0.0.0");
1152+
const semverVersion = semver.coerce(githubVersion.version);
1153+
if (semverVersion === null) {
1154+
return defaultIfInvalid;
1155+
}
11501156

11511157
// We always drop the pre-release part of the version, since anything that
11521158
// applies to GHES 3.18.0 should also apply to GHES 3.18.0.pre1.

0 commit comments

Comments
 (0)