Skip to content

Commit

Permalink
Add output ghc-version
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Dec 11, 2022
1 parent 45b39d0 commit e7a5e2b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ author: Simon Hengel
inputs:
ghc-version:
required: true

outputs:
ghc-version:
description: 'The installed GHC version.'

runs:
using: node16
main: dist/index.js
24 changes: 14 additions & 10 deletions dist/index.js

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

24 changes: 14 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ async function main() {
core.addPath(home + '/.cabal/bin/');
}
const requested = core.getInput('ghc-version');
if (requested === 'system') {
report();
} else {
const version = await install(requested);
await verify(version);
}
const version = await ensure(requested);
core.setOutput('ghc-version', version);
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
Expand All @@ -27,6 +23,18 @@ async function main() {
}
}

async function ensure(requested: string): Promise<string> {
if (requested === 'system') {
const version = installed();
core.info(`Using GHC version ${version}.`);
return version;
} else {
const version = await install(requested);
await verify(version);
return version;
}
}

async function install(requested: string): Promise<string> {
const resolved = await resolve(requested);
switch (resolved.source) {
Expand All @@ -48,10 +56,6 @@ async function verify(expected: string) {
core.info(`Installed GHC version ${expected}.`);
}

async function report() {
core.info(`Using GHC version ${await installed()}.`);
}

async function installed(): Promise<string> {
const result = await getExecOutput('ghc', ['--numeric-version'], {
silent: true,
Expand Down

0 comments on commit e7a5e2b

Please sign in to comment.