Skip to content

Commit

Permalink
Support explicit versions (#33)
Browse files Browse the repository at this point in the history
* Support explicit versions

* Add new inputs
  • Loading branch information
Kleidukos authored Mar 7, 2024
1 parent 3faac3b commit dceb7ef
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 21 deletions.
46 changes: 33 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
39 changes: 31 additions & 8 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
11 changes: 11 additions & 0 deletions app/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dceb7ef

Please sign in to comment.