Fix macos ghcup and cabal flags (#4)

* fix short-circuit logic for ghcup based installs of ghc

* fix unrecognized user-config option for cabal v2.0

* update dependencies
This commit is contained in:
Jared Weakly
2020-06-09 09:58:15 -07:00
committed by GitHub
parent c1b48c3995
commit cfefe70615
7 changed files with 6821 additions and 6158 deletions

View File

@@ -85,7 +85,14 @@ async function isInstalled(
.then(() => p)
.catch(() => undefined);
if (installedPath) return success(tool, version, installedPath);
if (installedPath) {
// Make sure that the correct ghc is used, even if ghcup has set a
// default prior to this action being ran.
if (tool === 'ghc' && installedPath === ghcupPath)
await exec(await ghcupBin(os), ['set', version]);
return success(tool, version, installedPath);
}
}
if (tool === 'cabal' && os !== 'win32') {
@@ -172,17 +179,23 @@ async function choco(tool: Tool, version: string): Promise<void> {
]);
}
async function ghcup(tool: Tool, version: string, os: OS): Promise<void> {
core.info(`Attempting to install ${tool} ${version} using ghcup`);
async function ghcupBin(os: OS): Promise<string> {
const v = '0.1.5';
const cachedBin = tc.find('ghcup', v);
if (cachedBin) return join(cachedBin, 'ghcup');
const v = '0.1.4';
const bin = await tc.downloadTool(
`https://downloads.haskell.org/~ghcup/${v}/x86_64-${
`https://downloads.haskell.org/ghcup/${v}/x86_64-${
os === 'darwin' ? 'apple-darwin' : 'linux'
}-ghcup-${v}`
);
await fs.chmod(bin, 0o755);
return join(await tc.cacheFile(bin, 'ghcup', 'ghcup', v), 'ghcup');
}
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);
await exec(bin, [tool === 'ghc' ? 'install' : 'install-cabal', version]);
if (tool === 'ghc') await exec(bin, ['set', version]);
}

View File

@@ -1,9 +1,20 @@
import * as core from '@actions/core';
import * as fs from 'fs';
import {getOpts, getDefaults, Tool} from './opts';
import {installTool} from './installer';
import type {OS} from './opts';
import {exec} from '@actions/exec';
async function cabalConfig(): Promise<string> {
let out = Buffer.from('');
const append = (b: Buffer): Buffer => (out = Buffer.concat([out, b]));
await exec('cabal', ['--help'], {
silent: true,
listeners: {stdout: append, stderr: append}
});
return out.toString().trim().split('\n').slice(-1)[0].trim();
}
(async () => {
try {
core.info('Preparing to setup a Haskell environment');
@@ -21,16 +32,19 @@ import {exec} from '@actions/exec';
if (opts.cabal.enable)
await core.group('Setting up cabal', async () => {
await exec(
'cabal user-config update -a "http-transport: plain-http" -v3'
);
await exec('cabal', ['update']);
await exec('cabal', ['user-config', 'update'], {silent: true});
const configFile = await cabalConfig();
fs.appendFileSync(configFile, 'http-transport: plain-http\n');
if (process.platform === 'win32') {
await exec('cabal user-config update -a "store-dir: C:\\sr" -v3');
fs.appendFileSync(configFile, 'store-dir: C:\\sr\n');
core.setOutput('cabal-store', 'C:\\sr');
} else {
core.setOutput('cabal-store', `${process.env.HOME}/.cabal/store`);
}
await exec('cabal user-config update');
if (!opts.stack.enable) await exec('cabal update');
});
} catch (error) {
core.setFailed(error.message);