Skip to content

Commit

Permalink
Break out getLatestNightlyFromGhcup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Jul 13, 2023
1 parent 65f7251 commit c5343c2
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 48 deletions.
43 changes: 29 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13302,20 +13302,7 @@ async function configureOutputs(tool, version, path, os) {
// can't put this in resolve() because it might run before ghcup is installed
let resolvedVersion = version;
if (version === 'latest-nightly') {
try {
const ghcupExe = await ghcupBin(os);
const out = await new Promise((resolve, reject) => child_process.execFile(ghcupExe, ['list', '-nr'], { encoding: 'utf-8' }, (error, stdout) => (error ? reject(error) : resolve(stdout))));
resolvedVersion =
out
.split('\n')
.map(line => line.split(' '))
.filter(line => line[2] === 'latest-nightly')
.map(line => line[1])
.at(0) ?? version;
}
catch (error) {
// swallow failures, just leave version as 'latest-nightly'
}
resolvedVersion = (await getLatestNightlyFromGhcup(os)) ?? version;
}
core.setOutput(`${tool}-version`, resolvedVersion);
}
Expand Down Expand Up @@ -13548,6 +13535,34 @@ async function addGhcupReleaseChannel(channel, os) {
await exec(bin, ['config', 'add-release-channel', channel.toString()]);
}
exports.addGhcupReleaseChannel = addGhcupReleaseChannel;
/**
* Get the resolved version of the `latest-nightly` GHC tag from ghcup,
* e.g. '9.9.20230711'
*/
async function getLatestNightlyFromGhcup(os) {
try {
const ghcupExe = await ghcupBin(os);
/* Example output:
ghc 9.0.2 base-4.15.1.0
ghc 9.7.20230526 nightly 2023-06-27
ghc 9.9.20230711 latest-nightly 2023-07-12
cabal 2.4.1.0 no-bindist
cabal 3.6.2.0 recommended
*/
const out = await new Promise((resolve, reject) => child_process.execFile(ghcupExe, ['list', '-nr'], { encoding: 'utf-8' }, (error, stdout) => (error ? reject(error) : resolve(stdout))));
return (out
.split('\n')
.map(line => line.split(' '))
.filter(line => line[2] === 'latest-nightly')
.map(line => line[1])
.at(0) ?? null);
}
catch (error) {
// swallow failures, just return null
return null;
}
}
async function ghcup(tool, version, os) {
core.info(`Attempting to install ${tool} ${version} using ghcup`);
const bin = await ghcupBin(os);
Expand Down
43 changes: 29 additions & 14 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,7 @@ async function configureOutputs(tool, version, path, os) {
// can't put this in resolve() because it might run before ghcup is installed
let resolvedVersion = version;
if (version === 'latest-nightly') {
try {
const ghcupExe = await ghcupBin(os);
const out = await new Promise((resolve, reject) => child_process.execFile(ghcupExe, ['list', '-nr'], { encoding: 'utf-8' }, (error, stdout) => (error ? reject(error) : resolve(stdout))));
resolvedVersion =
out
.split('\n')
.map(line => line.split(' '))
.filter(line => line[2] === 'latest-nightly')
.map(line => line[1])
.at(0) ?? version;
}
catch (error) {
// swallow failures, just leave version as 'latest-nightly'
}
resolvedVersion = (await getLatestNightlyFromGhcup(os)) ?? version;
}
core.setOutput(`${tool}-version`, resolvedVersion);
}
Expand Down Expand Up @@ -303,6 +290,34 @@ async function addGhcupReleaseChannel(channel, os) {
await exec(bin, ['config', 'add-release-channel', channel.toString()]);
}
exports.addGhcupReleaseChannel = addGhcupReleaseChannel;
/**
* Get the resolved version of the `latest-nightly` GHC tag from ghcup,
* e.g. '9.9.20230711'
*/
async function getLatestNightlyFromGhcup(os) {
try {
const ghcupExe = await ghcupBin(os);
/* Example output:
ghc 9.0.2 base-4.15.1.0
ghc 9.7.20230526 nightly 2023-06-27
ghc 9.9.20230711 latest-nightly 2023-07-12
cabal 2.4.1.0 no-bindist
cabal 3.6.2.0 recommended
*/
const out = await new Promise((resolve, reject) => child_process.execFile(ghcupExe, ['list', '-nr'], { encoding: 'utf-8' }, (error, stdout) => (error ? reject(error) : resolve(stdout))));
return (out
.split('\n')
.map(line => line.split(' '))
.filter(line => line[2] === 'latest-nightly')
.map(line => line[1])
.at(0) ?? null);
}
catch (error) {
// swallow failures, just return null
return null;
}
}
async function ghcup(tool, version, os) {
core.info(`Attempting to install ${tool} ${version} using ghcup`);
const bin = await ghcupBin(os);
Expand Down
58 changes: 38 additions & 20 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,7 @@ async function configureOutputs(
// can't put this in resolve() because it might run before ghcup is installed
let resolvedVersion = version;
if (version === 'latest-nightly') {
try {
const ghcupExe = await ghcupBin(os);
const out = await new Promise<string>((resolve, reject) =>
child_process.execFile(
ghcupExe,
['list', '-nr'],
{encoding: 'utf-8'},
(error, stdout) => (error ? reject(error) : resolve(stdout))
)
);
resolvedVersion =
out
.split('\n')
.map(line => line.split(' '))
.filter(line => line[2] === 'latest-nightly')
.map(line => line[1])
.at(0) ?? version;
} catch (error) {
// swallow failures, just leave version as 'latest-nightly'
}
resolvedVersion = (await getLatestNightlyFromGhcup(os)) ?? version;
}
core.setOutput(`${tool}-version`, resolvedVersion);
}
Expand Down Expand Up @@ -351,6 +332,43 @@ export async function addGhcupReleaseChannel(
await exec(bin, ['config', 'add-release-channel', channel.toString()]);
}

/**
* Get the resolved version of the `latest-nightly` GHC tag from ghcup,
* e.g. '9.9.20230711'
*/
async function getLatestNightlyFromGhcup(os: OS): Promise<string | null> {
try {
const ghcupExe = await ghcupBin(os);
/* Example output:
ghc 9.0.2 base-4.15.1.0
ghc 9.7.20230526 nightly 2023-06-27
ghc 9.9.20230711 latest-nightly 2023-07-12
cabal 2.4.1.0 no-bindist
cabal 3.6.2.0 recommended
*/
const out = await new Promise<string>((resolve, reject) =>
child_process.execFile(
ghcupExe,
['list', '-nr'],
{encoding: 'utf-8'},
(error, stdout) => (error ? reject(error) : resolve(stdout))
)
);
return (
out
.split('\n')
.map(line => line.split(' '))
.filter(line => line[2] === 'latest-nightly')
.map(line => line[1])
.at(0) ?? null
);
} catch (error) {
// swallow failures, just return null
return null;
}
}

async function ghcup(tool: Tool, version: string, os: OS): Promise<void> {
core.info(`Attempting to install ${tool} ${version} using ghcup`);
const bin = await ghcupBin(os);
Expand Down

0 comments on commit c5343c2

Please sign in to comment.