Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 0386b0a

Browse files
author
Jared Weakly
authored
Merge pull request #8 from omelkonian/main
Provide library for other actions to use.
2 parents b60d27d + 2546d99 commit 0386b0a

21 files changed

+671
-8506
lines changed

setup/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist/
2+
lib/
23
.out/
34
__tests__/
45
node_modules/

setup/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
dist-newstyle
33
.out
4+
**/tsbuildinfo
45
.eslintcache

setup/.lintstagedrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
2-
'setup/!(*test).{js,ts,json}': [
2+
'!(*test).{js,ts,json}': [
33
'eslint --cache --fix',
4-
() => 'ncc build',
5-
() => 'git add dist'
4+
() => 'npm run bundle',
5+
() => 'git add setup/dist/ setup/lib/'
66
],
7-
'setup/src/**/*.ts': () => 'tsc -p tsconfig.json',
8-
'setup/*.{js,ts,json,md}': 'prettier --write'
7+
'src/**/*.ts': () => 'tsc -p tsconfig.json',
8+
'*.{js,ts,json,md}': 'prettier --write'
99
};
Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {getOpts, getDefaults} from '../src/opts';
22
import type {OS, Revisions, Tool} from '../src/opts';
3-
import {getInput} from '@actions/core';
43
import * as supported_versions from '../src/versions.json';
54
import * as rv from '../src/release-revisions.json';
65

@@ -17,29 +16,13 @@ const latestRevisions = (os: OS) => ({
1716
stack: release_revisions?.[os]?.stack?.[0]?.to
1817
});
1918

20-
const mkName = (s: string): string =>
21-
`INPUT_${s.replace(/ /g, '_').toUpperCase()}`;
22-
23-
const setupEnv = (o: Record<string, unknown>): void =>
24-
Object.entries(o).forEach(([k, v]) => v && (process.env[mkName(k)] = `${v}`));
25-
2619
const forAllOS = (fn: (t: OS) => any) =>
2720
(['win32', 'darwin', 'linux'] as const).forEach(fn);
2821

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

3225
describe('haskell/actions/setup', () => {
33-
const OLD_ENV = process.env;
34-
35-
beforeEach(() => {
36-
jest.resetModules();
37-
process.env = {...OLD_ENV};
38-
delete process.env.NODE_ENV;
39-
});
40-
41-
afterEach(() => (process.env = OLD_ENV));
42-
4326
it('Parses action.yml to get correct default versions', () => {
4427
forAllOS(os =>
4528
forAllTools(t =>
@@ -55,43 +38,34 @@ describe('haskell/actions/setup', () => {
5538
forAllTools(t => expect(def(os)[t].supported).toBe(supported_versions[t]))
5639
));
5740

58-
it('[meta] Setup Env works', () => {
59-
setupEnv({input: 'value'});
60-
const i = getInput('input');
61-
expect(i).toEqual('value');
62-
});
63-
6441
it('getOpts grabs defaults correctly from environment', () => {
65-
setupEnv({});
6642
forAllOS(os => {
67-
const options = getOpts(def(os), os);
43+
const options = getOpts(def(os), os, {});
6844
forAllTools(t => expect(options[t].raw).toBe(def(os)[t].version));
6945
});
7046
});
7147

7248
it('Versions resolve correctly', () => {
7349
const v = {ghc: '8.6.5', cabal: '2.4.1.0', stack: '2.1.3'};
74-
setupEnv({
75-
'enable-stack': 'true',
76-
'stack-version': '2.1',
77-
'ghc-version': '8.6',
78-
'cabal-version': '2.4'
79-
});
8050
forAllOS(os => {
81-
const options = getOpts(def(os), os);
51+
const options = getOpts(def(os), os, {
52+
'enable-stack': 'true',
53+
'stack-version': '2.1',
54+
'ghc-version': '8.6',
55+
'cabal-version': '2.4'
56+
});
8257
forAllTools(t => expect(options[t].resolved).toBe(v[t]));
8358
});
8459
});
8560

8661
it('"latest" Versions resolve correctly', () => {
87-
setupEnv({
88-
'enable-stack': 'true',
89-
'stack-version': 'latest',
90-
'ghc-version': 'latest',
91-
'cabal-version': 'latest'
92-
});
9362
forAllOS(os => {
94-
const options = getOpts(def(os), os);
63+
const options = getOpts(def(os), os, {
64+
'enable-stack': 'true',
65+
'stack-version': 'latest',
66+
'ghc-version': 'latest',
67+
'cabal-version': 'latest'
68+
});
9569
forAllTools(t =>
9670
expect(options[t].resolved).toBe(
9771
latestRevisions(os)[t] ?? latestVersions[t]
@@ -101,9 +75,10 @@ describe('haskell/actions/setup', () => {
10175
});
10276

10377
it('Enabling stack does not disable GHC or Cabal', () => {
104-
setupEnv({'enable-stack': 'true'});
10578
forAllOS(os => {
106-
const {ghc, cabal, stack} = getOpts(def(os), os);
79+
const {ghc, cabal, stack} = getOpts(def(os), os, {
80+
'enable-stack': 'true'
81+
});
10782
expect({
10883
ghc: ghc.enable,
10984
stack: stack.enable,
@@ -113,9 +88,11 @@ describe('haskell/actions/setup', () => {
11388
});
11489

11590
it('Enabling stack-no-global disables GHC and Cabal', () => {
116-
setupEnv({'enable-stack': 'true', 'stack-no-global': 'true'});
11791
forAllOS(os => {
118-
const {ghc, cabal, stack} = getOpts(def(os), os);
92+
const {ghc, cabal, stack} = getOpts(def(os), os, {
93+
'enable-stack': 'true',
94+
'stack-no-global': 'true'
95+
});
11996
expect({
12097
ghc: ghc.enable,
12198
cabal: cabal.enable,
@@ -125,12 +102,14 @@ describe('haskell/actions/setup', () => {
125102
});
126103

127104
it('Enabling stack-no-global without setting enable-stack errors', () => {
128-
setupEnv({'stack-no-global': 'true'});
129-
forAllOS(os => expect(() => getOpts(def(os), os)).toThrow());
105+
forAllOS(os =>
106+
expect(() => getOpts(def(os), os, {'stack-no-global': 'true'})).toThrow()
107+
);
130108
});
131109

132110
it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
133-
setupEnv({'stack-setup-ghc': 'true'});
134-
forAllOS(os => expect(() => getOpts(def(os), os)).toThrow());
111+
forAllOS(os =>
112+
expect(() => getOpts(def(os), os, {'stack-setup-ghc': 'true'})).toThrow()
113+
);
135114
});
136115
});

setup/dist/index.js

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports =
4040
/******/ // the startup function
4141
/******/ function startup() {
4242
/******/ // Load entry module and return exports
43-
/******/ return __webpack_require__(661);
43+
/******/ return __webpack_require__(131);
4444
/******/ };
4545
/******/
4646
/******/ // run startup
@@ -868,21 +868,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
868868
return result;
869869
};
870870
Object.defineProperty(exports, "__esModule", { value: true });
871-
exports.getOpts = exports.getDefaults = void 0;
871+
exports.getOpts = exports.getDefaults = exports.yamlInputs = void 0;
872872
const core = __importStar(__webpack_require__(470));
873873
const fs_1 = __webpack_require__(747);
874874
const js_yaml_1 = __webpack_require__(414);
875875
const path_1 = __webpack_require__(622);
876876
const supported_versions = __importStar(__webpack_require__(447));
877877
const rv = __importStar(__webpack_require__(859));
878878
const release_revisions = rv;
879+
exports.yamlInputs = js_yaml_1.safeLoad(fs_1.readFileSync(__webpack_require__.ab + "action.yml", 'utf8')
880+
// The action.yml file structure is statically known.
881+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
882+
).inputs;
879883
function getDefaults(os) {
880-
const inpts = js_yaml_1.safeLoad(fs_1.readFileSync(__webpack_require__.ab + "action.yml", 'utf8')
881-
// The action.yml file structure is statically known.
882-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
883-
).inputs;
884884
const mkVersion = (v, vs, t) => ({
885-
version: resolve(inpts[v].default, vs, t, os),
885+
version: resolve(exports.yamlInputs[v].default, vs, t, os),
886886
supported: vs
887887
});
888888
return {
@@ -899,14 +899,16 @@ function resolve(version, supported, tool, os) {
899899
: (_a = supported.find(v => v.startsWith(version))) !== null && _a !== void 0 ? _a : version;
900900
return ((_e = (_d = (_c = (_b = release_revisions === null || release_revisions === void 0 ? void 0 : release_revisions[os]) === null || _b === void 0 ? void 0 : _b[tool]) === null || _c === void 0 ? void 0 : _c.find(({ from }) => from === resolved)) === null || _d === void 0 ? void 0 : _d.to) !== null && _e !== void 0 ? _e : resolved);
901901
}
902-
function getOpts({ ghc, cabal, stack }, os) {
903-
const stackNoGlobal = core.getInput('stack-no-global') !== '';
904-
const stackSetupGhc = core.getInput('stack-setup-ghc') !== '';
905-
const stackEnable = core.getInput('enable-stack') !== '';
902+
function getOpts({ ghc, cabal, stack }, os, inputs) {
903+
core.debug(`Inputs are: ${JSON.stringify(inputs)}`);
904+
const stackNoGlobal = (inputs['stack-no-global'] || '') !== '';
905+
const stackSetupGhc = (inputs['stack-setup-ghc'] || '') !== '';
906+
const stackEnable = (inputs['enable-stack'] || '') !== '';
907+
core.debug(`${stackNoGlobal}/${stackSetupGhc}/${stackEnable}`);
906908
const verInpt = {
907-
ghc: core.getInput('ghc-version') || ghc.version,
908-
cabal: core.getInput('cabal-version') || cabal.version,
909-
stack: core.getInput('stack-version') || stack.version
909+
ghc: inputs['ghc-version'] || ghc.version,
910+
cabal: inputs['cabal-version'] || cabal.version,
911+
stack: inputs['stack-version'] || stack.version
910912
};
911913
const errors = [];
912914
if (stackNoGlobal && !stackEnable) {
@@ -933,7 +935,7 @@ function getOpts({ ghc, cabal, stack }, os) {
933935
raw: verInpt.stack,
934936
resolved: resolve(verInpt.stack, stack.supported, 'stack', os),
935937
enable: stackEnable,
936-
setup: core.getInput('stack-setup-ghc') !== ''
938+
setup: stackSetupGhc
937939
}
938940
};
939941
// eslint-disable-next-line github/array-foreach
@@ -1143,6 +1145,42 @@ exports.issueCommand = issueCommand;
11431145

11441146
module.exports = require("child_process");
11451147

1148+
/***/ }),
1149+
1150+
/***/ 131:
1151+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
1152+
1153+
"use strict";
1154+
1155+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1156+
if (k2 === undefined) k2 = k;
1157+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1158+
}) : (function(o, m, k, k2) {
1159+
if (k2 === undefined) k2 = k;
1160+
o[k2] = m[k];
1161+
}));
1162+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1163+
Object.defineProperty(o, "default", { enumerable: true, value: v });
1164+
}) : function(o, v) {
1165+
o["default"] = v;
1166+
});
1167+
var __importStar = (this && this.__importStar) || function (mod) {
1168+
if (mod && mod.__esModule) return mod;
1169+
var result = {};
1170+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1171+
__setModuleDefault(result, mod);
1172+
return result;
1173+
};
1174+
var __importDefault = (this && this.__importDefault) || function (mod) {
1175+
return (mod && mod.__esModule) ? mod : { "default": mod };
1176+
};
1177+
Object.defineProperty(exports, "__esModule", { value: true });
1178+
const core = __importStar(__webpack_require__(470));
1179+
const opts_1 = __webpack_require__(54);
1180+
const setup_haskell_1 = __importDefault(__webpack_require__(661));
1181+
setup_haskell_1.default(Object.fromEntries(Object.keys(opts_1.yamlInputs).map(k => [k, core.getInput(k)])));
1182+
1183+
11461184
/***/ }),
11471185

11481186
/***/ 139:
@@ -8775,11 +8813,11 @@ async function cabalConfig() {
87758813
});
87768814
return out.toString().trim().split('\n').slice(-1)[0].trim();
87778815
}
8778-
(async () => {
8816+
async function run(inputs) {
87798817
try {
87808818
core.info('Preparing to setup a Haskell environment');
87818819
const os = process.platform;
8782-
const opts = opts_1.getOpts(opts_1.getDefaults(os), os);
8820+
const opts = opts_1.getOpts(opts_1.getDefaults(os), os, inputs);
87838821
for (const [t, { resolved }] of Object.entries(opts).filter(o => o[1].enable))
87848822
await core.group(`Installing ${t} version ${resolved}`, async () => installer_1.installTool(t, resolved, os));
87858823
if (opts.stack.setup)
@@ -8803,7 +8841,8 @@ async function cabalConfig() {
88038841
catch (error) {
88048842
core.setFailed(error.message);
88058843
}
8806-
})();
8844+
}
8845+
exports.default = run;
88078846

88088847

88098848
/***/ }),

setup/docs/contributors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Do checkin source (src)
66
- Do checkin build output (dist)
7+
- Do checkin library build output (lib)
78

89
### Dependencies
910

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

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

2224
## Versions

setup/lib/installer.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type {OS, Tool} from './opts';
2+
export declare function installTool(
3+
tool: Tool,
4+
version: string,
5+
os: OS
6+
): Promise<void>;

0 commit comments

Comments
 (0)