From 27aa12be6b632dcc74946a66e47dfb4ce5df2c11 Mon Sep 17 00:00:00 2001 From: Brandon Chinn Date: Thu, 13 Jul 2023 09:13:50 -0700 Subject: [PATCH] Parse multiline strings in main.ts --- .github/workflows/workflow.yml | 10 +++++----- README.md | 10 +++++----- action.yml | 2 +- dist/index.js | 15 +++------------ lib/opts.d.ts | 2 +- lib/opts.js | 13 ++----------- src/main.ts | 2 +- src/opts.ts | 28 ++++++++-------------------- 8 files changed, 26 insertions(+), 56 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1b6f592..7f539ae 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 @@ -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" diff --git a/README.md b/README.md index e4f65a0..69e6eba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 0e05e8d..6f4c012 100644 --- a/action.yml +++ b/action.yml @@ -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." diff --git a/dist/index.js b/dist/index.js index da2a98c..aa01c0b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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') }); @@ -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; @@ -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); } diff --git a/lib/opts.d.ts b/lib/opts.d.ts index d43afda..573aab6 100644 --- a/lib/opts.d.ts +++ b/lib/opts.d.ts @@ -82,7 +82,7 @@ export type RawInputs = { stackNoGlobal?: boolean; stackSetupGhc?: boolean; cabalUpdate?: boolean; - ghcupReleaseChannels?: string; + ghcupReleaseChannels?: string[]; ghcupReleaseChannel?: string; disableMatcher?: boolean; }; diff --git a/lib/opts.js b/lib/opts.js index f26fab4..c1b9e09 100644 --- a/lib/opts.js +++ b/lib/opts.js @@ -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; @@ -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); } diff --git a/src/main.ts b/src/main.ts index 81eac9e..66b23c0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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') }); diff --git a/src/opts.ts b/src/opts.ts index 4ccd988..aab5548 100644 --- a/src/opts.ts +++ b/src/opts.ts @@ -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; @@ -135,7 +125,7 @@ export type RawInputs = { stackNoGlobal?: boolean; stackSetupGhc?: boolean; cabalUpdate?: boolean; - ghcupReleaseChannels?: string; + ghcupReleaseChannels?: string[]; ghcupReleaseChannel?: string; disableMatcher?: boolean; }; @@ -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 = {