From f8495ed1b26eaa3f9f6ababdcbfdcb57cb250ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9cate=20Moonlight?= Date: Sat, 19 Nov 2022 14:13:32 +0100 Subject: [PATCH] Choose platform (#3) --- .github/workflows/ci.yml | 21 +++++++++------------ README.md | 3 +++ app/Main.hs | 18 ++++++++++++++++-- app/Types.hs | 9 +++++++++ get-tested.cabal | 6 ++---- 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 README.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a8c2a1..bb662c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,33 +7,30 @@ on: branches: ["main"] jobs: - generateMatrix: + generate-matrix: name: "Generate matrix from cabal" runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - name: Checkout base repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Extract the tested GHC versions id: set-matrix run: | - wget https://github.com/Kleidukos/get-tested/releases/download/v0.1.1.0/get-tested-0.1.1.0-linux-amd64 -O get-tested - chmod +x get-tested - ./get-tested get-tested.cabal >> $GITHUB_OUTPUT + echo "matrix={\"include\":[{\"ghc\":\"9.2.1\",\"os\":\"ubuntu-latest\"},{\"ghc\":\"9.2.2\",\"os\":\"ubuntu-latest\"},{\"ghc\":\"9.2.3\",\"os\":\"ubuntu-latest\"},{\"ghc\":\"9.2.4\",\"os\":\"ubuntu-latest\"},{\"ghc\":\"9.2.1\",\"os\":\"macos-latest\"},{\"ghc\":\"9.2.2\",\"os\":\"macos-latest\"},{\"ghc\":\"9.2.3\",\"os\":\"macos-latest\"},{\"ghc\":\"9.2.4\",\"os\":\"macos-latest\"}]}\n" >> $GITHUB_OUTPUT + # wget https://github.com/Kleidukos/get-tested/releases/download/v0.1.1.0/get-tested-0.1.1.0-linux-amd64 -O get-tested + # chmod +x get-tested + # ./get-tested get-tested.cabal >> $GITHUB_OUTPUT tests: name: ${{ matrix.ghc }} on ${{ matrix.os }} - needs: generateMatrix + needs: generate-matrix runs-on: ${{ matrix.os }} strategy: - matrix: ${{ fromJSON(needs.generateMatrix.outputs.matrix) }} + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} steps: - - name: "matrix output" - run: | - echo ${{ needs.generateMatrix.outputs.matrix }} - - name: Checkout base repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Haskell id: setup-haskell uses: haskell/actions/setup@v1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..49183d9 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# get-tested + +A CLI tool that retrieves the `tested-with` stanza of a cabal file and formats it in such a way that GitHub Actions can use it. diff --git a/app/Main.hs b/app/Main.hs index 41510b2..6646d09 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,6 +3,7 @@ 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 @@ -10,7 +11,12 @@ import Extract import Options.Applicative import Types -newtype Options = Options {path :: FilePath} +data Options = Options + { path :: FilePath + , macosFlag :: Bool + , ubuntuFlag :: Bool + , windowsFlag :: Bool + } deriving stock (Show, Eq) main :: IO () @@ -25,13 +31,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") runOptions :: Options -> Eff [Error ProcessingError, IOE] ByteString runOptions options = do genericPackageDescription <- loadFile options.path let supportedCompilers = extractTestedWith genericPackageDescription result = getVersions supportedCompilers - include = Vector.map (\version -> PlatformAndVersion "ubuntu-latest" version) result + 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")) + include = PlatformAndVersion <$> filteredList <*> result pure $ Aeson.encode $ ActionMatrix include withInfo :: Parser a -> String -> ParserInfo a diff --git a/app/Types.hs b/app/Types.hs index 3d00814..86d8fc6 100644 --- a/app/Types.hs +++ b/app/Types.hs @@ -10,6 +10,7 @@ import Data.Text qualified as Text import Data.Text.Display import Data.Text.Lazy.Builder qualified as Builder import Data.Vector (Vector) +import Data.Vector qualified as Vector import Distribution.Compiler import Distribution.Parsec (simpleParsec) import Distribution.Pretty qualified as Pretty @@ -59,6 +60,14 @@ data PlatformAndVersion = PlatformAndVersion deriving stock (Eq, Ord, Generic) deriving anyclass (ToJSON) +osList :: Vector Text +osList = + Vector.fromList + [ "ubuntu-latest" + , "macos-latest" + , "windows-latest" + ] + versionList :: Set Version versionList = Set.fromList diff --git a/get-tested.cabal b/get-tested.cabal index 3614dec..af4f7a0 100644 --- a/get-tested.cabal +++ b/get-tested.cabal @@ -1,6 +1,6 @@ cabal-version: 3.4 name: get-tested -version: 0.1.0.0 +version: 0.1.2.0 synopsis: Get the tested-with stanza of your Cabal file -- description: @@ -9,15 +9,13 @@ license: BSD-3-Clause license-file: LICENSE author: Hécate Moonlight maintainer: hecate+github@glitchbra.in -tested-with: GHC >=9.2 && <9.3 +tested-with: GHC ==9.2.4 -- copyright: category: Development build-type: Simple extra-doc-files: CHANGELOG.md --- extra-source-files: - executable get-tested main-is: Main.hs ghc-options: