Skip to content

Commit

Permalink
Parse multiline strings in main.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Jul 13, 2023
1 parent 0bcb5a2 commit 27aa12b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 56 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
# Any matrix combinations with latest-nightly should add the appropriate release channel
- plan:
ghc: latest-nightly
ghcup_release_channels: >
ghcup_release_channels: |
https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml
# Test deprecated release channel still works for now
Expand All @@ -110,10 +110,10 @@ jobs:

# Test ghcup release channels
- os: ubuntu-latest
ghcup_release_channels: >
https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.7.yaml,
https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml,
https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-vanilla-0.0.7.yaml,
ghcup_release_channels: |
https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.7.yaml
https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml
https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-vanilla-0.0.7.yaml
plan:
ghc: "9.6.0.20230111"
cabal: "3.8"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ Notes:
- `Toggle` inputs are booleans that are false when set as the empty string and true when set to _anything_.
However, to avoid confusion and for forward compatibility, it is still recommended to **only use value `true` to set a `Toggle` input.**

- Inputs that can take multiple values (like `ghcup-release-channels`) should be specified as a comma separated list, e.g.
- Inputs that can take multiple values (like `ghcup-release-channels`) should be specified as a multiline list, e.g.

```yaml
- uses: haskell-actions/setup@v2
with:
ghcup-release-channels: >
https://example.com/channel1,
https://example.com/channel2,
https://example.com/channel3,
ghcup-release-channels: |
https://example.com/channel1
https://example.com/channel2
https://example.com/channel3
```

## Outputs
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inputs:
# which are true as soon as they are not null.
ghcup-release-channels:
required: false
description: "Release channel URLs to add to ghcup via `ghcup config add-release-channel`."
description: "Release channel URLs to add to ghcup via `ghcup config add-release-channel`, as a multiline string"
ghcup-release-channel:
required: false
description: "Deprecated by ghcup-release-channels."
Expand Down
15 changes: 3 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13639,7 +13639,7 @@ const getToggleInput = (name) => core.getInput(name) !== '';
stackNoGlobal: getToggleInput('stack-no-global'),
stackSetupGhc: getToggleInput('stack-setup-ghc'),
cabalUpdate: core.getBooleanInput('cabal-update'),
ghcupReleaseChannels: core.getInput('ghcup-release-channels'),
ghcupReleaseChannels: core.getMultilineInput('ghcup-release-channels'),
ghcupReleaseChannel: core.getInput('ghcup-release-channel'),
disableMatcher: getToggleInput('disable-matcher')
});
Expand Down Expand Up @@ -13755,15 +13755,6 @@ function releaseRevision(version, tool, os) {
return result;
}
exports.releaseRevision = releaseRevision;
/**
* Parse a string as a comma-separated list.
*/
function parseCSV(val) {
return val
.split(',')
.map(s => s.trim())
.filter(s => s != '');
}
function getOpts({ ghc, cabal, stack }, os, inputs) {
core.debug(`Inputs are: ${JSON.stringify(inputs)}`);
const stackNoGlobal = inputs.stackNoGlobal ?? false;
Expand All @@ -13773,9 +13764,9 @@ function getOpts({ ghc, cabal, stack }, os, inputs) {
const matcherDisable = inputs.disableMatcher ?? false;
if (inputs.ghcupReleaseChannel) {
core.warning('ghcup-release-channel is deprecated in favor of ghcup-release-channels');
inputs.ghcupReleaseChannels = inputs.ghcupReleaseChannel;
inputs.ghcupReleaseChannels = [inputs.ghcupReleaseChannel];
}
const ghcupReleaseChannels = parseCSV(inputs.ghcupReleaseChannels ?? '').map(v => {
const ghcupReleaseChannels = (inputs.ghcupReleaseChannels ?? []).map(v => {
try {
return new URL(v);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/opts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export type RawInputs = {
stackNoGlobal?: boolean;
stackSetupGhc?: boolean;
cabalUpdate?: boolean;
ghcupReleaseChannels?: string;
ghcupReleaseChannels?: string[];
ghcupReleaseChannel?: string;
disableMatcher?: boolean;
};
Expand Down
13 changes: 2 additions & 11 deletions lib/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ function releaseRevision(version, tool, os) {
return result;
}
exports.releaseRevision = releaseRevision;
/**
* Parse a string as a comma-separated list.
*/
function parseCSV(val) {
return val
.split(',')
.map(s => s.trim())
.filter(s => s != '');
}
function getOpts({ ghc, cabal, stack }, os, inputs) {
core.debug(`Inputs are: ${JSON.stringify(inputs)}`);
const stackNoGlobal = inputs.stackNoGlobal ?? false;
Expand All @@ -120,9 +111,9 @@ function getOpts({ ghc, cabal, stack }, os, inputs) {
const matcherDisable = inputs.disableMatcher ?? false;
if (inputs.ghcupReleaseChannel) {
core.warning('ghcup-release-channel is deprecated in favor of ghcup-release-channels');
inputs.ghcupReleaseChannels = inputs.ghcupReleaseChannel;
inputs.ghcupReleaseChannels = [inputs.ghcupReleaseChannel];
}
const ghcupReleaseChannels = parseCSV(inputs.ghcupReleaseChannels ?? '').map(v => {
const ghcupReleaseChannels = (inputs.ghcupReleaseChannels ?? []).map(v => {
try {
return new URL(v);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ run({
stackNoGlobal: getToggleInput('stack-no-global'),
stackSetupGhc: getToggleInput('stack-setup-ghc'),
cabalUpdate: core.getBooleanInput('cabal-update'),
ghcupReleaseChannels: core.getInput('ghcup-release-channels'),
ghcupReleaseChannels: core.getMultilineInput('ghcup-release-channels'),
ghcupReleaseChannel: core.getInput('ghcup-release-channel'),
disableMatcher: getToggleInput('disable-matcher')
});
28 changes: 8 additions & 20 deletions src/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ export function releaseRevision(version: string, tool: Tool, os: OS): string {
return result;
}

/**
* Parse a string as a comma-separated list.
*/
function parseCSV(val: string): string[] {
return val
.split(',')
.map(s => s.trim())
.filter(s => s != '');
}

export type RawInputs = {
ghcVersion?: string;
cabalVersion?: string;
Expand All @@ -135,7 +125,7 @@ export type RawInputs = {
stackNoGlobal?: boolean;
stackSetupGhc?: boolean;
cabalUpdate?: boolean;
ghcupReleaseChannels?: string;
ghcupReleaseChannels?: string[];
ghcupReleaseChannel?: string;
disableMatcher?: boolean;
};
Expand All @@ -157,18 +147,16 @@ export function getOpts(
core.warning(
'ghcup-release-channel is deprecated in favor of ghcup-release-channels'
);
inputs.ghcupReleaseChannels = inputs.ghcupReleaseChannel;
inputs.ghcupReleaseChannels = [inputs.ghcupReleaseChannel];
}

const ghcupReleaseChannels = parseCSV(inputs.ghcupReleaseChannels ?? '').map(
v => {
try {
return new URL(v);
} catch (e) {
throw new TypeError(`Not a valid URL: ${v}`);
}
const ghcupReleaseChannels = (inputs.ghcupReleaseChannels ?? []).map(v => {
try {
return new URL(v);
} catch (e) {
throw new TypeError(`Not a valid URL: ${v}`);
}
);
});

core.debug(`${stackNoGlobal}/${stackSetupGhc}/${stackEnable}`);
const verInpt = {
Expand Down

0 comments on commit 27aa12b

Please sign in to comment.