Skip to content

Commit

Permalink
Provide library for other actions to use.
Browse files Browse the repository at this point in the history
  * This allows other Github actions to import and use setup-haskell, see for instance [setup-agda](https://github.com/omelkonian/setup-agda/blob/master/src/setup-haskell.ts#L2).

  * Closes haskell#6.
  • Loading branch information
omelkonian committed Dec 14, 2020
1 parent b60d27d commit 3b85191
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 8,474 deletions.
1 change: 1 addition & 0 deletions setup/.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 setup/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist-newstyle
.out
**/tsbuildinfo
.eslintcache
4 changes: 2 additions & 2 deletions setup/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
'setup/!(*test).{js,ts,json}': [
'eslint --cache --fix',
() => 'ncc build',
() => 'git add dist'
() => 'npm run bundle',
() => 'git add dist/ lib/'
],
'setup/src/**/*.ts': () => 'tsc -p tsconfig.json',
'setup/*.{js,ts,json,md}': 'prettier --write'
Expand Down
63 changes: 26 additions & 37 deletions setup/__tests__/find-haskell.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {getOpts, getDefaults} from '../src/opts';
import type {OS, Revisions, Tool} from '../src/opts';
import {getInput} from '@actions/core';
import * as supported_versions from '../src/versions.json';
import * as rv from '../src/release-revisions.json';

Expand All @@ -17,12 +16,6 @@ const latestRevisions = (os: OS) => ({
stack: release_revisions?.[os]?.stack?.[0]?.to
});

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 forAllOS = (fn: (t: OS) => any) =>
(['win32', 'darwin', 'linux'] as const).forEach(fn);

Expand Down Expand Up @@ -55,43 +48,34 @@ describe('haskell/actions/setup', () => {
forAllTools(t => expect(def(os)[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({});
forAllOS(os => {
const options = getOpts(def(os), os);
const options = getOpts(def(os), os, {});
forAllTools(t => expect(options[t].raw).toBe(def(os)[t].version));
});
});

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

it('"latest" Versions resolve correctly', () => {
setupEnv({
'enable-stack': 'true',
'stack-version': 'latest',
'ghc-version': 'latest',
'cabal-version': 'latest'
});
forAllOS(os => {
const options = getOpts(def(os), os);
const options = getOpts(def(os), os, {
'enable-stack': 'true',
'stack-version': 'latest',
'ghc-version': 'latest',
'cabal-version': 'latest'
});
forAllTools(t =>
expect(options[t].resolved).toBe(
latestRevisions(os)[t] ?? latestVersions[t]
Expand All @@ -101,9 +85,10 @@ describe('haskell/actions/setup', () => {
});

it('Enabling stack does not disable GHC or Cabal', () => {
setupEnv({'enable-stack': 'true'});
forAllOS(os => {
const {ghc, cabal, stack} = getOpts(def(os), os);
const {ghc, cabal, stack} = getOpts(def(os), os, {
'enable-stack': 'true'
});
expect({
ghc: ghc.enable,
stack: stack.enable,
Expand All @@ -113,9 +98,11 @@ describe('haskell/actions/setup', () => {
});

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

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

it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
setupEnv({'stack-setup-ghc': 'true'});
forAllOS(os => expect(() => getOpts(def(os), os)).toThrow());
forAllOS(os =>
expect(() => getOpts(def(os), os, {'stack-setup-ghc': 'true'})).toThrow()
);
});
});
4 changes: 3 additions & 1 deletion setup/docs/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

### Dependencies

Expand All @@ -16,7 +17,8 @@ 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 transpiled library under `lib/`.
Finally, it will make sure these changes are appropriately included in your commit--no further work is needed.

## Versions
Expand Down
Loading

0 comments on commit 3b85191

Please sign in to comment.