diff --git a/dist/index.js b/dist/index.js index 4f84c7f7..2e0090af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -144264,7 +144264,6 @@ async function getLatestOpamRelease() { const { data: releases } = await octokit.rest.repos.listReleases({ owner: "ocaml", repo: "opam", - per_page: 100, }); const matchedReleases = releases .filter((release) => semver.satisfies(release.tag_name, semverRange, { @@ -144273,22 +144272,19 @@ async function getLatestOpamRelease() { })) .sort(({ tag_name: v1 }, { tag_name: v2 }) => semver.rcompare(v1, v2, { loose: true })); const latestRelease = matchedReleases.at(0); - if (latestRelease === undefined) { - throw new Error("latestRelease not found"); + if (!latestRelease) { + throw new Error("Could not retrieve the opam release matching the version constraint"); } - else { - const { assets, tag_name: version } = latestRelease; - const architecture = getArchitecture(); - const platform = getPlatform(); - const matchedAssets = assets.find(({ browser_download_url }) => browser_download_url.includes(`${architecture}-${platform}`)); - if (matchedAssets === undefined) { - throw new Error("matchedAssets not found"); - } - else { - const { browser_download_url: browserDownloadUrl } = matchedAssets; - return { version, browserDownloadUrl }; - } + const architecture = getArchitecture(); + const platform = getPlatform(); + const matchedAssets = latestRelease.assets.find((asset) => asset.browser_download_url.includes(`${architecture}-${platform}`)); + if (!matchedAssets) { + throw new Error("Could not find any assets matching the current platform or architecture"); } + return { + version: latestRelease.tag_name, + browserDownloadUrl: matchedAssets.browser_download_url, + }; } async function findOpam() { const platform = getPlatform(); @@ -144579,16 +144575,17 @@ async function repositoryRemove(name) { await (0,lib_exec.exec)(opam, ["repository", "remove", name, "--all-switches"]); } async function repositoryList() { - let output = ""; const opam = await findOpam(); - await (0,lib_exec.exec)(opam, ["repository", "list", "--all-switches", "--short"], { - listeners: { stdout: (data) => (output += data.toString()) }, - }); - const result = output - .split("\n") - .map((repository) => repository.trim()) - .filter((repository) => repository.length > 0); - return result; + const repositoryList = await (0,lib_exec.getExecOutput)(opam, ["repository", "list", "--all-switches", "--short"], { ignoreReturnCode: true }); + if (repositoryList.exitCode === 0) { + return repositoryList.stdout + .split("\n") + .map((repository) => repository.trim()) + .filter((repository) => repository.length > 0); + } + else { + return []; + } } async function repositoryRemoveAll() { lib_core.startGroup("Remove the opam repositories"); diff --git a/dist/post/index.js b/dist/post/index.js index 7394eeec..efd59c6c 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -143072,7 +143072,6 @@ async function opam_getLatestOpamRelease() { const { data: releases } = await octokit.rest.repos.listReleases({ owner: "ocaml", repo: "opam", - per_page: 100, }); const matchedReleases = releases .filter((release) => semver.satisfies(release.tag_name, semverRange, { @@ -143081,22 +143080,19 @@ async function opam_getLatestOpamRelease() { })) .sort(({ tag_name: v1 }, { tag_name: v2 }) => semver.rcompare(v1, v2, { loose: true })); const latestRelease = matchedReleases.at(0); - if (latestRelease === undefined) { - throw new Error("latestRelease not found"); + if (!latestRelease) { + throw new Error("Could not retrieve the opam release matching the version constraint"); } - else { - const { assets, tag_name: version } = latestRelease; - const architecture = getArchitecture(); - const platform = getPlatform(); - const matchedAssets = assets.find(({ browser_download_url }) => browser_download_url.includes(`${architecture}-${platform}`)); - if (matchedAssets === undefined) { - throw new Error("matchedAssets not found"); - } - else { - const { browser_download_url: browserDownloadUrl } = matchedAssets; - return { version, browserDownloadUrl }; - } + const architecture = getArchitecture(); + const platform = getPlatform(); + const matchedAssets = latestRelease.assets.find((asset) => asset.browser_download_url.includes(`${architecture}-${platform}`)); + if (!matchedAssets) { + throw new Error("Could not find any assets matching the current platform or architecture"); } + return { + version: latestRelease.tag_name, + browserDownloadUrl: matchedAssets.browser_download_url, + }; } async function findOpam() { const platform = getPlatform(); @@ -143387,16 +143383,17 @@ async function repositoryRemove(name) { await exec(opam, ["repository", "remove", name, "--all-switches"]); } async function repositoryList() { - let output = ""; const opam = await findOpam(); - await exec(opam, ["repository", "list", "--all-switches", "--short"], { - listeners: { stdout: (data) => (output += data.toString()) }, - }); - const result = output - .split("\n") - .map((repository) => repository.trim()) - .filter((repository) => repository.length > 0); - return result; + const repositoryList = await getExecOutput(opam, ["repository", "list", "--all-switches", "--short"], { ignoreReturnCode: true }); + if (repositoryList.exitCode === 0) { + return repositoryList.stdout + .split("\n") + .map((repository) => repository.trim()) + .filter((repository) => repository.length > 0); + } + else { + return []; + } } async function repositoryRemoveAll() { core.startGroup("Remove the opam repositories"); diff --git a/packages/setup-ocaml/src/opam.ts b/packages/setup-ocaml/src/opam.ts index 18a544f8..d42e7c15 100644 --- a/packages/setup-ocaml/src/opam.ts +++ b/packages/setup-ocaml/src/opam.ts @@ -34,7 +34,6 @@ export async function getLatestOpamRelease() { const { data: releases } = await octokit.rest.repos.listReleases({ owner: "ocaml", repo: "opam", - per_page: 100, }); const matchedReleases = releases .filter((release) => @@ -47,22 +46,25 @@ export async function getLatestOpamRelease() { semver.rcompare(v1, v2, { loose: true }), ); const latestRelease = matchedReleases.at(0); - if (latestRelease === undefined) { - throw new Error("latestRelease not found"); - } else { - const { assets, tag_name: version } = latestRelease; - const architecture = getArchitecture(); - const platform = getPlatform(); - const matchedAssets = assets.find(({ browser_download_url }) => - browser_download_url.includes(`${architecture}-${platform}`), + if (!latestRelease) { + throw new Error( + "Could not retrieve the opam release matching the version constraint", ); - if (matchedAssets === undefined) { - throw new Error("matchedAssets not found"); - } else { - const { browser_download_url: browserDownloadUrl } = matchedAssets; - return { version, browserDownloadUrl }; - } } + const architecture = getArchitecture(); + const platform = getPlatform(); + const matchedAssets = latestRelease.assets.find((asset) => + asset.browser_download_url.includes(`${architecture}-${platform}`), + ); + if (!matchedAssets) { + throw new Error( + "Could not find any assets matching the current platform or architecture", + ); + } + return { + version: latestRelease.tag_name, + browserDownloadUrl: matchedAssets.browser_download_url, + }; } async function findOpam() { @@ -381,16 +383,20 @@ async function repositoryRemove(name: string) { } async function repositoryList() { - let output = ""; const opam = await findOpam(); - await exec(opam, ["repository", "list", "--all-switches", "--short"], { - listeners: { stdout: (data) => (output += data.toString()) }, - }); - const result = output - .split("\n") - .map((repository) => repository.trim()) - .filter((repository) => repository.length > 0); - return result; + const repositoryList = await getExecOutput( + opam, + ["repository", "list", "--all-switches", "--short"], + { ignoreReturnCode: true }, + ); + if (repositoryList.exitCode === 0) { + return repositoryList.stdout + .split("\n") + .map((repository) => repository.trim()) + .filter((repository) => repository.length > 0); + } else { + return []; + } } export async function repositoryRemoveAll() {