Skip to content
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

Use the provided OCaml version when a match is not found #275

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 20 additions & 6 deletions dist/index.js

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

26 changes: 20 additions & 6 deletions dist/post/index.js

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

36 changes: 28 additions & 8 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import * as semver from "semver";

Expand All @@ -20,6 +21,7 @@ function unique(array: string[]) {
return Array.from(new Set(array));
}

// Get all the OCaml releases on GitHub
async function getAllCompilerVersions(): Promise<string[]> {
const octokit = github.getOctokit(GITHUB_TOKEN);
const releases = [];
Expand All @@ -42,13 +44,31 @@ async function getAllCompilerVersions(): Promise<string[]> {
return versions;
}

export async function resolveVersion(semverVersion: string): Promise<string> {
export async function resolveVersion(
semverVersionRange: string
): Promise<string> {
const compilerVersions = await getAllCompilerVersions();
const matchedFullCompilerVersions = compilerVersions
.filter((version) =>
semver.satisfies(version, semverVersion, { loose: true })
)
.sort((v1, v2) => semver.rcompare(v1, v2, { loose: true }));
const latestFullCompilerVersion = matchedFullCompilerVersions[0];
return latestFullCompilerVersion;
const latestFullCompilerVersion = semver.maxSatisfying(
compilerVersions,
semverVersionRange,
{ loose: true }
);
if (latestFullCompilerVersion !== null) {
return latestFullCompilerVersion;
} else {
core.warning(
`Could not find an OCaml release on GitHub that matches the range ${semverVersionRange}.`
);
const cleanedFullCompilerVersion = semver.clean(semverVersionRange, {
loose: true,
});
if (cleanedFullCompilerVersion === null) {
throw new Error(`Failed to resolve version range ${semverVersionRange}.`);
} else {
core.warning(
`Proceed with the OCaml version ${cleanedFullCompilerVersion}.`
);
return cleanedFullCompilerVersion;
}
}
}