Skip to content

Ignore pre-release parts when comparing GHES versions #2972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/upload-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/upload-lib.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lib/upload-lib.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/upload-lib.test.js.map

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/upload-lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,19 @@ test("throwIfCombineSarifFilesDisabled when on GHES 3.18", async (t) => {
);
});

test("throwIfCombineSarifFilesDisabled with an invalid GHES version", async (t) => {
await t.notThrowsAsync(
uploadLib.throwIfCombineSarifFilesDisabled(
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
createFeatures([]),
{
type: GitHubVariant.GHES,
version: "foobar",
},
),
);
});

test("throwIfCombineSarifFilesDisabled with only 1 run", async (t) => {
await t.notThrowsAsync(
uploadLib.throwIfCombineSarifFilesDisabled(
Expand Down
7 changes: 3 additions & 4 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as core from "@actions/core";
import { OctokitResponse } from "@octokit/types";
import fileUrl from "file-url";
import * as jsonschema from "jsonschema";
import * as semver from "semver";

import * as actionsUtil from "./actions-util";
import * as api from "./api-client";
Expand All @@ -29,7 +28,7 @@ import {
getRequiredEnvParam,
GitHubVariant,
GitHubVersion,
parseGhesVersion,
satisfiesGHESVersion,
SarifFile,
SarifRun,
} from "./util";
Expand Down Expand Up @@ -132,7 +131,7 @@ export async function shouldShowCombineSarifFilesDeprecationWarning(
// Do not show this warning on GHES versions before 3.14.0
if (
githubVersion.type === GitHubVariant.GHES &&
semver.lt(parseGhesVersion(githubVersion.version), "3.14.0")
satisfiesGHESVersion(githubVersion.version, "<3.14", true)
) {
return false;
}
Expand Down Expand Up @@ -177,7 +176,7 @@ async function shouldDisableCombineSarifFiles(
) {
if (githubVersion.type === GitHubVariant.GHES) {
// Never block on GHES versions before 3.18.
if (semver.lt(parseGhesVersion(githubVersion.version), "3.18.0-0")) {
if (satisfiesGHESVersion(githubVersion.version, "<3.18", true)) {
return false;
}
} else {
Expand Down
30 changes: 19 additions & 11 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,20 +1133,28 @@ export function checkActionVersion(
}

/**
* This will parse a GitHub Enterprise Server version string into a SemVer object.
* This will check whether the given GitHub version satisfies the given range,
* taking into account that a range like >=3.18 will also match the GHES 3.18
* pre-release/RC versions.
*
* GHES versions are usually in a semver-compatible format, so usually this will
* just call the SemVer constructor. However, for GHES pre-release versions,
* the version string is in the format "3.18.0.pre1", which is not a valid semver
* version since the pre-release part of the version should be separated by a
* hyphen. This function will replace the ".pre" part of the version with "-pre"
* to make it a valid semver version.
* When the given `githubVersion` is not a GHES version, or if the version
* is invalid, this will return `defaultIfInvalid`.
*/
export function parseGhesVersion(version: string): semver.SemVer {
if (version.includes(".pre")) {
version = version.replace(".pre", "-pre");
export function satisfiesGHESVersion(
ghesVersion: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

range: string,
defaultIfInvalid: boolean,
): boolean {
const semverVersion = semver.coerce(ghesVersion);
if (semverVersion === null) {
return defaultIfInvalid;
}
return new semver.SemVer(version);

// We always drop the pre-release part of the version, since anything that
// applies to GHES 3.18.0 should also apply to GHES 3.18.0.pre1.
semverVersion.prerelease = [];

return semver.satisfies(semverVersion, range);
}

/**
Expand Down
Loading
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