Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Fix #144: include <tool> in 'Resolved' info (#145)
Browse files Browse the repository at this point in the history
Fix #144: Instead of just printing e.g. `Resolved latest to 2.9.3`, print `Resolved stack latest to 2.9.3`.

E.g.: https://github.com/haskell/actions/actions/runs/3757986267/jobs/6385794767#step:3:7
```
Preparing to setup a Haskell environment
Resolved latest to 9.4.2
Resolved latest to 3.8.1.0
```

With this PR: https://github.com/haskell/actions/actions/runs/3794946311/jobs/6453551975#step:3:7
```
Preparing to setup a Haskell environment
Resolved ghc latest to 9.4.2
Resolved cabal latest to 3.8.1.0
```
  • Loading branch information
andreasabel committed Dec 28, 2022
1 parent cfcdd36 commit 04b033e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 41 deletions.
33 changes: 20 additions & 13 deletions setup/dist/index.js

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

33 changes: 20 additions & 13 deletions setup/lib/opts.js

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

50 changes: 35 additions & 15 deletions setup/src/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const yamlInputs: Record<string, {default: string}> = (

export function getDefaults(os: OS): Defaults {
const mkVersion = (v: string, vs: string[], t: Tool): Version => ({
version: resolve(yamlInputs[v].default, vs, t, os),
version: resolve(yamlInputs[v].default, vs, t, os, false), // verbose=false: no printout here
supported: vs
});

Expand All @@ -56,20 +56,25 @@ export function getDefaults(os: OS): Defaults {
};
}

// E.g. resolve ghc latest to 9.4.2
function resolve(
version: string,
supported: string[],
tool: Tool,
os: OS
os: OS,
verbose: boolean // If resolution isn't the identity, print what resolved to what.
): string {
const resolved =
version === 'latest'
? supported[0]
: supported.find(v => v.startsWith(version)) ?? version;
return (
const result =
release_revisions?.[os]?.[tool]?.find(({from}) => from === resolved)?.to ??
resolved
);
resolved;
// 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}`);
return result;
}

export function getOpts(
Expand Down Expand Up @@ -102,31 +107,46 @@ export function getOpts(
throw new Error(errors.join('\n'));
}

const ghcEnable = !stackNoGlobal;
const cabalEnable = !stackNoGlobal;
const opts: Options = {
ghc: {
raw: verInpt.ghc,
resolved: resolve(verInpt.ghc, ghc.supported, 'ghc', os),
enable: !stackNoGlobal
resolved: resolve(
verInpt.ghc,
ghc.supported,
'ghc',
os,
ghcEnable // if true: inform user about resolution
),
enable: ghcEnable
},
cabal: {
raw: verInpt.cabal,
resolved: resolve(verInpt.cabal, cabal.supported, 'cabal', os),
enable: !stackNoGlobal
resolved: resolve(
verInpt.cabal,
cabal.supported,
'cabal',
os,
cabalEnable // if true: inform user about resolution
),
enable: cabalEnable
},
stack: {
raw: verInpt.stack,
resolved: resolve(verInpt.stack, stack.supported, 'stack', os),
resolved: resolve(
verInpt.stack,
stack.supported,
'stack',
os,
stackEnable // if true: inform user about resolution
),
enable: stackEnable,
setup: stackSetupGhc
},
general: {matcher: {enable: !matcherDisable}}
};

// eslint-disable-next-line github/array-foreach
Object.values(opts)
.filter(t => t.enable && t.raw !== t.resolved)
.forEach(t => core.info(`Resolved ${t.raw} to ${t.resolved}`));

core.debug(`Options are: ${JSON.stringify(opts)}`);
return opts;
}

0 comments on commit 04b033e

Please sign in to comment.