Skip to content

Commit da38471

Browse files
committed
Fix #248: resolve stack "2.1" to "2.1.3" rather than "2.11.1"
Fix taken from https://github.com/hspec/setup-haskell/blob/bdd4c910d94a07946cfdf9e6c3e7299a7e123705/src/resolve.ts#L25 as recommended by @sol in haskell/actions#248 (comment)
1 parent cf7abe1 commit da38471

5 files changed

Lines changed: 20 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ This list is replicated (hopefully correctly) below.
230230

231231
Versions specified by the inputs, e.g. `ghc-version`, are resolved against this list,
232232
by taking the first entry from the list if `latest` is requested,
233-
or the first entry that is a (string-)extension of the requested version otherwise.
234-
E.g., `8.10` will be resolved to `8.10.7`, and so will `8.10.`, `8.` and `8`
235-
(and incorrectly, [even `8.1`](github.com/haskell/actions/issues/248)).
233+
or the first entry that matches exactly,
234+
or otherwise the first entry that is a (string-)extension of the requested version extended by a `.`.
235+
E.g., `8.10` will be resolved to `8.10.7`, and so will `8`.
236236

237237
**GHC:**
238238

__tests__/find-haskell.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ describe('haskell/actions/setup', () => {
9696
});
9797
});
9898

99-
it('Versions resolve as string prefix (resolving 8.1 to 8.10.x should be considered a bug)', () => {
99+
it('Versions resolve as version prefix', () => {
100100
const v = {ghc: '8.10.7', cabal: '2.4.1.0', stack: '2.1.3'};
101101
forAllOS(os => {
102102
const options = getOpts(def(os), os, {
103103
'enable-stack': 'true',
104104
'stack-version': '2.1',
105-
'ghc-version': '8.1',
105+
'ghc-version': '8.10',
106106
'cabal-version': '2'
107107
});
108108
forAllTools(t => expect(options[t].resolved).toBe(v[t]));

dist/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13750,7 +13750,11 @@ function resolve(version, supported, tool, os, verbose // If resolution isn't th
1375013750
) {
1375113751
const result = version === 'latest'
1375213752
? supported[0]
13753-
: supported.find(v => v.startsWith(version)) ?? version;
13753+
: supported.find(v => v === version) ??
13754+
supported.find(v => v.startsWith(version + '.')) ??
13755+
// Andreas, 2023-05-19, issue #248
13756+
// Append "." so that eg stack "2.1" resolves to "2.1.3" and not "2.11.1".
13757+
version;
1375413758
// Andreas 2022-12-29, issue #144: inform about resolution here where we can also output ${tool}.
1375513759
if (verbose === true && version !== result)
1375613760
core.info(`Resolved ${tool} ${version} to ${result}`);

lib/opts.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ function resolve(version, supported, tool, os, verbose // If resolution isn't th
8484
) {
8585
const result = version === 'latest'
8686
? supported[0]
87-
: supported.find(v => v.startsWith(version)) ?? version;
87+
: supported.find(v => v === version) ??
88+
supported.find(v => v.startsWith(version + '.')) ??
89+
// Andreas, 2023-05-19, issue #248
90+
// Append "." so that eg stack "2.1" resolves to "2.1.3" and not "2.11.1".
91+
version;
8892
// Andreas 2022-12-29, issue #144: inform about resolution here where we can also output ${tool}.
8993
if (verbose === true && version !== result)
9094
core.info(`Resolved ${tool} ${version} to ${result}`);

src/opts.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ function resolve(
9797
const result =
9898
version === 'latest'
9999
? supported[0]
100-
: supported.find(v => v.startsWith(version)) ?? version;
100+
: supported.find(v => v === version) ??
101+
supported.find(v => v.startsWith(version + '.')) ??
102+
// Andreas, 2023-05-19, issue #248
103+
// Append "." so that eg stack "2.1" resolves to "2.1.3" and not "2.11.1".
104+
version;
101105
// Andreas 2022-12-29, issue #144: inform about resolution here where we can also output ${tool}.
102106
if (verbose === true && version !== result)
103107
core.info(`Resolved ${tool} ${version} to ${result}`);

0 commit comments

Comments
 (0)