diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..ce656d9b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: haskell-actions/setup@v2 + with: + ghc-version: "9.8.2" + cabal-version: "3.12.1.0" + + - run: | + cabal update + cabal build all + + tests: + name: Tests + runs-on: ubuntu-latest + needs: build + + steps: + - uses: actions/checkout@v4 + + - uses: haskell-actions/setup@v2 + with: + ghc-version: "9.8.2" + cabal-version: "3.12.1.0" + + - run: | + cabal update + cabal test all + + format-hs: + name: Haskell format + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: haskell-actions/setup@v2 + with: + ghc-version: "9.8.2" + cabal-version: "3.12.1.0" + + - name: Install ormolu + run: | + cabal install ormolu --overwrite-policy=always + echo "$HOME/.cabal/bin" >> "$GITHUB_PATH" + + - name: Check formatting + run: | + find . \ + -name '*.hs' \ + -not -path './dist-newstyle/*' \ + -not -path './runtimes/*' \ + -exec ormolu --mode check {} + + + prettier: + name: Prettier + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "20" + + - run: npm install --global prettier + + - run: prettier --check . --ignore-path .prettierignore diff --git a/cli/CLI/UI.hs b/cli/CLI/UI.hs index 915bb055..8820341a 100644 --- a/cli/CLI/UI.hs +++ b/cli/CLI/UI.hs @@ -4,23 +4,23 @@ module CLI.UI where +import CLI.AppEnv (ConfigLoadResult (clrWarning)) import Control.Concurrent (forkIO, threadDelay) import Control.Concurrent.MVar (MVar, newMVar, withMVar) import Control.Exception (SomeException, displayException, try) import Control.Monad (unless, when) import Data.Bits ((.|.)) import Data.Char (toLower) +import Data.Foldable (for_) import Data.IORef (IORef, atomicModifyIORef', modifyIORef', newIORef, readIORef, writeIORef) import Data.List (isInfixOf) import Data.Maybe (isNothing) -import Data.Foldable (for_) import Data.Text (Text) import Data.Text qualified as T import Data.Text.IO qualified as TIO import System.Environment (lookupEnv) -import System.Info (os) import System.IO (Handle, hFlush, hIsTerminalDevice, stdin, stdout) -import CLI.AppEnv (ConfigLoadResult (clrWarning)) +import System.Info (os) #if defined(mingw32_HOST_OS) import System.Win32.Console (eNABLE_PROCESSED_OUTPUT, eNABLE_VIRTUAL_TERMINAL_PROCESSING, getConsoleMode, setConsoleMode) import System.Win32.Types (withHandleToHANDLE) diff --git a/cli/Main.hs b/cli/Main.hs index 8d4b8d26..2df15e5e 100644 --- a/cli/Main.hs +++ b/cli/Main.hs @@ -3,20 +3,18 @@ module Main where import CLI.Commands -import CLI.Runtime (Runtime, mkRuntime) import CLI.Config qualified as Config import CLI.Download qualified as Download import CLI.Onboarding (runOnboarding) +import CLI.Runtime (Runtime, mkRuntime) import CLI.Submit qualified as Submit import Control.Exception (SomeException, try) -import Data.List (find) import Data.Version (showVersion) import GHC.IO.Encoding (utf8) import Options.Applicative import Options.Applicative.Help.Pretty (Doc, pretty, vsep) import Paths_openleetcode qualified -import System.Environment (getArgs, withArgs) -import System.Exit (exitWith, ExitCode (ExitFailure, ExitSuccess)) +import System.Exit (ExitCode (ExitFailure, ExitSuccess), exitWith) import System.IO (hSetEncoding, stderr, stdout) #if defined(mingw32_HOST_OS) import System.Win32.Console (setConsoleOutputCP) @@ -70,11 +68,16 @@ cliHelpFooter = initConsoleEncoding :: IO () initConsoleEncoding = do -#if defined(mingw32_HOST_OS) - do - _ <- try (setConsoleOutputCP 65001) :: IO (Either SomeException ()) - pure () -#endif + setupWindowsCP _ <- try (hSetEncoding stdout utf8) :: IO (Either SomeException ()) _ <- try (hSetEncoding stderr utf8) :: IO (Either SomeException ()) pure () + +setupWindowsCP :: IO () +#if defined(mingw32_HOST_OS) +setupWindowsCP = do + _ <- try (setConsoleOutputCP 65001) :: IO (Either SomeException ()) + pure () +#else +setupWindowsCP = pure () +#endif