Implement fallback install and outputs (#2)

* Add better version support. Restructure code. Implement OS agnostic fallback

* Support latest for cabal and stack. Add enable-stack option.

* Add outputs

* Update documentation. Change default for GHC to latest.
This commit is contained in:
Jared Weakly
2020-04-24 11:53:29 -07:00
committed by GitHub
parent c4e863e92f
commit 120f5dc3eb
19 changed files with 5359 additions and 2031 deletions

View File

@@ -1,38 +1,37 @@
import * as core from '@actions/core';
import {getOpts, getDefaults} from './installer';
import {getOpts, getDefaults, Tool} from './opts';
import {installTool} from './installer';
import type {OS} from './opts';
import {exec} from '@actions/exec';
(async () => {
try {
const opts = getOpts(getDefaults());
core.info('Preparing to setup a Haskell environment');
core.debug(`Options are: ${JSON.stringify(opts)}`);
const opts = getOpts(getDefaults());
for (const [tool, o] of Object.entries(opts)) {
if (o.enable) {
core.info(`Installing ${tool} version ${o.version}`);
await o.install(o.version);
}
}
for (const [t, {resolved}] of Object.entries(opts).filter(o => o[1].enable))
await core.group(`Installing ${t} version ${resolved}`, async () =>
installTool(t as Tool, resolved, process.platform as OS)
);
if (opts.stack.setup) {
core.startGroup('Pre-installing GHC with stack');
await exec('stack', ['setup', opts.ghc.version]);
core.endGroup();
}
if (opts.stack.setup)
await core.group('Pre-installing GHC with stack', async () =>
exec('stack', ['setup', opts.ghc.resolved])
);
if (opts.cabal.enable) {
core.startGroup('Setting up cabal');
await exec('cabal', [
'user-config',
'update',
'-a',
'http-transport: plain-http',
'-v3'
]);
await exec('cabal', ['update']);
core.endGroup();
}
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']);
if (process.platform === 'win32') {
await exec('cabal user-config update -a "store-dir: C:\\sr" -v3');
core.setOutput('cabal-store', 'C:\\sr');
} else {
core.setOutput('cabal-store', `${process.env.HOME}/.cabal/store`);
}
});
} catch (error) {
core.setFailed(error.message);
}