Skip to content

Commit

Permalink
Support latest-nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Jul 12, 2023
1 parent 14547ab commit 611064b
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 33 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ E.g., `8.10` will be resolved to `8.10.7`, and so will `8`.

**GHC:**

- `latest-nightly`
- `latest` (default)
- `9.6.2` `9.6`
- `9.6.1`
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: 'GitHub'
inputs:
ghc-version:
required: false
description: 'Version of GHC to use. If set to "latest", it will always get the latest stable version.'
description: 'Version of GHC to use. If set to "latest", it will always get the latest stable version. If set to "latest-nightly", it will always get the latest nightly version of GHC'
default: 'latest'
cabal-version:
required: false
Expand Down
49 changes: 40 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13276,6 +13276,7 @@ const core = __importStar(__nccwpck_require__(2186));
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const tc = __importStar(__nccwpck_require__(7784));
const child_process = __importStar(__nccwpck_require__(2081));
const fs_1 = __nccwpck_require__(7147);
const path_1 = __nccwpck_require__(1017);
const opts_1 = __nccwpck_require__(8131);
Expand All @@ -13298,7 +13299,25 @@ async function configureOutputs(tool, version, path, os) {
if (os === 'win32')
core.exportVariable('STACK_ROOT', sr);
}
core.setOutput(`${tool}-version`, version);
// 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'
}
}
core.setOutput(`${tool}-version`, resolvedVersion);
}
async function success(tool, version, path, os) {
core.addPath(path);
Expand Down Expand Up @@ -13400,12 +13419,14 @@ async function installTool(tool, version, os) {
}
switch (os) {
case 'linux':
if (tool === 'ghc' && (0, compare_versions_1.compareVersions)('8.3', version)) {
// Andreas, 2022-12-09: The following errors out if we are not ubuntu-20.04.
// Atm, I do not know how to check whether we are on ubuntu-20.04.
// So, ignore the error.
// if (!(await aptLibCurses5())) break;
await aptLibNCurses5();
if (tool === 'ghc') {
if (version !== 'latest-nightly' && (0, compare_versions_1.compareVersions)('8.3', version)) {
// Andreas, 2022-12-09: The following errors out if we are not ubuntu-20.04.
// Atm, I do not know how to check whether we are on ubuntu-20.04.
// So, ignore the error.
// if (!(await aptLibCurses5())) break;
await aptLibNCurses5();
}
}
await ghcup(tool, version, os);
if (await isInstalled(tool, version, os))
Expand Down Expand Up @@ -13862,8 +13883,18 @@ async function run(inputs) {
core.debug(`run: inputs = ${JSON.stringify(inputs)}`);
core.debug(`run: os = ${JSON.stringify(os)}`);
core.debug(`run: opts = ${JSON.stringify(opts)}`);
if (opts.ghcup.releaseChannel) {
await core.group(`Preparing ghcup environment`, async () => (0, installer_1.addGhcupReleaseChannel)(opts.ghcup.releaseChannel, os));
const releaseChannels = [
opts.ghcup.releaseChannel,
opts.ghc.raw === 'latest-nightly'
? new URL('https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml')
: null
].filter((v) => v !== null);
if (releaseChannels.length > 0) {
await core.group(`Setting release channels`, async () => {
for (const channel of releaseChannels) {
await (0, installer_1.addGhcupReleaseChannel)(channel, os);
}
});
}
for (const [t, { resolved }] of Object.entries(opts).filter(o => o[1].enable)) {
await core.group(`Preparing ${t} environment`, async () => (0, installer_1.resetTool)(t, resolved, os));
Expand Down
35 changes: 28 additions & 7 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec");
const io_1 = require("@actions/io");
const tc = __importStar(require("@actions/tool-cache"));
const child_process = __importStar(require("child_process"));
const fs_1 = require("fs");
const path_1 = require("path");
const opts_1 = require("./opts");
Expand All @@ -53,7 +54,25 @@ async function configureOutputs(tool, version, path, os) {
if (os === 'win32')
core.exportVariable('STACK_ROOT', sr);
}
core.setOutput(`${tool}-version`, version);
// 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'
}
}
core.setOutput(`${tool}-version`, resolvedVersion);
}
async function success(tool, version, path, os) {
core.addPath(path);
Expand Down Expand Up @@ -155,12 +174,14 @@ async function installTool(tool, version, os) {
}
switch (os) {
case 'linux':
if (tool === 'ghc' && (0, compare_versions_1.compareVersions)('8.3', version)) {
// Andreas, 2022-12-09: The following errors out if we are not ubuntu-20.04.
// Atm, I do not know how to check whether we are on ubuntu-20.04.
// So, ignore the error.
// if (!(await aptLibCurses5())) break;
await aptLibNCurses5();
if (tool === 'ghc') {
if (version !== 'latest-nightly' && (0, compare_versions_1.compareVersions)('8.3', version)) {
// Andreas, 2022-12-09: The following errors out if we are not ubuntu-20.04.
// Atm, I do not know how to check whether we are on ubuntu-20.04.
// So, ignore the error.
// if (!(await aptLibCurses5())) break;
await aptLibNCurses5();
}
}
await ghcup(tool, version, os);
if (await isInstalled(tool, version, os))
Expand Down
4 changes: 2 additions & 2 deletions lib/opts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ProgramOpt {
export interface Options {
ghc: ProgramOpt;
ghcup: {
releaseChannel?: URL;
releaseChannel: URL | null;
};
cabal: ProgramOpt & {
update: boolean;
Expand Down Expand Up @@ -85,6 +85,6 @@ export declare function releaseRevision(version: string, tool: Tool, os: OS): st
* @returns boolean
*/
export declare function parseYAMLBoolean(name: string, val: string): boolean;
export declare function parseURL(name: string, val: string): URL | undefined;
export declare function parseURL(name: string, val: string): URL | null;
export declare function getOpts({ ghc, cabal, stack }: Defaults, os: OS, inputs: Record<string, string>): Options;
export {};
2 changes: 1 addition & 1 deletion lib/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function parseYAMLBoolean(name, val) {
exports.parseYAMLBoolean = parseYAMLBoolean;
function parseURL(name, val) {
if (val === '')
return undefined;
return null;
try {
return new URL(val);
}
Expand Down
14 changes: 12 additions & 2 deletions lib/setup-haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,18 @@ async function run(inputs) {
core.debug(`run: inputs = ${JSON.stringify(inputs)}`);
core.debug(`run: os = ${JSON.stringify(os)}`);
core.debug(`run: opts = ${JSON.stringify(opts)}`);
if (opts.ghcup.releaseChannel) {
await core.group(`Preparing ghcup environment`, async () => (0, installer_1.addGhcupReleaseChannel)(opts.ghcup.releaseChannel, os));
const releaseChannels = [
opts.ghcup.releaseChannel,
opts.ghc.raw === 'latest-nightly'
? new URL('https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml')
: null
].filter((v) => v !== null);
if (releaseChannels.length > 0) {
await core.group(`Setting release channels`, async () => {
for (const channel of releaseChannels) {
await (0, installer_1.addGhcupReleaseChannel)(channel, os);
}
});
}
for (const [t, { resolved }] of Object.entries(opts).filter(o => o[1].enable)) {
await core.group(`Preparing ${t} environment`, async () => (0, installer_1.resetTool)(t, resolved, os));
Expand Down
42 changes: 35 additions & 7 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core';
import {exec as e} from '@actions/exec';
import {which} from '@actions/io';
import * as tc from '@actions/tool-cache';
import * as child_process from 'child_process';
import {promises as afs} from 'fs';
import {join, dirname} from 'path';
import {ghcup_version, OS, Tool, releaseRevision} from './opts';
Expand Down Expand Up @@ -33,7 +34,32 @@ async function configureOutputs(
core.setOutput('stack-root', sr);
if (os === 'win32') core.exportVariable('STACK_ROOT', sr);
}
core.setOutput(`${tool}-version`, version);

// 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'
}
}
core.setOutput(`${tool}-version`, resolvedVersion);
}

async function success(
Expand Down Expand Up @@ -165,12 +191,14 @@ export async function installTool(

switch (os) {
case 'linux':
if (tool === 'ghc' && compareVersions('8.3', version)) {
// Andreas, 2022-12-09: The following errors out if we are not ubuntu-20.04.
// Atm, I do not know how to check whether we are on ubuntu-20.04.
// So, ignore the error.
// if (!(await aptLibCurses5())) break;
await aptLibNCurses5();
if (tool === 'ghc') {
if (version !== 'latest-nightly' && compareVersions('8.3', version)) {
// Andreas, 2022-12-09: The following errors out if we are not ubuntu-20.04.
// Atm, I do not know how to check whether we are on ubuntu-20.04.
// So, ignore the error.
// if (!(await aptLibCurses5())) break;
await aptLibNCurses5();
}
}
await ghcup(tool, version, os);
if (await isInstalled(tool, version, os)) return;
Expand Down
18 changes: 14 additions & 4 deletions src/setup-haskell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ export default async function run(
core.debug(`run: os = ${JSON.stringify(os)}`);
core.debug(`run: opts = ${JSON.stringify(opts)}`);

if (opts.ghcup.releaseChannel) {
await core.group(`Preparing ghcup environment`, async () =>
addGhcupReleaseChannel(opts.ghcup.releaseChannel!, os)
);
const releaseChannels = [
opts.ghcup.releaseChannel,
opts.ghc.raw === 'latest-nightly'
? new URL(
'https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml'
)
: null
].filter((v): v is URL => v !== null);
if (releaseChannels.length > 0) {
await core.group(`Setting release channels`, async () => {
for (const channel of releaseChannels) {
await addGhcupReleaseChannel(channel, os);
}
});
}

for (const [t, {resolved}] of Object.entries(opts).filter(
Expand Down

0 comments on commit 611064b

Please sign in to comment.