Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
lib/
.out/
__tests__/
node_modules/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist-newstyle
.out
**/tsbuildinfo
.eslintcache
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
'!(*test).{js,ts}': 'eslint --cache --fix',
'!(*test).ts': () => ['ncc build', 'git add dist'],
'!(*test).ts': () => ['npm run bundle', 'git add dist/ lib/'],
'src/**/*.ts': () => 'tsc -p tsconfig.json',
'*.{js,ts,json,md}': 'prettier --write'
};
37 changes: 10 additions & 27 deletions __tests__/find-haskell.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {getOpts, getDefaults, Tool} from '../src/opts';
import {getInput} from '@actions/core';
import * as supported_versions from '../src/versions.json';

const def = getDefaults();
Expand All @@ -9,12 +8,6 @@ const latestVersions = {
stack: supported_versions.stack[0]
};

const mkName = (s: string): string =>
`INPUT_${s.replace(/ /g, '_').toUpperCase()}`;

const setupEnv = (o: Record<string, unknown>): void =>
Object.entries(o).forEach(([k, v]) => v && (process.env[mkName(k)] = `${v}`));

const forAll = (fn: (t: Tool) => any) =>
(['ghc', 'cabal', 'stack'] as const).forEach(fn);

Expand All @@ -36,42 +29,32 @@ describe('actions/setup-haskell', () => {
it('Supported versions are parsed from JSON correctly', () =>
forAll(t => expect(def[t].supported).toBe(supported_versions[t])));

it('[meta] Setup Env works', () => {
setupEnv({input: 'value'});
const i = getInput('input');
expect(i).toEqual('value');
});

it('getOpts grabs defaults correctly from environment', () => {
setupEnv({});
const options = getOpts(def);
const options = getOpts(def, {});
forAll(t => expect(options[t].raw).toBe(def[t].version));
});

it('Versions resolve correctly', () => {
const v = {ghc: '8.6.5', cabal: '2.4.1.0', stack: '2.1.3'};
setupEnv({
const options = getOpts(def, {
'stack-version': '2.1',
'ghc-version': '8.6',
'cabal-version': '2.4'
});
const options = getOpts(def);
forAll(t => expect(options[t].resolved).toBe(v[t]));
});

it('"latest" Versions resolve correctly', () => {
setupEnv({
const options = getOpts(def, {
'stack-version': 'latest',
'ghc-version': 'latest',
'cabal-version': 'latest'
});
const options = getOpts(def);
forAll(t => expect(options[t].resolved).toBe(latestVersions[t]));
});

it('Enabling stack does not disable GHC or Cabal', () => {
setupEnv({'enable-stack': 'true'});
const {ghc, cabal, stack} = getOpts(def);
const {ghc, cabal, stack} = getOpts(def, {'enable-stack': 'true'});
expect({
ghc: ghc.enable,
stack: stack.enable,
Expand All @@ -80,8 +63,10 @@ describe('actions/setup-haskell', () => {
});

it('Enabling stack-no-global disables GHC and Cabal', () => {
setupEnv({'enable-stack': 'true', 'stack-no-global': 'true'});
const {ghc, cabal, stack} = getOpts(def);
const {ghc, cabal, stack} = getOpts(def, {
'enable-stack': 'true',
'stack-no-global': 'true'
});
expect({
ghc: ghc.enable,
cabal: cabal.enable,
Expand All @@ -90,12 +75,10 @@ describe('actions/setup-haskell', () => {
});

it('Enabling stack-no-global without setting enable-stack errors', () => {
setupEnv({'stack-no-global': 'true'});
expect(() => getOpts(def)).toThrow();
expect(() => getOpts(def, {'stack-no-global': 'true'})).toThrow();
});

it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
setupEnv({'stack-setup-ghc': 'true'});
expect(() => getOpts(def)).toThrow();
expect(() => getOpts(def, {'stack-setup-ghc': 'true'})).toThrow();
});
});
67 changes: 52 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports =
/******/ // the startup function
/******/ function startup() {
/******/ // Load entry module and return exports
/******/ return __webpack_require__(661);
/******/ return __webpack_require__(131);
/******/ };
/******/
/******/ // run startup
Expand Down Expand Up @@ -868,16 +868,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOpts = exports.getDefaults = void 0;
exports.getOpts = exports.getDefaults = exports.yamlInputs = void 0;
const core = __importStar(__webpack_require__(470));
const fs_1 = __webpack_require__(747);
const js_yaml_1 = __webpack_require__(414);
const path_1 = __webpack_require__(622);
const supported_versions = __importStar(__webpack_require__(447));
exports.yamlInputs = js_yaml_1.safeLoad(fs_1.readFileSync(__webpack_require__.ab + "action.yml", 'utf8')).inputs;
function getDefaults() {
const inpts = js_yaml_1.safeLoad(fs_1.readFileSync(__webpack_require__.ab + "action.yml", 'utf8')).inputs;
const mkVersion = (v, vs) => ({
version: resolve(inpts[v].default, vs),
version: resolve(exports.yamlInputs[v].default, vs),
supported: vs
});
return {
Expand All @@ -893,14 +893,14 @@ function resolve(version, supported) {
? supported[0]
: (_a = supported.find(v => v.startsWith(version))) !== null && _a !== void 0 ? _a : version;
}
function getOpts({ ghc, cabal, stack }) {
const stackNoGlobal = core.getInput('stack-no-global') !== '';
const stackSetupGhc = core.getInput('stack-setup-ghc') !== '';
const stackEnable = core.getInput('enable-stack') !== '';
function getOpts({ ghc, cabal, stack }, inputs) {
const stackNoGlobal = inputs['stack-no-global'] === 'true';
const stackSetupGhc = inputs['stack-setup-ghc'] === 'true';
const stackEnable = inputs['enable-stack'] === 'true';
const verInpt = {
ghc: core.getInput('ghc-version') || ghc.version,
cabal: core.getInput('cabal-version') || cabal.version,
stack: core.getInput('stack-version') || stack.version
ghc: inputs['ghc-version'] || ghc.version,
cabal: inputs['cabal-version'] || cabal.version,
stack: inputs['stack-version'] || stack.version
};
const errors = [];
if (stackNoGlobal && !stackEnable) {
Expand All @@ -927,7 +927,7 @@ function getOpts({ ghc, cabal, stack }) {
raw: verInpt.stack,
resolved: resolve(verInpt.stack, stack.supported),
enable: stackEnable,
setup: core.getInput('stack-setup-ghc') !== ''
setup: inputs['stack-setup-ghc'] !== ''
}
};
// eslint-disable-next-line github/array-foreach
Expand Down Expand Up @@ -1137,6 +1137,42 @@ exports.issueCommand = issueCommand;

module.exports = require("child_process");

/***/ }),

/***/ 131:
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const opts_1 = __webpack_require__(54);
const setup_haskell_1 = __importDefault(__webpack_require__(661));
setup_haskell_1.default(Object.fromEntries(Object.keys(opts_1.yamlInputs).map(k => [k, core.getInput(k)])));


/***/ }),

/***/ 139:
Expand Down Expand Up @@ -8690,10 +8726,10 @@ async function cabalConfig() {
});
return out.toString().trim().split('\n').slice(-1)[0].trim();
}
(async () => {
async function run(inputs) {
try {
core.info('Preparing to setup a Haskell environment');
const opts = opts_1.getOpts(opts_1.getDefaults());
const opts = opts_1.getOpts(opts_1.getDefaults(), inputs);
for (const [t, { resolved }] of Object.entries(opts).filter(o => o[1].enable))
await core.group(`Installing ${t} version ${resolved}`, async () => installer_1.installTool(t, resolved, process.platform));
if (opts.stack.setup)
Expand All @@ -8717,7 +8753,8 @@ async function cabalConfig() {
catch (error) {
core.setFailed(error.message);
}
})();
}
exports.default = run;


/***/ }),
Expand Down
5 changes: 3 additions & 2 deletions docs/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
### Checkin

- Do checkin source (src)
- Do checkin build output (dist)
- Do checkin action build output (dist)
- Do checkin library build output (lib)

### Dependencies

Expand All @@ -16,7 +17,7 @@ git add abc.ext # Add the files you've changed. This
git commit -m "Informative commit message" # Commit. This will run Husky
```

During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier). It will also bundle the code into a single `dist/index.js` file.
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier). It will also bundle the code into a single `dist/index.js` file and output the traspiled library under `lib/`.
Finally, it will make sure these changes are appropriately included in your commit--no further work is needed.

## Versions
Expand Down
6 changes: 6 additions & 0 deletions lib/installer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {OS, Tool} from './opts';
export declare function installTool(
tool: Tool,
version: string,
os: OS
): Promise<void>;
Loading