Skip to content

Commit

Permalink
Merge pull request haskell#5 from haskell/updates
Browse files Browse the repository at this point in the history
Address most of the outstanding issues left over from the actions/setup-haskell -> haskell/actions/setup migration.
  • Loading branch information
Jared Weakly authored Dec 13, 2020
2 parents 6d69175 + 0dab3aa commit b60d27d
Show file tree
Hide file tree
Showing 12 changed files with 10,378 additions and 2,751 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,49 @@ jobs:
install-haskell:
name: GHC ${{ matrix.ghc }}, Cabal ${{ matrix.cabal }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.expect-fail }}
strategy:
fail-fast: false
fail-fast: true
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
ghc: ["latest", "8.4.4"]
cabal: ["latest"]
expect-fail: [false]
include:
- os: ubuntu-latest
ghc: "7.10.3"
cabal: "3.0.0.0"
expect-fail: false
- os: ubuntu-latest
ghc: "8.2.2"
cabal: "2.0"

expect-fail: false
- os: ubuntu-latest
ghc: "8.12.0" # A version that will never exist.
expect-fail: true
steps:
- uses: actions/checkout@v2
- uses: ./setup
continue-on-error: ${{ matrix.expect-fail }}
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- run: |
runhaskell --version
runhaskell __tests__/hello.hs
- shell: bash
run: cd __tests__/project && cabal build && cabal run
continue-on-error: ${{ matrix.expect-fail }}
- working-directory: setup/__tests__/project
run: cabal build
continue-on-error: ${{ matrix.expect-fail }}
- working-directory: setup/__tests__/project
run: cabal run
continue-on-error: ${{ matrix.expect-fail }}
- run: |
cabal --version
ghc --version
continue-on-error: ${{ matrix.expect-fail }}
- shell: bash
continue-on-error: ${{ matrix.expect-fail }}
if: matrix.ghc != 'latest'
# this check depends on the ghc versions being "exact" in the matrix
run: |
Expand All @@ -81,6 +95,7 @@ jobs:

steps:
- uses: actions/checkout@v2

- uses: ./setup
with:
enable-stack: true
Expand Down
11 changes: 7 additions & 4 deletions setup/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
'!(*test).{js,ts}': 'eslint --cache --fix',
'!(*test).ts': () => ['ncc build', 'git add dist'],
'src/**/*.ts': () => 'tsc -p tsconfig.json',
'*.{js,ts,json,md}': 'prettier --write'
'setup/!(*test).{js,ts,json}': [
'eslint --cache --fix',
() => 'ncc build',
() => 'git add dist'
],
'setup/src/**/*.ts': () => 'tsc -p tsconfig.json',
'setup/*.{js,ts,json,md}': 'prettier --write'
};
7 changes: 5 additions & 2 deletions setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ jobs:
**GHC:**

- `latest` (default, recommended)
- `8.10.1` `8.10`
- `8.10.2` `8.10`
- `8.10.1`
- `8.8.3` `8.8`
- `8.8.2`
- `8.8.1`
Expand Down Expand Up @@ -157,7 +158,9 @@ Recommendation: Use the latest available version if possible.
**Stack:**

- `latest` (recommended) -- follows the latest release automatically.
- `2.3.1` `2.3`
- `2.5.1` `2.5`
- `2.3.3` `2.3`
- `2.3.1`
- `2.1.3` `2.1`
- `2.1.1`
- `1.9.3.1` `1.9`
Expand Down
85 changes: 60 additions & 25 deletions setup/__tests__/find-haskell.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import {getOpts, getDefaults, Tool} from '../src/opts';
import {getOpts, getDefaults} from '../src/opts';
import type {OS, Revisions, Tool} from '../src/opts';
import {getInput} from '@actions/core';
import * as supported_versions from '../src/versions.json';
import * as rv from '../src/release-revisions.json';

const def = getDefaults();
const release_revisions = rv as Revisions;
const def = (os: OS) => getDefaults(os);
const latestVersions = {
ghc: supported_versions.ghc[0],
cabal: supported_versions.cabal[0],
stack: supported_versions.stack[0]
};
const latestRevisions = (os: OS) => ({
ghc: release_revisions?.[os]?.ghc?.[0]?.to,
cabal: release_revisions?.[os]?.cabal?.[0]?.to,
stack: release_revisions?.[os]?.stack?.[0]?.to
});

const mkName = (s: string): string =>
`INPUT_${s.replace(/ /g, '_').toUpperCase()}`;

const setupEnv = (o: Record<string, unknown>): void =>
Object.entries(o).forEach(([k, v]) => v && (process.env[mkName(k)] = `${v}`));

const forAll = (fn: (t: Tool) => any) =>
const forAllOS = (fn: (t: OS) => any) =>
(['win32', 'darwin', 'linux'] as const).forEach(fn);

const forAllTools = (fn: (t: Tool) => any) =>
(['ghc', 'cabal', 'stack'] as const).forEach(fn);

describe('haskell/actions/setup', () => {
Expand All @@ -30,11 +41,19 @@ describe('haskell/actions/setup', () => {
afterEach(() => (process.env = OLD_ENV));

it('Parses action.yml to get correct default versions', () => {
forAll(t => expect(def[t].version).toBe(latestVersions[t]));
forAllOS(os =>
forAllTools(t =>
expect(def(os)[t].version).toBe(
latestRevisions(os)[t] ?? latestVersions[t]
)
)
);
});

it('Supported versions are parsed from JSON correctly', () =>
forAll(t => expect(def[t].supported).toBe(supported_versions[t])));
forAllOS(os =>
forAllTools(t => expect(def(os)[t].supported).toBe(supported_versions[t]))
));

it('[meta] Setup Env works', () => {
setupEnv({input: 'value'});
Expand All @@ -44,58 +63,74 @@ describe('haskell/actions/setup', () => {

it('getOpts grabs defaults correctly from environment', () => {
setupEnv({});
const options = getOpts(def);
forAll(t => expect(options[t].raw).toBe(def[t].version));
forAllOS(os => {
const options = getOpts(def(os), os);
forAllTools(t => expect(options[t].raw).toBe(def(os)[t].version));
});
});

it('Versions resolve correctly', () => {
const v = {ghc: '8.6.5', cabal: '2.4.1.0', stack: '2.1.3'};
setupEnv({
'enable-stack': 'true',
'stack-version': '2.1',
'ghc-version': '8.6',
'cabal-version': '2.4'
});
const options = getOpts(def);
forAll(t => expect(options[t].resolved).toBe(v[t]));
forAllOS(os => {
const options = getOpts(def(os), os);
forAllTools(t => expect(options[t].resolved).toBe(v[t]));
});
});

it('"latest" Versions resolve correctly', () => {
setupEnv({
'enable-stack': 'true',
'stack-version': 'latest',
'ghc-version': 'latest',
'cabal-version': 'latest'
});
const options = getOpts(def);
forAll(t => expect(options[t].resolved).toBe(latestVersions[t]));
forAllOS(os => {
const options = getOpts(def(os), os);
forAllTools(t =>
expect(options[t].resolved).toBe(
latestRevisions(os)[t] ?? latestVersions[t]
)
);
});
});

it('Enabling stack does not disable GHC or Cabal', () => {
setupEnv({'enable-stack': 'true'});
const {ghc, cabal, stack} = getOpts(def);
expect({
ghc: ghc.enable,
stack: stack.enable,
cabal: cabal.enable
}).toStrictEqual({ghc: true, cabal: true, stack: true});
forAllOS(os => {
const {ghc, cabal, stack} = getOpts(def(os), os);
expect({
ghc: ghc.enable,
stack: stack.enable,
cabal: cabal.enable
}).toStrictEqual({ghc: true, cabal: true, stack: true});
});
});

it('Enabling stack-no-global disables GHC and Cabal', () => {
setupEnv({'enable-stack': 'true', 'stack-no-global': 'true'});
const {ghc, cabal, stack} = getOpts(def);
expect({
ghc: ghc.enable,
cabal: cabal.enable,
stack: stack.enable
}).toStrictEqual({ghc: false, cabal: false, stack: true});
forAllOS(os => {
const {ghc, cabal, stack} = getOpts(def(os), os);
expect({
ghc: ghc.enable,
cabal: cabal.enable,
stack: stack.enable
}).toStrictEqual({ghc: false, cabal: false, stack: true});
});
});

it('Enabling stack-no-global without setting enable-stack errors', () => {
setupEnv({'stack-no-global': 'true'});
expect(() => getOpts(def)).toThrow();
forAllOS(os => expect(() => getOpts(def(os), os)).toThrow());
});

it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
setupEnv({'stack-setup-ghc': 'true'});
expect(() => getOpts(def)).toThrow();
forAllOS(os => expect(() => getOpts(def(os), os)).toThrow());
});
});
Loading

0 comments on commit b60d27d

Please sign in to comment.