Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper boolean options; enable-matcher; imply enable-stack #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,18 @@ jobs:

## Inputs

| Name | Description | Type | Default |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------- |
| `ghc-version` | GHC version to use, e.g. `9.2` or `9.2.5`. | `string` | `latest` |
| `cabal-version` | Cabal version to use, e.g. `3.6`. | `string` | `latest` |
| `stack-version` | Stack version to use, e.g. `latest`. Stack will only be installed if `enable-stack` is set. | `string` | `latest` |
| `enable-stack` | If set, will setup Stack. | "boolean" | false/unset |
| `stack-no-global` | If set, `enable-stack` must be set. Prevents installing GHC and Cabal globally. | "boolean" | false/unset |
| `stack-setup-ghc` | If set, `enable-stack` must be set. Runs stack setup to install the specified GHC. (Note: setting this does _not_ imply `stack-no-global`.) | "boolean" | false/unset |
| `disable-matcher` | If set, disables match messages from GHC as GitHub CI annotations. | "boolean" | false/unset |
| `cabal-update` | If set to `false`, skip `cabal update` step. | `boolean` | `true` |
| `ghcup-release-channel` | If set, add a [release channel](https://www.haskell.org/ghcup/guide/#pre-release-channels) to ghcup. | `URL` | none |

Note: "boolean" types are set/unset, not true/false.
That is, setting any "boolean" to a value other than the empty string (`""`) will be considered true/set.
However, to avoid confusion and for forward compatibility, it is still recommended to **only use value `true` to set a "boolean" flag.**

In contrast, a proper `boolean` input like `cabal-update` only accepts values `true` and `false`.
| Name | Description | Type | Default |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------- | -------- |
| `ghc-version` | GHC version to use, e.g. `9.2` or `9.2.5`. | `string` | `latest` |
| `cabal-version` | Cabal version to use, e.g. `3.6`. | `string` | `latest` |
| `stack-version` | Stack version to use, e.g. `latest`. Implies `enable-stack`. | `string` | `latest` |
| `enable-stack` | Setup Stack. Implied by `stack-version`, `stack-no-global`, `stack-setup-ghc`. | `boolean` | `false` |
| `stack-no-global` | Implies `enable-stack`. Prevents installing GHC and Cabal globally. | `boolean` | `false` |
| `stack-setup-ghc` | Implies `enable-stack`. Runs stack setup to install the specified GHC. (Note: setting this does _not_ imply `stack-no-global`.) | `boolean` | `false` |
| `enable-matcher` | Enable match messages from GHC as GitHub CI annotations. | `boolean` | `true` |
| `disable-matcher` | Disable match messages from GHC as GitHub CI annotations. (Legacy option, deprecated in favour of `enable-matcher`.) | `boolean` | `false` |
| `cabal-update` | Perform `cabal update` step. (Default if Cabal is enabled.) | `boolean` | `true` |
| `ghcup-release-channel` | If set, add a [release channel](https://www.haskell.org/ghcup/guide/#pre-release-channels) to ghcup. | `URL` | none |

## Outputs

Expand Down
55 changes: 51 additions & 4 deletions __tests__/find-haskell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ describe('haskell-actions/setup', () => {
forAllTools(t => expect(def(os)[t].supported).toBe(supported_versions[t]))
));

it('Setting enable-matcher to false disables matcher', () => {
forAllOS(os => {
const options = getOpts(def(os), os, {
'enable-matcher': 'false'
});
expect(options.general.matcher.enable).toBe(false);
});
});
it('Setting disable-matcher to true disables matcher', () => {
forAllOS(os => {
const options = getOpts(def(os), os, {
Expand All @@ -51,6 +59,25 @@ describe('haskell-actions/setup', () => {
expect(options.general.matcher.enable).toBe(false);
});
});
it('Setting both enable-matcher to false and disable-matcher to true disables matcher', () => {
forAllOS(os => {
const options = getOpts(def(os), os, {
'enable-matcher': 'false',
'disable-matcher': 'true'
});
expect(options.general.matcher.enable).toBe(false);
});
});
it('Setting both enable-matcher and disable-matcher to true errors', () => {
forAllOS(os =>
expect(() =>
getOpts(def(os), os, {
'enable-matcher': 'true',
'disable-matcher': 'true'
})
).toThrow()
);
});

it('getOpts grabs default general settings correctly from environment', () => {
forAllOS(os => {
Expand Down Expand Up @@ -148,15 +175,35 @@ describe('haskell-actions/setup', () => {
});
});

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

it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
it('Enabling stack-no-global but setting ghc-version errors', () => {
forAllOS(os =>
expect(() =>
getOpts(def(os), os, {
'stack-no-global': 'true',
'ghc-version': 'latest'
})
).toThrow()
);
});
it('Enabling stack-no-global but setting cabal-version errors', () => {
forAllOS(os =>
expect(() => getOpts(def(os), os, {'stack-setup-ghc': 'true'})).toThrow()
expect(() =>
getOpts(def(os), os, {
'stack-no-global': 'true',
'cabal-version': 'latest'
})
).toThrow()
);
});
});
19 changes: 12 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: 'Setup Haskell'
description: 'Set up a specific version of GHC and Cabal and add the command-line tools to the PATH'
author: 'GitHub'
author: 'Haskell community'
inputs:
ghc-version:
required: false
description: 'Version of GHC to use. If set to "latest", it will always get the latest stable version. If set to "head", it will always get the latest build of GHC.'
default: 'latest'
cabal-version:
required: false
description: 'Version of Cabal to use. If set to "latest", it will always get the latest stable version. If set to "head", it will always get the latest build of cabal.'
default: 'latest'
stack-version:
required: false
description: 'Version of Stack to use. If set to "latest", it will always get the latest stable version.'
default: 'latest'
enable-stack:
required: false
description: 'If specified, will setup Stack.'
description: 'If set to `true`, will setup default Stack. Implied by any of `stack-version`, `stack-no-global`, `stack-setup-ghc`.'
stack-no-global:
required: false
description: 'If specified, enable-stack must be set. Prevents installing GHC and Cabal globally.'
default: false
description: 'If set to `true`, will setup Stack but will not install GHC and Cabal globally.'
stack-setup-ghc:
required: false
description: 'If specified, enable-stack must be set. Will run stack setup to install the specified GHC.'
default: false
description: 'If set to `true`, will setup Stack. Will run `stack setup` to install the specified GHC.'
cabal-update:
required: false
default: true
Expand All @@ -33,9 +33,14 @@ inputs:
ghcup-release-channel:
required: false
description: "A release channel URL to add to ghcup via `ghcup config add-release-channel`."
enable-matcher:
required: false
default: true
description: 'Enable match messages from GHC as GitHub CI annotations.'
disable-matcher:
required: false
description: 'If specified, disables match messages from GHC as GitHub CI annotations.'
default: false
description: 'Legacy input, use `enable-matcher` instead.'
outputs:
ghc-version:
description: 'The resolved version of ghc'
Expand Down
95 changes: 70 additions & 25 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/opts.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading