From 569449e8d91346bce8a30a4d8735acbb29623ccc Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 25 May 2026 13:49:42 +0300 Subject: [PATCH 1/4] add automated build and test workflow --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..94c6f3b0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: CI + +on: + push: + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Haskell + uses: haskell-actions/setup@v2 + with: + ghc-version: "9.8.2" + cabal-version: "3.12.1.0" + + - name: Build + run: | + cabal update + cabal build all + + - name: Test + run: cabal test all + + - name: Install ormolu + run: | + cabal install ormolu --overwrite-policy=always --installdir="$HOME/.cabal/bin" + echo "$HOME/.cabal/bin" >> "$GITHUB_PATH" + + - name: Check Haskell formatting + run: | + find . \ + -name '*.hs' \ + -not -path './dist-newstyle/*' \ + -not -path './runtimes/*' \ + -exec ormolu --mode check {} + + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Install Prettier + run: npm install --global prettier + + - name: Check formatting with Prettier + run: prettier --check . --ignore-path .prettierignore From 9be14d9f63d28de91954bdcd0343cacf06dfce47 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 25 May 2026 13:53:28 +0300 Subject: [PATCH 2/4] maybe more precisely --- .github/workflows/ci.yml | 62 +++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94c6f3b0..78288bdb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,33 +5,57 @@ on: pull_request: jobs: - check: + build: + name: Build runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Set up Haskell - uses: haskell-actions/setup@v2 + - uses: haskell-actions/setup@v2 with: ghc-version: "9.8.2" cabal-version: "3.12.1.0" - - name: Build - run: | + - run: | cabal update cabal build all - - name: Test - run: cabal test 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 --installdir="$HOME/.cabal/bin" + cabal install ormolu --overwrite-policy=always echo "$HOME/.cabal/bin" >> "$GITHUB_PATH" - - name: Check Haskell formatting + - name: Check formatting run: | find . \ -name '*.hs' \ @@ -39,13 +63,17 @@ jobs: -not -path './runtimes/*' \ -exec ormolu --mode check {} + - - name: Set up Node.js - uses: actions/setup-node@v4 + prettier: + name: Prettier + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 with: node-version: "20" - - name: Install Prettier - run: npm install --global prettier + - run: npm install --global prettier - - name: Check formatting with Prettier - run: prettier --check . --ignore-path .prettierignore + - run: prettier --check . --ignore-path .prettierignore From 859d537aec7cfb47185779dcb5f2d8262be8c36f Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 25 May 2026 13:54:18 +0300 Subject: [PATCH 3/4] main branch --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78288bdb..ce656d9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI on: push: + branches: + - main pull_request: jobs: From 9f1efe90064daa16d03062d6ed80dd086ff45788 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 25 May 2026 14:18:17 +0300 Subject: [PATCH 4/4] format --- cli/CLI/UI.hs | 6 +++--- cli/Main.hs | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) 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