From dceb7efc96f51620294402df0348a4f4d992149f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9cate=20Moonlight?= Date: Thu, 7 Mar 2024 12:18:09 +0100 Subject: [PATCH] Support explicit versions (#33) * Support explicit versions * Add new inputs --- action.yml | 46 +++++++++++++++++++++++++++++++++------------- app/Main.hs | 39 +++++++++++++++++++++++++++++++-------- app/Types.hs | 11 +++++++++++ 3 files changed, 75 insertions(+), 21 deletions(-) diff --git a/action.yml b/action.yml index e4b9167..2434a01 100644 --- a/action.yml +++ b/action.yml @@ -9,17 +9,29 @@ inputs: description: "Version of the tool" required: true windows: - description: "Enable Windows runner" + description: "(legacy) Enable Windows runner, latest version" required: false default: false + windows-version: + description: "Enable Windows runner. If both `windows` and `windows-version` inputs are set, the explicit version will take priority" + required: false + default: "" macos: - description: "Enable macOS runner" + description: "(legacy) Enable macOS runner, latest version" required: false default: false + macos-version: + description: "Enable macOS runner. If both `macos` and `macos-version` inputs are set, the explicit version will take priority" + required: false + default: "" ubuntu: - description: "Enable Ubuntu runner" + description: "(legacy) Enable Ubuntu runner, latest version" required: false default: false + ubuntu-version: + description: "Enable Ubuntu runner. If both `ubuntu` and `ubuntu-version` inputs are set, the explicit version will take priority" + required: false + default: "" outputs: matrix: @@ -34,23 +46,31 @@ runs: - name: Set up options shell: bash run: | - # Extract e.g. 0.1 from /runner/foo/bar/.../v0.1 wget -q https://github.com/Kleidukos/get-tested/releases/download/v${{ inputs.version }}/get-tested-${{ inputs.version }}-linux-amd64 -O get-tested chmod +x get-tested - echo "::debug:: Windows enabled: ${{ inputs.windows }}" - if [[ ${{ inputs.windows}} = "true" ]] - then echo "WINDOWS=--windows" >> $GITHUB_ENV + if [[ -n ${{ inputs.windows-version}} ]] + echo "::debug:: Windows explicit enabled: ${{ inputs.windows-version }}" + then echo "WINDOWS=\"--windows-version=${{ inputs.windows-version }}\"" >> $GITHUB_ENV + elif [[ ${{ inputs.windows }} == "true" ]] + echo "::debug:: Windows fallback enabled: ${{ inputs.windows }}" + then echo "WINDOWS=--windows" >> $GITHUB_ENV fi - echo "::debug:: macOS enabled: ${{ inputs.macos }}" - if [[ ${{ inputs.macos}} = "true" ]] - then echo "MACOS=--macos" >> $GITHUB_ENV + if [[ ${{ -n inputs.macos-version}} ]] + echo "::debug:: macOS explicit version enabled: ${{ inputs.macos-version }}" + then echo "MACOS=\"--macos-version=${{ inputs.macos-version }}\"" >> $GITHUB_ENV + elif [[ ${{ inputs.macos }} == "true" ]] + echo "::debug:: macOS fallback enabled: ${{ inputs.macos }}" + then echo "MACOS=--macos" >> $GITHUB_ENV fi - echo "::debug:: Ubuntu enabled: ${{ inputs.ubuntu }}" - if [[ ${{ inputs.ubuntu}} = "true" ]] - then echo "UBUNTU=--ubuntu" >> $GITHUB_ENV + if [[ ${{ -n inputs.ubuntu-version}} ]] + echo "::debug:: Ubuntu explicit version enabled: ${{ inputs.ubuntu-version }}" + then echo "UBUNTU=\"--ubuntu-version=${{ inputs.ubuntu-version }}\"" >> $GITHUB_ENV + elif [[ ${{ inputs.ubuntu }} == "true" ]] + echo "::debug:: Ubuntu fallback enabled: ${{ inputs.ubuntu }}" + then echo "UBUNTU=--ubuntu" >> $GITHUB_ENV fi - name: Extract the tested GHC versions diff --git a/app/Main.hs b/app/Main.hs index e050a7a..e0d64b4 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,21 +3,26 @@ module Main where import Data.Aeson qualified as Aeson import Data.ByteString.Lazy (ByteString) import Data.ByteString.Lazy.Char8 qualified as ByteString -import Data.Function ((&)) import Data.Vector qualified as Vector import Effectful import Effectful.Error.Static import Options.Applicative import System.Exit +import Data.Text (Text) +import Data.Text.Display (display) +import Data.Vector (Vector) import Extract import Types data Options = Options { path :: FilePath , macosFlag :: Bool + , macosVersion :: Maybe Text , ubuntuFlag :: Bool + , ubuntuVersion :: Maybe Text , windowsFlag :: Bool + , windowsVersion :: Maybe Text } deriving stock (Show, Eq) @@ -38,19 +43,21 @@ parseOptions :: Parser Options parseOptions = Options <$> argument str (metavar "FILE") - <*> switch (long "macos" <> help "Enable the macOS platform") - <*> switch (long "ubuntu" <> help "Enable the ubuntu platform") - <*> switch (long "windows" <> help "Enable the windows platform") + <*> switch (long "macos" <> help "(legacy) Enable the macOS runner's latest version") + <*> optional (strOption (long "macos-version" <> metavar "VERSION" <> help "Enable the macOS runner with the selected version")) + <*> switch (long "ubuntu" <> help "(legacy) Enable the Ubuntu runner's latest version") + <*> optional (strOption (long "ubuntu-version" <> metavar "VERSION" <> help "Enable the Ubuntu runner with the selected version")) + <*> switch (long "windows" <> help "(legacy) Enable the Windows runner's latest version") + <*> optional (strOption (long "windows-version" <> metavar "VERSION" <> help "Enable the Windows runner with the selected version")) runOptions :: Options -> Eff [Error ProcessingError, IOE] ByteString runOptions options = do genericPackageDescription <- loadFile options.path let supportedCompilers = extractTestedWith genericPackageDescription filteredList = - osList - & (if options.macosFlag then id else Vector.filter (/= "macos-latest")) - & (if options.windowsFlag then id else Vector.filter (/= "windows-latest")) - & (if options.ubuntuFlag then id else Vector.filter (/= "ubuntu-latest")) + processFlag MacOS options.macosFlag options.macosVersion + <> processFlag Ubuntu options.ubuntuFlag options.ubuntuVersion + <> processFlag Windows options.windowsFlag options.windowsVersion pure $ if null filteredList then Aeson.encode supportedCompilers @@ -60,3 +67,19 @@ runOptions options = do withInfo :: Parser a -> String -> ParserInfo a withInfo opts desc = info (helper <*> opts) $ progDesc desc + +processFlag + :: RunnerOS + -- ^ OS flag we're processing + -> Bool + -- ^ explicit version + -> Maybe Text + -- ^ legacy fallback + -> Vector Text +processFlag runnerOS legacyFallback mExplicitVersion = + case mExplicitVersion of + Just explicitVersion -> Vector.singleton (display runnerOS <> "-" <> explicitVersion) + Nothing -> + if legacyFallback + then Vector.singleton $ display runnerOS <> "-latest" + else Vector.empty diff --git a/app/Types.hs b/app/Types.hs index 0f51249..c816d9a 100644 --- a/app/Types.hs +++ b/app/Types.hs @@ -24,6 +24,17 @@ data ProcessingError (Display) via ShowInstance ProcessingError +data RunnerOS + = Ubuntu + | Windows + | MacOS + deriving stock (Eq, Ord, Show) + +instance Display RunnerOS where + displayBuilder Ubuntu = "ubuntu" + displayBuilder Windows = "windows" + displayBuilder MacOS = "macos" + instance ToJSON CompilerFlavor where toJSON = toJSON . Pretty.prettyShow