From 921b0b6e6b2a8da7388666e544cfa934157eedc7 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Fri, 19 May 2023 20:12:50 +0200 Subject: [PATCH] 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 https://github.com/haskell/actions/issues/248#issuecomment-1537117318 --- setup/README.md | 6 +++--- setup/__tests__/find-haskell.test.ts | 4 ++-- setup/dist/index.js | 6 +++++- setup/lib/opts.js | 6 +++++- setup/src/opts.ts | 6 +++++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/setup/README.md b/setup/README.md index 8b45a4de..2c59ba16 100644 --- a/setup/README.md +++ b/setup/README.md @@ -230,9 +230,9 @@ This list is replicated (hopefully correctly) below. Versions specified by the inputs, e.g. `ghc-version`, are resolved against this list, by taking the first entry from the list if `latest` is requested, -or the first entry that is a (string-)extension of the requested version otherwise. -E.g., `8.10` will be resolved to `8.10.7`, and so will `8.10.`, `8.` and `8` -(and incorrectly, [even `8.1`](github.com/haskell/actions/issues/248)). +or the first entry that matches exactly, +or otherwise the first entry that is a (string-)extension of the requested version extended by a `.`. +E.g., `8.10` will be resolved to `8.10.7`, and so will `8`. **GHC:** diff --git a/setup/__tests__/find-haskell.test.ts b/setup/__tests__/find-haskell.test.ts index acd91933..5aaa396e 100644 --- a/setup/__tests__/find-haskell.test.ts +++ b/setup/__tests__/find-haskell.test.ts @@ -96,13 +96,13 @@ describe('haskell/actions/setup', () => { }); }); - it('Versions resolve as string prefix (resolving 8.1 to 8.10.x should be considered a bug)', () => { + it('Versions resolve as version prefix', () => { const v = {ghc: '8.10.7', cabal: '2.4.1.0', stack: '2.1.3'}; forAllOS(os => { const options = getOpts(def(os), os, { 'enable-stack': 'true', 'stack-version': '2.1', - 'ghc-version': '8.1', + 'ghc-version': '8.10', 'cabal-version': '2' }); forAllTools(t => expect(options[t].resolved).toBe(v[t])); diff --git a/setup/dist/index.js b/setup/dist/index.js index c9523e55..c9dc01bc 100644 --- a/setup/dist/index.js +++ b/setup/dist/index.js @@ -13750,7 +13750,11 @@ function resolve(version, supported, tool, os, verbose // If resolution isn't th ) { const result = version === 'latest' ? supported[0] - : supported.find(v => v.startsWith(version)) ?? version; + : supported.find(v => v === version) ?? + supported.find(v => v.startsWith(version + '.')) ?? + // Andreas, 2023-05-19, issue #248 + // Append "." so that eg stack "2.1" resolves to "2.1.3" and not "2.11.1". + version; // Andreas 2022-12-29, issue #144: inform about resolution here where we can also output ${tool}. if (verbose === true && version !== result) core.info(`Resolved ${tool} ${version} to ${result}`); diff --git a/setup/lib/opts.js b/setup/lib/opts.js index 599f4ec0..fb933dec 100644 --- a/setup/lib/opts.js +++ b/setup/lib/opts.js @@ -84,7 +84,11 @@ function resolve(version, supported, tool, os, verbose // If resolution isn't th ) { const result = version === 'latest' ? supported[0] - : supported.find(v => v.startsWith(version)) ?? version; + : supported.find(v => v === version) ?? + supported.find(v => v.startsWith(version + '.')) ?? + // Andreas, 2023-05-19, issue #248 + // Append "." so that eg stack "2.1" resolves to "2.1.3" and not "2.11.1". + version; // Andreas 2022-12-29, issue #144: inform about resolution here where we can also output ${tool}. if (verbose === true && version !== result) core.info(`Resolved ${tool} ${version} to ${result}`); diff --git a/setup/src/opts.ts b/setup/src/opts.ts index 4fff340c..9fe2dc15 100644 --- a/setup/src/opts.ts +++ b/setup/src/opts.ts @@ -97,7 +97,11 @@ function resolve( const result = version === 'latest' ? supported[0] - : supported.find(v => v.startsWith(version)) ?? version; + : supported.find(v => v === version) ?? + supported.find(v => v.startsWith(version + '.')) ?? + // Andreas, 2023-05-19, issue #248 + // Append "." so that eg stack "2.1" resolves to "2.1.3" and not "2.11.1". + version; // Andreas 2022-12-29, issue #144: inform about resolution here where we can also output ${tool}. if (verbose === true && version !== result) core.info(`Resolved ${tool} ${version} to ${result}`);