Skip to content

Commit dea33d5

Browse files
committed
Proper boolean options; enable-matcher; imply enable-stack
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
1 parent 70d6a9e commit dea33d5

File tree

7 files changed

+309
-104
lines changed

7 files changed

+309
-104
lines changed

README.md

+12-17
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,18 @@ jobs:
190190
191191
## Inputs
192192
193-
| Name | Description | Type | Default |
194-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------- |
195-
| `ghc-version` | GHC version to use, e.g. `9.2` or `9.2.5`. | `string` | `latest` |
196-
| `cabal-version` | Cabal version to use, e.g. `3.6`. | `string` | `latest` |
197-
| `stack-version` | Stack version to use, e.g. `latest`. Stack will only be installed if `enable-stack` is set. | `string` | `latest` |
198-
| `enable-stack` | If set, will setup Stack. | "boolean" | false/unset |
199-
| `stack-no-global` | If set, `enable-stack` must be set. Prevents installing GHC and Cabal globally. | "boolean" | false/unset |
200-
| `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 |
201-
| `disable-matcher` | If set, disables match messages from GHC as GitHub CI annotations. | "boolean" | false/unset |
202-
| `cabal-update` | If set to `false`, skip `cabal update` step. | `boolean` | `true` |
203-
| `ghcup-release-channel` | If set, add a [release channel](https://www.haskell.org/ghcup/guide/#pre-release-channels) to ghcup. | `URL` | none |
204-
205-
Note: "boolean" types are set/unset, not true/false.
206-
That is, setting any "boolean" to a value other than the empty string (`""`) will be considered true/set.
207-
However, to avoid confusion and for forward compatibility, it is still recommended to **only use value `true` to set a "boolean" flag.**
208-
209-
In contrast, a proper `boolean` input like `cabal-update` only accepts values `true` and `false`.
193+
| Name | Description | Type | Default |
194+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------- | -------- |
195+
| `ghc-version` | GHC version to use, e.g. `9.2` or `9.2.5`. | `string` | `latest` |
196+
| `cabal-version` | Cabal version to use, e.g. `3.6`. | `string` | `latest` |
197+
| `stack-version` | Stack version to use, e.g. `latest`. Implies `enable-stack`. | `string` | `latest` |
198+
| `enable-stack` | Setup Stack. Implied by `stack-version`, `stack-no-global`, `stack-setup-ghc`. | `boolean` | `false` |
199+
| `stack-no-global` | Implies `enable-stack`. Prevents installing GHC and Cabal globally. | `boolean` | `false` |
200+
| `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` |
201+
| `enable-matcher` | Enable match messages from GHC as GitHub CI annotations. | `boolean` | `true` |
202+
| `disable-matcher` | Disable match messages from GHC as GitHub CI annotations. (Legacy option, deprecated in favour of `enable-matcher`.) | `boolean` | `false` |
203+
| `cabal-update` | Perform `cabal update` step. (Default if Cabal is enabled.) | `boolean` | `true` |
204+
| `ghcup-release-channel` | If set, add a [release channel](https://www.haskell.org/ghcup/guide/#pre-release-channels) to ghcup. | `URL` | none |
210205

211206
## Outputs
212207

__tests__/find-haskell.test.ts

+51-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ describe('haskell-actions/setup', () => {
4343
forAllTools(t => expect(def(os)[t].supported).toBe(supported_versions[t]))
4444
));
4545

46+
it('Setting enable-matcher to false disables matcher', () => {
47+
forAllOS(os => {
48+
const options = getOpts(def(os), os, {
49+
'enable-matcher': 'false'
50+
});
51+
expect(options.general.matcher.enable).toBe(false);
52+
});
53+
});
4654
it('Setting disable-matcher to true disables matcher', () => {
4755
forAllOS(os => {
4856
const options = getOpts(def(os), os, {
@@ -51,6 +59,25 @@ describe('haskell-actions/setup', () => {
5159
expect(options.general.matcher.enable).toBe(false);
5260
});
5361
});
62+
it('Setting both enable-matcher to false and disable-matcher to true disables matcher', () => {
63+
forAllOS(os => {
64+
const options = getOpts(def(os), os, {
65+
'enable-matcher': 'false',
66+
'disable-matcher': 'true'
67+
});
68+
expect(options.general.matcher.enable).toBe(false);
69+
});
70+
});
71+
it('Setting both enable-matcher and disable-matcher to true errors', () => {
72+
forAllOS(os =>
73+
expect(() =>
74+
getOpts(def(os), os, {
75+
'enable-matcher': 'true',
76+
'disable-matcher': 'true'
77+
})
78+
).toThrow()
79+
);
80+
});
5481

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

151-
it('Enabling stack-no-global without setting enable-stack errors', () => {
178+
it('Enabling stack-no-global but disabling enable-stack errors', () => {
152179
forAllOS(os =>
153-
expect(() => getOpts(def(os), os, {'stack-no-global': 'true'})).toThrow()
180+
expect(() =>
181+
getOpts(def(os), os, {
182+
'stack-no-global': 'true',
183+
'enable-stack': 'false'
184+
})
185+
).toThrow()
154186
);
155187
});
156188

157-
it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
189+
it('Enabling stack-no-global but setting ghc-version errors', () => {
190+
forAllOS(os =>
191+
expect(() =>
192+
getOpts(def(os), os, {
193+
'stack-no-global': 'true',
194+
'ghc-version': 'latest'
195+
})
196+
).toThrow()
197+
);
198+
});
199+
it('Enabling stack-no-global but setting cabal-version errors', () => {
158200
forAllOS(os =>
159-
expect(() => getOpts(def(os), os, {'stack-setup-ghc': 'true'})).toThrow()
201+
expect(() =>
202+
getOpts(def(os), os, {
203+
'stack-no-global': 'true',
204+
'cabal-version': 'latest'
205+
})
206+
).toThrow()
160207
);
161208
});
162209
});

action.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 'Setup Haskell'
22
description: 'Set up a specific version of GHC and Cabal and add the command-line tools to the PATH'
3-
author: 'GitHub'
3+
author: 'Haskell community'
44
inputs:
55
ghc-version:
66
required: false
@@ -16,13 +16,16 @@ inputs:
1616
default: 'latest'
1717
enable-stack:
1818
required: false
19-
description: 'If specified, will setup Stack.'
19+
default: false
20+
description: 'If set to `true`, will setup default Stack. Implied by any of `stack-version`, `stack-no-global`, `stack-setup-ghc`.'
2021
stack-no-global:
2122
required: false
22-
description: 'If specified, enable-stack must be set. Prevents installing GHC and Cabal globally.'
23+
default: false
24+
description: 'If set to `true`, will setup Stack but will not install GHC and Cabal globally.'
2325
stack-setup-ghc:
2426
required: false
25-
description: 'If specified, enable-stack must be set. Will run stack setup to install the specified GHC.'
27+
default: false
28+
description: 'If set to `true`, will setup Stack. Will run `stack setup` to install the specified GHC.'
2629
cabal-update:
2730
required: false
2831
default: true
@@ -33,9 +36,14 @@ inputs:
3336
ghcup-release-channel:
3437
required: false
3538
description: "A release channel URL to add to ghcup via `ghcup config add-release-channel`."
39+
enable-matcher:
40+
required: false
41+
default: true
42+
description: 'Enable match messages from GHC as GitHub CI annotations.'
3643
disable-matcher:
3744
required: false
38-
description: 'If specified, disables match messages from GHC as GitHub CI annotations.'
45+
default: false
46+
description: 'Legacy input, use `enable-matcher` instead.'
3947
outputs:
4048
ghc-version:
4149
description: 'The resolved version of ghc'

dist/index.js

+69-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/opts.d.ts

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)