Skip to content

Commit

Permalink
Proper boolean options; enable-matcher; imply enable-stack
Browse files Browse the repository at this point in the history
The options `enable-stack`, `stack-no-global`, `stack-setup-ghc` and `disable-matcher` are now proper booleans only accepting `true` or `false`.
Previously, they were true when set to some non-empty string, even when set to "false" or "off" etc.

`disable-matcher` is deprecated in favour of a new positive form `enable-matcher`.

`enable-stack` is now implied by setting another stack-related option, i.e., one of `stack-version`, `stack-no-global` and `stack-setup-ghc`.
Previously, it was a prerequisite to these options.

Contradictory options now give an error, such as `stack-no-global` with `ghc-version` or `enable-stack: false` with `stack-version`.

Fixes: haskell/actions#142
  • Loading branch information
andreasabel committed Jan 27, 2024
1 parent 70d6a9e commit dea33d5
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 104 deletions.
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()
);
});
});
18 changes: 13 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
Expand All @@ -16,13 +16,16 @@ inputs:
default: 'latest'
enable-stack:
required: false
description: 'If specified, will setup Stack.'
default: false
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 +36,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
93 changes: 69 additions & 24 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

0 comments on commit dea33d5

Please sign in to comment.