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

New outputs ghc/cabal/stack-version (resolved versions) #249

Merged
merged 3 commits into from
May 6, 2023
Merged
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
13 changes: 11 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
- uses: actions/checkout@v3

- uses: ./setup
id: setup
with:
ghc-version: ${{ matrix.plan.ghc }}
ghcup-release-channel: ${{ matrix.ghcup_release_channel }}
Expand All @@ -152,6 +153,16 @@ jobs:
ghc --version
echo "$PATH"

- name: Confirm resolved and installed versions match
shell: bash
run: |
CABALVER="$(cabal --numeric-version)"
GHCVER="$(ghc --numeric-version)"
echo "CABALVER=${CABALVER}" >> "${GITHUB_ENV}"
echo "GHCVER=${GHCVER}" >> "${GITHUB_ENV}"
[[ "${CABALVER}" == "${{ steps.setup.outputs.cabal-version }}" ]] && \
[[ "${GHCVER}" == "${{ steps.setup.outputs.ghc-version }}" ]]

- name: Test runghc
run: |
runghc --version
Expand Down Expand Up @@ -185,8 +196,6 @@ jobs:
# - ghc: major and minor version
# pure bash startsWith
run: |
CABALVER="$(cabal --numeric-version)"
GHCVER="$(ghc --numeric-version)"
if [[ "${{ matrix.plan.cabal }}" =~ ^([0-9]+\.[0-9]+) ]]; then cabalmajor="${BASH_REMATCH[1]}"; fi
if [[ "${{ matrix.plan.ghc }}" =~ ^([0-9]+\.[0-9]+) ]]; then ghcmajor="${BASH_REMATCH[1]}"; fi
if [[ "${{ matrix.plan.ghc }}" =~ ^([0-9]+\.[0-9]+\.[0-9]+) ]]; then ghcver="${BASH_REMATCH[1]}"; fi
Expand Down
54 changes: 32 additions & 22 deletions setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This action sets up a Haskell environment for use in actions by:

- if requested, installing a version of [ghc](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/) and [cabal](https://www.haskell.org/cabal/) and adding them to `PATH`,
- if requested, installing a version of [Stack](https://haskellstack.org) and adding it to the `PATH`,
- outputting of `ghc-exe/path`, `cabal-exe/path`, `stack-exe/path`, `stack-root` and `cabal-store` (for the requested components).
- outputting of `ghc-version/exe/path`, `cabal-version/exe/path`, `stack-version/exe/path`, `stack-root` and `cabal-store` (for the requested components).

The GitHub runners come with [pre-installed versions of GHC and Cabal](https://github.com/actions/runner-images).
Those will be used whenever possible.
Expand Down Expand Up @@ -141,14 +141,6 @@ jobs:
cabal-version: 'latest'
cabal-update: true

- name: Installed minor versions of GHC and Cabal
shell: bash
run: |
GHC_VERSION=$(ghc --numeric-version)
CABAL_VERSION=$(cabal --numeric-version)
echo "GHC_VERSION=${GHC_VERSION}" >> "${GITHUB_ENV}"
echo "CABAL_VERSION=${CABAL_VERSION}" >> "${GITHUB_ENV}"

- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
Expand All @@ -158,11 +150,12 @@ jobs:
- name: Restore cached dependencies
uses: actions/cache/restore@v3
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: |
${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
run: cabal build all --only-dependencies
Expand Down Expand Up @@ -211,19 +204,36 @@ In contrast, a proper `boolean` input like `cabal-update` only accepts values `t

## Outputs

| Name | Description | Type |
| ------------- | -------------------------------------------------------------------------------------------------------------------------- | ------ |
| `ghc-path` | The path of the ghc executable _directory_ | string |
| `cabal-path` | The path of the cabal executable _directory_ | string |
| `stack-path` | The path of the stack executable _directory_ | string |
| `cabal-store` | The path to the cabal store | string |
| `stack-root` | The path to the stack root (equal to the `STACK_ROOT` environment variable if it is set; otherwise an OS-specific default) | string |
| `ghc-exe` | The path of the ghc _executable_ | string |
| `cabal-exe` | The path of the cabal _executable_ | string |
| `stack-exe` | The path of the stack _executable_ | string |
The action outputs parameters for the components it installed.
E.g. if `ghc-version: 8.10` is requested, the action will output `ghc-version: 8.10.7` if installation succeeded,
and `ghc-exe` and `ghc-path` will be set accordingly.
(Details on version resolution see next section.)

| Name | Description | Type |
| --------------- | -------------------------------------------------------------------------------------------------------------------------- | ------ |
| `ghc-version` | The resolved version of `ghc` | string |
| `cabal-version` | The resolved version of `cabal` | string |
| `stack-version` | The resolved version of `stack` | string |
| `ghc-exe` | The path of the `ghc` _executable_ | string |
| `cabal-exe` | The path of the `cabal` _executable_ | string |
| `stack-exe` | The path of the `stack` _executable_ | string |
| `ghc-path` | The path of the `ghc` executable _directory_ | string |
| `cabal-path` | The path of the `cabal` executable _directory_ | string |
| `stack-path` | The path of the `stack` executable _directory_ | string |
| `cabal-store` | The path to the cabal store | string |
| `stack-root` | The path to the stack root (equal to the `STACK_ROOT` environment variable if it is set; otherwise an OS-specific default) | string |

## Version Support

This action is conscious about the tool versions specified in [`versions.json`](src/versions.json).
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)).

**GHC:**

- `latest` (default)
Expand Down
19 changes: 16 additions & 3 deletions setup/__tests__/find-haskell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ describe('haskell/actions/setup', () => {
});

it('Versions resolve correctly', () => {
const v = {ghc: '8.6.5', cabal: '2.4.1.0', stack: '2.1.3'};
const v = {ghc: '8.6.5', cabal: '3.4.1.0', stack: '1.9.3'};
forAllOS(os => {
const options = getOpts(def(os), os, {
'enable-stack': 'true',
'stack-version': '2.1',
'stack-version': '1',
'ghc-version': '8.6',
'cabal-version': '2.4'
'cabal-version': '3.4'
});
forAllTools(t => expect(options[t].resolved).toBe(v[t]));
});
Expand All @@ -96,6 +96,19 @@ describe('haskell/actions/setup', () => {
});
});

it('Versions resolve as string prefix (resolving 8.1 to 8.10.x should be considered a bug)', () => {
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',
'cabal-version': '2'
});
forAllTools(t => expect(options[t].resolved).toBe(v[t]));
});
});

it('Enabling stack does not disable GHC or Cabal', () => {
forAllOS(os => {
const {ghc, cabal, stack} = getOpts(def(os), os, {
Expand Down
18 changes: 12 additions & 6 deletions setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ inputs:
required: false
description: 'If specified, disables match messages from GHC as GitHub CI annotations.'
outputs:
ghc-version:
description: 'The resolved version of ghc'
cabal-version:
description: 'The resolved version of cabal'
stack-version:
description: 'The resolved version of stack'
ghc-exe:
description: 'The path of the ghc _executable_'
cabal-exe:
description: 'The path of the cabal _executable_'
stack-exe:
description: 'The path of the stack _executable_'
ghc-path:
description: 'The path of the ghc executable _directory_'
cabal-path:
Expand All @@ -47,12 +59,6 @@ outputs:
description: 'The path to the cabal store'
stack-root:
description: 'The path to the stack root (equal to the STACK_ROOT environment variable if it is set; otherwise an OS-specific default)'
ghc-exe:
description: 'The path of the ghc _executable_'
cabal-exe:
description: 'The path of the cabal _executable_'
stack-exe:
description: 'The path of the stack _executable_'
runs:
using: 'node16'
main: 'dist/index.js'
6 changes: 4 additions & 2 deletions setup/dist/index.js

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

5 changes: 3 additions & 2 deletions setup/lib/installer.js

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

1 change: 1 addition & 0 deletions setup/lib/opts.js

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

4 changes: 3 additions & 1 deletion setup/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function failed(tool: Tool, version: string): void {

async function configureOutputs(
tool: Tool,
version: string,
path: string,
os: OS
): Promise<void> {
Expand All @@ -32,6 +33,7 @@ async function configureOutputs(
core.setOutput('stack-root', sr);
if (os === 'win32') core.exportVariable('STACK_ROOT', sr);
}
core.setOutput(`${tool}-version`, version);
}

async function success(
Expand All @@ -41,7 +43,7 @@ async function success(
os: OS
): Promise<true> {
core.addPath(path);
await configureOutputs(tool, path, os);
await configureOutputs(tool, version, path, os);
core.info(
`Found ${tool} ${version} in cache at path ${path}. Setup successful.`
);
Expand Down
1 change: 1 addition & 0 deletions setup/src/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function getDefaults(os: OS): Defaults {
}

// E.g. resolve ghc latest to 9.4.2
// resolve ghc 8.1 to 8.10.7 (bug, https://github.com/haskell/actions/issues/248)
function resolve(
version: string,
supported: string[],
Expand Down