Skip to content

Commit 9933312

Browse files
nlanderandreasabel
authored andcommitted
Use ghcup to install cabal head (#290)
This allows `head` to be the specified cabal version. Commits: * Use ghcup to install cabal head * Add cabal head to cabal-version description * Add cabal head test and check * Add cabal head to README supported versions * Use wildcard to check that version is prefix * Make sed version grabber cross platform
1 parent 751fcb7 commit 9933312

File tree

6 files changed

+106
-8
lines changed

6 files changed

+106
-8
lines changed

.github/workflows/workflow.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
# Latest releases
4949
- ghc: latest
5050
cabal: latest
51+
# Latest ghc with cabal head
52+
- ghc: latest
53+
cabal: head
5154
# Recommended releases (update according to ghcup)
5255
# 9.4 will be recommended soon
5356
- ghc: "9.4"
@@ -177,7 +180,17 @@ jobs:
177180
else
178181
GHCVER_EXPECTED="${{ steps.setup.outputs.ghc-version }}"
179182
fi
180-
[[ "${CABALVER}" == "${{ steps.setup.outputs.cabal-version }}" ]] && \
183+
if [[ "${{ steps.setup.outputs.cabal-version }}" == "head" ]]
184+
then
185+
CABALVER_EXPECTED=$( \
186+
curl --silent https://github.com/raw/haskell/cabal/master/cabal-install/cabal-install.cabal | \
187+
sed -E -n 's/^Version:[[:space:]]+//p' \
188+
)
189+
echo "Cabal head: ${CABALVER_EXPECTED}"
190+
else
191+
CABALVER_EXPECTED="${{ steps.setup.outputs.cabal-version }}"
192+
fi
193+
[[ "${CABALVER_EXPECTED}" == ${CABALVER}* ]] && \
181194
[[ "${GHCVER}" == "${GHCVER_EXPECTED}" ]]
182195
183196
- name: Test runghc

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Suggestion: Try to support at least the three latest major versions of GHC.
286286

287287
**Cabal:**
288288

289+
- `head` (the [cabal-head](https://github.com/haskell/cabal/releases/tag/cabal-head) release of the most recent build of the `master` branch)
289290
- `latest` (default, recommended)
290291
- `3.10.1.0` `3.10`
291292
- `3.8.1.0` `3.8`

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
default: 'latest'
99
cabal-version:
1010
required: false
11-
description: 'Version of Cabal to use. If set to "latest", it will always get the latest stable version.'
11+
description: 'Version of Cabal to use. If set to "latest", it will always get the latest stable version. If set to "head", it will always get the latest build of cabal.'
1212
default: 'latest'
1313
stack-version:
1414
required: false

dist/index.js

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/installer.js

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/installer.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,36 @@ export async function addGhcupReleaseChannel(
346346
async function ghcup(tool: Tool, version: string, os: OS): Promise<void> {
347347
core.info(`Attempting to install ${tool} ${version} using ghcup`);
348348
const bin = await ghcupBin(os);
349-
const returnCode = await exec(bin, ['install', tool, version]);
350-
if (returnCode === 0) await exec(bin, ['set', tool, version]);
349+
if (tool === 'cabal' && version === 'head') {
350+
await ghcupCabalHead(os, bin);
351+
} else {
352+
const returnCode = await exec(bin, ['install', tool, version]);
353+
if (returnCode === 0) await exec(bin, ['set', tool, version]);
354+
}
355+
}
356+
357+
function cabalHeadUrlTag(os: OS): string {
358+
switch (os) {
359+
case 'linux':
360+
return 'Linux';
361+
case 'darwin':
362+
return 'macOS';
363+
case 'win32':
364+
return 'Windows';
365+
}
366+
}
367+
368+
async function ghcupCabalHead(os: OS, bin: string): Promise<void> {
369+
const osTag = cabalHeadUrlTag(os);
370+
const cabalHeadUrl = `https://github.com/haskell/cabal/releases/download/cabal-head/cabal-head-${osTag}-x86_64.tar.gz`;
371+
const returnCode = await exec(bin, [
372+
'install',
373+
'cabal',
374+
'-u',
375+
cabalHeadUrl,
376+
'head'
377+
]);
378+
if (returnCode === 0) await exec(bin, ['set', 'cabal', 'head']);
351379
}
352380

353381
async function ghcupGHCHead(): Promise<void> {

0 commit comments

Comments
 (0)