Skip to content

Commit

Permalink
Choose platform (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleidukos authored Nov 19, 2022
1 parent e706eb3 commit f8495ed
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
21 changes: 9 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 16 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ 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 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 ()
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions get-tested.cabal
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -9,15 +9,13 @@ license: BSD-3-Clause
license-file: LICENSE
author: Hécate Moonlight
maintainer: [email protected]
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:
Expand Down

0 comments on commit f8495ed

Please sign in to comment.