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

Don't fall back to ppa:hvr/ghc, ghcup is sufficient in all cases #138

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This action sets up a Haskell environment for use in actions by:
- setting the outputs of `ghc-path`, `cabal-path`, `stack-path`, and `cabal-store` when necessary.

The GitHub runners come with [pre-installed versions of GHC and Cabal](https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners). Those will be used whenever possible.
For all other versions, this action utilizes [`ppa:hvr/ghc`](https://launchpad.net/~hvr/+archive/ubuntu/ghc), [`ghcup`](https://gitlab.haskell.org/haskell/ghcup-hs), and [`chocolatey`](https://chocolatey.org/packages/ghc).
For all other versions, this action utilizes [`ghcup`](https://gitlab.haskell.org/haskell/ghcup-hs), and [`chocolatey`](https://chocolatey.org/packages/ghc).

## Usage

Expand Down
21 changes: 2 additions & 19 deletions setup/dist/index.js

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

24 changes: 2 additions & 22 deletions setup/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ function warn(tool: Tool, version: string): void {
);
}

function aptVersion(tool: string, version: string): string {
// For Cabal, extract the first two segments of the version number. This
// regex is intentionally liberal to accomodate unusual cases like "head".
return tool === 'cabal' ? /[^.]*\.?[^.]*/.exec(version)![0] : version;
}

async function isInstalled(
tool: Tool,
version: string,
Expand All @@ -82,21 +76,19 @@ async function isInstalled(
const ghcupPath = `${process.env.HOME}/.ghcup${
tool === 'ghc' ? `/ghc/${version}` : ''
}/bin`;
const v = aptVersion(tool, version);
const aptPath = `/opt/${tool}/${v}/bin`;

const chocoPath = await getChocoPath(tool, version);

const locations = {
stack: [], // Always installed into the tool cache
cabal: {
win32: [chocoPath],
linux: [aptPath],
linux: [],
darwin: []
}[os],
ghc: {
win32: [chocoPath],
linux: [aptPath, ghcupPath],
linux: [ghcupPath],
darwin: [ghcupPath]
}[os]
};
Expand Down Expand Up @@ -162,8 +154,6 @@ export async function installTool(
await aptLibNCurses5();
}
await ghcup(tool, version, os);
if (await isInstalled(tool, version, os)) return;
await apt(tool, version);
break;
case 'win32':
await choco(tool, version);
Expand Down Expand Up @@ -245,16 +235,6 @@ async function aptLibNCurses5(): Promise<boolean> {
return returnCode === 0;
}

async function apt(tool: Tool, version: string): Promise<void> {
const toolName = tool === 'ghc' ? 'ghc' : 'cabal-install';
const v = aptVersion(tool, version);
core.info(`Attempting to install ${toolName} ${v} using apt-get`);
// Ignore the return code so we can fall back to ghcup
await exec(
`sudo -- sh -c "add-apt-repository -y ppa:hvr/ghc && apt-get update && apt-get -y install ${toolName}-${v}"`
);
}

async function choco(tool: Tool, version: string): Promise<void> {
core.info(`Attempting to install ${tool} ${version} using chocolatey`);
// Choco tries to invoke `add-path` command on earlier versions of ghc, which has been deprecated and fails the step, so disable command execution during this.
Expand Down