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

Commit 2e698e5

Browse files
author
Jared Weakly
committed
Support transparent usage of patch versions for GHC on Windows
1 parent fa4f6cc commit 2e698e5

File tree

6 files changed

+282
-105
lines changed

6 files changed

+282
-105
lines changed

setup/.lintstagedrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
2-
'!(*test).{js,ts}': 'eslint --cache --fix',
3-
'!(*test).ts': () => ['ncc build', 'git add dist'],
2+
'!(*test).{js,ts}': [
3+
'eslint --cache --fix',
4+
() => 'ncc build',
5+
() => 'git add dist'
6+
],
47
'src/**/*.ts': () => 'tsc -p tsconfig.json',
58
'*.{js,ts,json,md}': 'prettier --write'
69
};
Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
import {getOpts, getDefaults, Tool} from '../src/opts';
1+
import {getOpts, getDefaults} from '../src/opts';
2+
import type {OS, Revisions, Tool} from '../src/opts';
23
import {getInput} from '@actions/core';
34
import * as supported_versions from '../src/versions.json';
5+
import * as rv from '../src/release-revisions.json';
46

5-
const def = getDefaults();
7+
const release_revisions = rv as Revisions;
8+
const def = (os: OS) => getDefaults(os);
69
const latestVersions = {
710
ghc: supported_versions.ghc[0],
811
cabal: supported_versions.cabal[0],
912
stack: supported_versions.stack[0]
1013
};
14+
const latestRevisions = (os: OS) => ({
15+
ghc: release_revisions?.[os]?.ghc?.[0]?.to,
16+
cabal: release_revisions?.[os]?.cabal?.[0]?.to,
17+
stack: release_revisions?.[os]?.stack?.[0]?.to
18+
});
1119

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

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

18-
const forAll = (fn: (t: Tool) => any) =>
26+
const forAllOS = (fn: (t: OS) => any) =>
27+
(['win32', 'darwin', 'linux'] as const).forEach(fn);
28+
29+
const forAllTools = (fn: (t: Tool) => any) =>
1930
(['ghc', 'cabal', 'stack'] as const).forEach(fn);
2031

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

3243
it('Parses action.yml to get correct default versions', () => {
33-
forAll(t => expect(def[t].version).toBe(latestVersions[t]));
44+
forAllOS(os =>
45+
forAllTools(t =>
46+
expect(def(os)[t].version).toBe(
47+
latestRevisions(os)[t] ?? latestVersions[t]
48+
)
49+
)
50+
);
3451
});
3552

3653
it('Supported versions are parsed from JSON correctly', () =>
37-
forAll(t => expect(def[t].supported).toBe(supported_versions[t])));
54+
forAllOS(os =>
55+
forAllTools(t => expect(def(os)[t].supported).toBe(supported_versions[t]))
56+
));
3857

3958
it('[meta] Setup Env works', () => {
4059
setupEnv({input: 'value'});
@@ -44,8 +63,10 @@ describe('haskell/actions/setup', () => {
4463

4564
it('getOpts grabs defaults correctly from environment', () => {
4665
setupEnv({});
47-
const options = getOpts(def);
48-
forAll(t => expect(options[t].raw).toBe(def[t].version));
66+
forAllOS(os => {
67+
const options = getOpts(def(os), os);
68+
forAllTools(t => expect(options[t].raw).toBe(def(os)[t].version));
69+
});
4970
});
5071

5172
it('Versions resolve correctly', () => {
@@ -55,8 +76,10 @@ describe('haskell/actions/setup', () => {
5576
'ghc-version': '8.6',
5677
'cabal-version': '2.4'
5778
});
58-
const options = getOpts(def);
59-
forAll(t => expect(options[t].resolved).toBe(v[t]));
79+
forAllOS(os => {
80+
const options = getOpts(def(os), os);
81+
forAllTools(t => expect(options[t].resolved).toBe(v[t]));
82+
});
6083
});
6184

6285
it('"latest" Versions resolve correctly', () => {
@@ -65,37 +88,47 @@ describe('haskell/actions/setup', () => {
6588
'ghc-version': 'latest',
6689
'cabal-version': 'latest'
6790
});
68-
const options = getOpts(def);
69-
forAll(t => expect(options[t].resolved).toBe(latestVersions[t]));
91+
forAllOS(os => {
92+
const options = getOpts(def(os), os);
93+
forAllTools(t =>
94+
expect(options[t].resolved).toBe(
95+
latestRevisions(os)[t] ?? latestVersions[t]
96+
)
97+
);
98+
});
7099
});
71100

72101
it('Enabling stack does not disable GHC or Cabal', () => {
73102
setupEnv({'enable-stack': 'true'});
74-
const {ghc, cabal, stack} = getOpts(def);
75-
expect({
76-
ghc: ghc.enable,
77-
stack: stack.enable,
78-
cabal: cabal.enable
79-
}).toStrictEqual({ghc: true, cabal: true, stack: true});
103+
forAllOS(os => {
104+
const {ghc, cabal, stack} = getOpts(def(os), os);
105+
expect({
106+
ghc: ghc.enable,
107+
stack: stack.enable,
108+
cabal: cabal.enable
109+
}).toStrictEqual({ghc: true, cabal: true, stack: true});
110+
});
80111
});
81112

82113
it('Enabling stack-no-global disables GHC and Cabal', () => {
83114
setupEnv({'enable-stack': 'true', 'stack-no-global': 'true'});
84-
const {ghc, cabal, stack} = getOpts(def);
85-
expect({
86-
ghc: ghc.enable,
87-
cabal: cabal.enable,
88-
stack: stack.enable
89-
}).toStrictEqual({ghc: false, cabal: false, stack: true});
115+
forAllOS(os => {
116+
const {ghc, cabal, stack} = getOpts(def(os), os);
117+
expect({
118+
ghc: ghc.enable,
119+
cabal: cabal.enable,
120+
stack: stack.enable
121+
}).toStrictEqual({ghc: false, cabal: false, stack: true});
122+
});
90123
});
91124

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

97130
it('Enabling stack-setup-ghc without setting enable-stack errors', () => {
98131
setupEnv({'stack-setup-ghc': 'true'});
99-
expect(() => getOpts(def)).toThrow();
132+
forAllOS(os => expect(() => getOpts(def(os), os)).toThrow());
100133
});
101134
});

0 commit comments

Comments
 (0)