Skip to content

Commit e4f079c

Browse files
committed
Ignore pre-release parts when comparing GHES versions
1 parent 6f936b5 commit e4f079c

File tree

6 files changed

+39
-36
lines changed

6 files changed

+39
-36
lines changed

lib/upload-lib.js

Lines changed: 2 additions & 3 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/util.js

Lines changed: 14 additions & 15 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.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as core from "@actions/core";
66
import { OctokitResponse } from "@octokit/types";
77
import fileUrl from "file-url";
88
import * as jsonschema from "jsonschema";
9-
import * as semver from "semver";
109

1110
import * as actionsUtil from "./actions-util";
1211
import { getOptionalInput, getRequiredInput } from "./actions-util";
@@ -30,7 +29,7 @@ import {
3029
getRequiredEnvParam,
3130
GitHubVariant,
3231
GitHubVersion,
33-
parseGhesVersion,
32+
satisfiesGHESVersion,
3433
SarifFile,
3534
SarifRun,
3635
} from "./util";
@@ -133,7 +132,7 @@ export async function shouldShowCombineSarifFilesDeprecationWarning(
133132
// Do not show this warning on GHES versions before 3.14.0
134133
if (
135134
githubVersion.type === GitHubVariant.GHES &&
136-
semver.lt(parseGhesVersion(githubVersion.version), "3.14.0")
135+
satisfiesGHESVersion(githubVersion, "<3.14")
137136
) {
138137
return false;
139138
}
@@ -178,7 +177,7 @@ async function shouldDisableCombineSarifFiles(
178177
) {
179178
if (githubVersion.type === GitHubVariant.GHES) {
180179
// Never block on GHES versions before 3.18.
181-
if (semver.lt(parseGhesVersion(githubVersion.version), "3.18.0-0")) {
180+
if (satisfiesGHESVersion(githubVersion, "<3.18")) {
182181
return false;
183182
}
184183
} else {

src/util.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,20 +1133,26 @@ export function checkActionVersion(
11331133
}
11341134

11351135
/**
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.
1136+
* This will check whether the given GitHub version satisfies the given range,
1137+
* taking into account that a range like >=3.18 will also match the GHES 3.18
1138+
* pre-release/RC versions.
11441139
*/
1145-
export function parseGhesVersion(version: string): semver.SemVer {
1146-
if (version.includes(".pre")) {
1147-
version = version.replace(".pre", "-pre");
1140+
export function satisfiesGHESVersion(
1141+
githubVersion: GitHubVersion,
1142+
range: string,
1143+
): boolean {
1144+
if (githubVersion.type !== GitHubVariant.GHES) {
1145+
return false;
11481146
}
1149-
return new semver.SemVer(version);
1147+
1148+
const semverVersion =
1149+
semver.coerce(githubVersion.version) ?? new semver.SemVer("0.0.0");
1150+
1151+
// We always drop the pre-release part of the version, since anything that
1152+
// applies to GHES 3.18.0 should also apply to GHES 3.18.0.pre1.
1153+
semverVersion.prerelease = [];
1154+
1155+
return semver.satisfies(semverVersion, range);
11501156
}
11511157

11521158
/**

0 commit comments

Comments
 (0)