From 3f010e16c82422d0539c7d0033b7151cb660636b Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Sat, 30 Nov 2024 16:01:04 +0800 Subject: [PATCH 01/14] [ ci ] Setup Haskell environment on all platforms --- .github/workflows/test-linux.yaml | 12 ++++------ .github/workflows/test-mac.yaml | 19 ++++----------- .github/workflows/test-windows.yaml | 36 +++++++++++++++-------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/.github/workflows/test-linux.yaml b/.github/workflows/test-linux.yaml index 22cc3b2..e581eb1 100644 --- a/.github/workflows/test-linux.yaml +++ b/.github/workflows/test-linux.yaml @@ -4,7 +4,7 @@ name: CI (Linux) on: push: - branches: [master, ci-*] + branches: [master, ci-*, ci] tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 pull_request: @@ -18,10 +18,12 @@ jobs: - name: ๐Ÿ“ฅ Checkout repository uses: actions/checkout@v4 - - name: Determine stack resolver + - name: ๐Ÿ” Determine stack resolver & GHC run: | STACK_RESOLVER=$(yq .resolver stack.yaml) + GHC_VERSION=$(yq .compiler stack.yaml) echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" # things to be restored: # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. @@ -55,12 +57,6 @@ jobs: # if [[ ! -x ~/.local/bin/stack ]]; then curl -sL https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'; chmod a+x ~/.local/bin/stack; fi stack --version - - name: โฌ Install GHC - run: | - df -h - stack setup --install-ghc - df -h - - name: โฌ Install dependencies run: | stack build --only-dependencies diff --git a/.github/workflows/test-mac.yaml b/.github/workflows/test-mac.yaml index 59c9233..93d8c1c 100644 --- a/.github/workflows/test-mac.yaml +++ b/.github/workflows/test-mac.yaml @@ -18,10 +18,12 @@ jobs: - name: ๐Ÿ“ฅ Checkout repository uses: actions/checkout@v4 - - name: ๐Ÿ” Determine stack resolver + - name: ๐Ÿ” Determine stack resolver & GHC run: | STACK_RESOLVER=$(yq .resolver stack.yaml) + GHC_VERSION=$(yq .compiler stack.yaml) echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" # things to be restored: # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. @@ -54,23 +56,10 @@ jobs: uses: haskell-actions/setup@v2 id: setup-haskell with: - ghc-version: '9.2.8' + ghc-version: ${{ env.GHC_VERSION }} enable-stack: true stack-version: 'latest' - # - name: โฌ Install stack - # run: | - # # mkdir -p ~/.local/bin - # # export PATH=~/.local/bin:$PATH - # ## Stack is preinstalled on the GHA runners - # # brew install gnu-tar; curl -sL https://get.haskellstack.org/stable/osx-x86_64.tar.gz | gtar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'; chmod a+x ~/.local/bin/stack - # # if [[ ! -x ~/.local/bin/stack ]]; then brew install gnu-tar; curl -sL https://get.haskellstack.org/stable/osx-x86_64.tar.gz | gtar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'; chmod a+x ~/.local/bin/stack; fi - # stack --version - - # - name: โฌ Install GHC - # run: | - # stack setup --install-ghc - - name: โฌ Install dependencies run: | stack build --only-dependencies diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml index 356fda5..6fd8a26 100644 --- a/.github/workflows/test-windows.yaml +++ b/.github/workflows/test-windows.yaml @@ -25,7 +25,7 @@ jobs: - name: ๐Ÿ— Install yq uses: frenck/action-setup-yq@v1 - - name: Determine stack root and resolver + - name: ๐Ÿ” Determine stack root and resolver and GHC ## 2023-11-21 https://github.com/commercialhaskell/stack/issues/6340 ## Asking stack for the stack root unfortunately does not work ## if stack is not fully operational (meaning e.g. that GHC is installed) @@ -33,8 +33,10 @@ jobs: run: | STACK_ROOT="C:/Users/runneradmin/AppData/Local/Programs/stack/x86_64-windows" STACK_RESOLVER=$(yq .resolver stack.yaml) + GHC_VERSION=$(yq .compiler stack.yaml) echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" # run: | # STACK_ROOT="$(stack --system-ghc --no-install-ghc path --stack-root || echo "C:/Users/runneradmin/AppData/Local/Programs/stack/x86_64-windows")" # echo "STACK_ROOT = ${STACK_ROOT}" @@ -64,22 +66,22 @@ jobs: # actions - - name: โฌ Install stack - ## Stack is preinstalled on GHA runners. - # - #if: steps.stack-programs-dir.outputs.cache-hit != 'true' - # this step is needed to get stack.exe into PATH, for now - # curl -sL https://get.haskellstack.org/stable/windows-x86_64.zip -o stack.zip - # 7z x stack.zip stack.exe - run: | - which stack - stack --version - - - name: โฌ Install GHC - # if: steps.stack-programs-dir.outputs.cache-hit != 'true' - # set PATH=C:\Users\runneradmin\AppData\Local\Programs\stack\local\bin;%PATH% - run: | - stack --no-terminal setup --install-ghc + # - name: โฌ Install stack + # ## Stack is preinstalled on GHA runners. + # # + # #if: steps.stack-programs-dir.outputs.cache-hit != 'true' + # # this step is needed to get stack.exe into PATH, for now + # # curl -sL https://get.haskellstack.org/stable/windows-x86_64.zip -o stack.zip + # # 7z x stack.zip stack.exe + # run: | + # which stack + # stack --version + + # - name: โฌ Install GHC + # # if: steps.stack-programs-dir.outputs.cache-hit != 'true' + # # set PATH=C:\Users\runneradmin\AppData\Local\Programs\stack\local\bin;%PATH% + # run: | + # stack --no-terminal setup --install-ghc - name: Install the icu library run: | From df3b47b684d0249563bc254fd21583db96cefd9a Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Sat, 30 Nov 2024 16:05:15 +0800 Subject: [PATCH 02/14] [ ci ] Grep only the digits from the GHC version --- .github/workflows/test-linux.yaml | 19 +++++++++---------- .github/workflows/test-mac.yaml | 2 +- .github/workflows/test-windows.yaml | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-linux.yaml b/.github/workflows/test-linux.yaml index e581eb1..6c5606d 100644 --- a/.github/workflows/test-linux.yaml +++ b/.github/workflows/test-linux.yaml @@ -21,7 +21,7 @@ jobs: - name: ๐Ÿ” Determine stack resolver & GHC run: | STACK_RESOLVER=$(yq .resolver stack.yaml) - GHC_VERSION=$(yq .compiler stack.yaml) + GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" @@ -48,15 +48,14 @@ jobs: # actions: - - name: โฌ Install stack - run: | - # mkdir -p ~/.local/bin - # export PATH=~/.local/bin:$PATH - ## Stack is preinstalled on the GHA runners - # curl -sL https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'; chmod a+x ~/.local/bin/stack - # if [[ ! -x ~/.local/bin/stack ]]; then curl -sL https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'; chmod a+x ~/.local/bin/stack; fi - stack --version - + - name: โฌ Setup Haskell + uses: haskell-actions/setup@v2 + id: setup-haskell + with: + ghc-version: ${{ env.GHC_VERSION }} + enable-stack: true + stack-version: 'latest' + - name: โฌ Install dependencies run: | stack build --only-dependencies diff --git a/.github/workflows/test-mac.yaml b/.github/workflows/test-mac.yaml index 93d8c1c..e7cfad6 100644 --- a/.github/workflows/test-mac.yaml +++ b/.github/workflows/test-mac.yaml @@ -21,7 +21,7 @@ jobs: - name: ๐Ÿ” Determine stack resolver & GHC run: | STACK_RESOLVER=$(yq .resolver stack.yaml) - GHC_VERSION=$(yq .compiler stack.yaml) + GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml index 6fd8a26..8858cbb 100644 --- a/.github/workflows/test-windows.yaml +++ b/.github/workflows/test-windows.yaml @@ -4,7 +4,7 @@ name: CI (Windows) on: push: - branches: [master, ci-*] + branches: [master, ci-*, ci] tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 pull_request: @@ -33,7 +33,7 @@ jobs: run: | STACK_ROOT="C:/Users/runneradmin/AppData/Local/Programs/stack/x86_64-windows" STACK_RESOLVER=$(yq .resolver stack.yaml) - GHC_VERSION=$(yq .compiler stack.yaml) + GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" From b4b5b295aab2857b3d3a891188d0bee04c0a4642 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Tue, 3 Dec 2024 14:34:02 +0800 Subject: [PATCH 03/14] [ new ] LSP testing for agda-mode:load --- agda-language-server.cabal | 4 +++- package.yaml | 1 + src/Agda.hs | 3 +++ stack.yaml | 1 + stack.yaml.lock | 7 +++++++ test/Test.hs | 8 +++++++- test/Test/LSP.hs | 39 ++++++++++++++++++++++++++++++++++++++ test/data/A.agda | 4 ++++ 8 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/Test/LSP.hs create mode 100644 test/data/A.agda diff --git a/agda-language-server.cabal b/agda-language-server.cabal index d9f18a4..4f46620 100644 --- a/agda-language-server.cabal +++ b/agda-language-server.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: agda-language-server -version: 0.2.6.4.3.0 +version: 0.2.7.0.1.0 synopsis: An implementation of language server protocal (LSP) for Agda 2. description: Please see the README on GitHub at category: Development @@ -171,6 +171,7 @@ test-suite als-test type: exitcode-stdio-1.0 main-is: Test.hs other-modules: + Test.LSP Test.SrcLoc Agda Agda.Convert @@ -216,6 +217,7 @@ test-suite als-test , directory , filepath , lsp >=2 + , lsp-test , lsp-types >=2 , mtl , network diff --git a/package.yaml b/package.yaml index 3ef3ac6..67abbf7 100644 --- a/package.yaml +++ b/package.yaml @@ -130,6 +130,7 @@ tests: - test - src dependencies: + - lsp-test - tasty - tasty-hunit - tasty-golden diff --git a/src/Agda.hs b/src/Agda.hs index 9a5e614..f44c4b8 100644 --- a/src/Agda.hs +++ b/src/Agda.hs @@ -8,6 +8,8 @@ module Agda , runAgda , sendCommand , getCommandLineOptions + , CommandReq(..) + , CommandRes(..) ) where import Prelude hiding ( null ) @@ -251,6 +253,7 @@ data CommandReq | CmdReq String deriving (Generic) +instance ToJSON CommandReq instance FromJSON CommandReq data CommandRes diff --git a/stack.yaml b/stack.yaml index 4009418..03c7f87 100644 --- a/stack.yaml +++ b/stack.yaml @@ -10,6 +10,7 @@ extra-deps: - Agda-2.7.0.1 - lsp-2.7.0.0@sha256:2a64b40a69fd9638056ca552d5660203019473061cff1d09dccc0c94e40a275c,3834 - lsp-types-2.3.0.0@sha256:ca17a686bda5dc7ff04105ca7081dce5a90bcd050c8800a13efd68b7f0901f1c,34215 +- lsp-test-0.17.1.0@sha256:f54757a564b46783cf67b13f4cb4ebc45e43f5afc3604d9757ee387c091b73e9,4406 - mod-0.2.0.1@sha256:eeb316fef3a8c12f4e83bbeeea748e74d75fca54d4498d574ace92e464adb05a,2409 - row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071 diff --git a/stack.yaml.lock b/stack.yaml.lock index a23b31e..77bcfbc 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -25,6 +25,13 @@ packages: size: 51996 original: hackage: lsp-types-2.3.0.0@sha256:ca17a686bda5dc7ff04105ca7081dce5a90bcd050c8800a13efd68b7f0901f1c,34215 +- completed: + hackage: lsp-test-0.17.1.0@sha256:f54757a564b46783cf67b13f4cb4ebc45e43f5afc3604d9757ee387c091b73e9,4406 + pantry-tree: + sha256: 66797a8efd50812189c410310dc0a9b72858ea3a3e78764e9cedd8f406df2564 + size: 1561 + original: + hackage: lsp-test-0.17.1.0@sha256:f54757a564b46783cf67b13f4cb4ebc45e43f5afc3604d9757ee387c091b73e9,4406 - completed: hackage: mod-0.2.0.1@sha256:eeb316fef3a8c12f4e83bbeeea748e74d75fca54d4498d574ace92e464adb05a,2409 pantry-tree: diff --git a/test/Test.hs b/test/Test.hs index 3effac0..1b02182 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1,4 +1,7 @@ +module Test where + import qualified Test.SrcLoc as SrcLoc +import qualified Test.LSP as LSP import Test.Tasty ( TestTree , defaultMain , testGroup @@ -8,4 +11,7 @@ main :: IO () main = defaultMain tests tests :: TestTree -tests = testGroup "Tests" [SrcLoc.tests] +tests = testGroup "Tests" + [SrcLoc.tests, + LSP.tests + ] diff --git a/test/Test/LSP.hs b/test/Test/LSP.hs new file mode 100644 index 0000000..c21ea97 --- /dev/null +++ b/test/Test/LSP.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE OverloadedStrings #-} +module Test.LSP (tests) where + +import Control.Applicative.Combinators +import Control.Monad.IO.Class +import Language.LSP.Protocol.Message +import Language.LSP.Protocol.Types +import Language.LSP.Test +import Test.Tasty +import Test.Tasty.HUnit +import qualified Data.Aeson as JSON +import Switchboard ( agdaCustomMethod ) +import Agda + +tests :: TestTree +tests = + testGroup + "LSP" + [ testCase "load" demo + ] + +demo :: IO () +demo = runSession "als" fullLatestClientCaps "test/data/" $ do + doc <- openDoc "A.agda" "agda" + + -- Use your favourite favourite combinators. + -- skipManyTill loggingNotification (count 1 publishDiagnosticsNotification) + + testCustomMethod "IOTCM \"test/data/A.agdaa\" NonInteractive Direct( Cmd_load \"test/data/A.agda\" [] )" + + -- Or use one of the helper functions + -- getDocumentSymbols doc >>= liftIO . print + +-- | Sends a custom method request to the server and expects a response of `CmdRes Nothing` +testCustomMethod :: String -> Session () +testCustomMethod cmd = do + TResponseMessage _ _ rsp <- request agdaCustomMethod $ + JSON.toJSON $ CmdReq cmd + liftIO $ rsp @?= Right (JSON.toJSON (CmdRes Nothing)) \ No newline at end of file diff --git a/test/data/A.agda b/test/data/A.agda new file mode 100644 index 0000000..c5ff8e5 --- /dev/null +++ b/test/data/A.agda @@ -0,0 +1,4 @@ +module A where + +data โŠค : Set where + tt : โŠค \ No newline at end of file From 3266f71b7c3e31518611731610d9c535e2523d49 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Tue, 3 Dec 2024 16:21:07 +0800 Subject: [PATCH 04/14] [ new ] Allow path of ALS to be passed into the test suite --- test/Test.hs | 37 +++++++++++++++++++++++++------------ test/Test/LSP.hs | 11 ++++++----- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/test/Test.hs b/test/Test.hs index 1b02182..f16831d 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1,17 +1,30 @@ -module Test where +import Data.Proxy (Proxy (..)) +import Data.Typeable (Typeable) +import qualified Test.LSP as LSP +import qualified Test.SrcLoc as SrcLoc +import Test.Tasty +import Test.Tasty.Options -import qualified Test.SrcLoc as SrcLoc -import qualified Test.LSP as LSP -import Test.Tasty ( TestTree - , defaultMain - , testGroup - ) +-- Define the custom option +newtype AlsPathOption = AlsPathOption FilePath + deriving (Show, Typeable) + +instance IsOption AlsPathOption where + defaultValue = AlsPathOption "als" + parseValue = Just . AlsPathOption + optionName = return "als-path" + optionHelp = return "Path to the als executable" main :: IO () -main = defaultMain tests +main = do + let opts = [Option (Proxy :: Proxy AlsPathOption)] + ingredients = includingOptions opts : defaultIngredients + defaultMainWithIngredients ingredients tests tests :: TestTree -tests = testGroup "Tests" - [SrcLoc.tests, - LSP.tests - ] +tests = askOption $ \(AlsPathOption alsPath) -> + testGroup + "Tests" + [ SrcLoc.tests, + LSP.tests alsPath + ] \ No newline at end of file diff --git a/test/Test/LSP.hs b/test/Test/LSP.hs index c21ea97..023ca77 100644 --- a/test/Test/LSP.hs +++ b/test/Test/LSP.hs @@ -12,15 +12,16 @@ import qualified Data.Aeson as JSON import Switchboard ( agdaCustomMethod ) import Agda -tests :: TestTree -tests = +tests :: FilePath -> TestTree +tests alsPath = testGroup "LSP" - [ testCase "load" demo + [ testCase "load" (demo alsPath) ] -demo :: IO () -demo = runSession "als" fullLatestClientCaps "test/data/" $ do +demo :: FilePath -> IO () +demo alsPath = + runSession alsPath fullLatestClientCaps "test/data/" $ do doc <- openDoc "A.agda" "agda" -- Use your favourite favourite combinators. From cc318c424d821a0aa29c63fe8c92762a8b08d824 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Tue, 3 Dec 2024 17:08:07 +0800 Subject: [PATCH 05/14] [ ci ] Trying to merge test-linux.yaml with test-mac.yaml --- .github/workflows/test-linux.yaml | 3 +- .github/workflows/test-unix.yaml | 227 ++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-unix.yaml diff --git a/.github/workflows/test-linux.yaml b/.github/workflows/test-linux.yaml index 6c5606d..94fd5b2 100644 --- a/.github/workflows/test-linux.yaml +++ b/.github/workflows/test-linux.yaml @@ -4,7 +4,8 @@ name: CI (Linux) on: push: - branches: [master, ci-*, ci] + branches: [master] + # branches: [master, ci-*, ci] tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 pull_request: diff --git a/.github/workflows/test-unix.yaml b/.github/workflows/test-unix.yaml new file mode 100644 index 0000000..3d2e561 --- /dev/null +++ b/.github/workflows/test-unix.yaml @@ -0,0 +1,227 @@ +# modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/linux.yml + +name: CI (Unix) + +on: + push: + branches: [master, ci-*, ci] + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + pull_request: + branches: [master] + +jobs: + build-and-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + fail-fast: false + steps: + + - name: ๐Ÿ“ฅ Checkout repository + uses: actions/checkout@v4 + + - name: ๐Ÿ” Determine stack resolver & GHC + run: | + STACK_RESOLVER=$(yq .resolver stack.yaml) + GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) + echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" + + # things to be restored: + # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. + + - name: ๐Ÿ’พ Restore cached stack global package db + id: stack-global + uses: actions/cache/restore@v4 + with: + path: ~/.stack + key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} + restore-keys: | + ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global + + - name: ๐Ÿ’พ Restore cached .stack-work + id: stack-work + uses: actions/cache/restore@v4 + with: + path: .stack-work + key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} + restore-keys: | + ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work + + # actions: + - name: Set PKG_CONFIG_PATH for the ICU library (on macOS) + if: runner.os == 'macOS' + run: | + echo PKG_CONFIG_PATH="$(brew --prefix)/opt/icu4c/lib/pkgconfig" >> "${GITHUB_ENV}" + + - name: โฌ Setup Haskell + uses: haskell-actions/setup@v2 + id: setup-haskell + with: + ghc-version: ${{ env.GHC_VERSION }} + enable-stack: true + stack-version: 'latest' + + - name: โฌ Install dependencies + run: | + stack build + + - name: ๐Ÿ”จ Build and run tests + run: | + stack test + + # things to be cached + + - name: ๐Ÿ’พ Cache stack global package db + if: always() && steps.stack-global.outputs.cache-hit != 'true' + uses: actions/cache/save@v3 + with: + path: ~/.stack + key: ${{ steps.stack-global.outputs.cache-primary-key }} + + - name: ๐Ÿ’พ Cache .stack-work + if: always() && steps.stack-work.outputs.cache-hit != 'true' + uses: actions/cache/save@v3 + with: + path: .stack-work + key: ${{ steps.stack-work.outputs.cache-primary-key }} + + + - name: ๐Ÿ”— Bundle ICU4C DLLs (on macOS) + if: runner.os == 'macOS' + run: | # Bundle icu4c DLLs + + # see if icu4c has been installed + if [ "$(brew list | grep icu4c)" = "" ] + then + echo "installing icu4c" + brew install icu4c + fi + + # get the directory of the DDLs we want (icuuc, icui18n, icudata) + dylib_dir=$(dirname "$(brew list icu4c | grep icuuc.dylib)") + echo "dylib_dir: $dylib_dir" + + # find the path of "als" + executable=$(find "$(stack path --local-install-root)"/bin -name "als") + echo "executable: $executable" + + # remove the old dylib, and make a new one + rm -rf dylib + mkdir dylib + + ################################################################################ + # icuuc + ################################################################################ + + icuuc_id=$(otool -L "$executable" | grep icuuc | awk '{print $1}') + icuuc_id_basename=$(basename "$icuuc_id") + + icuuc_path=$dylib_dir/$icuuc_id_basename + icuuc_path_new=dylib/$icuuc_id_basename + icuuc_id_new=@loader_path/dylib/$icuuc_id_basename + + # copy icuuc to the new directory + cp "$icuuc_path" "$icuuc_path_new" + + # change icuuc's ID referenced by ALS + install_name_tool -change "$icuuc_id" "$icuuc_id_new" "$executable" + + echo "icuuc referenced by ALS" + echo " old ID : $icuuc_id" + echo " new ID : $icuuc_id_new" + echo " old path: $icuuc_path" + echo " new path: $icuuc_path_new" + + ################################################################################ + # icui18n + ################################################################################ + + icui18n_id=$(otool -L "$executable" | grep icui18n | awk '{print $1}') + icui18n_id_basename=$(basename "$icui18n_id") + + icui18n_path=$dylib_dir/$icui18n_id_basename + icui18n_path_new=dylib/$icui18n_id_basename + icui18n_id_new=@loader_path/dylib/$icui18n_id_basename + + # copy icui18n to the new directory + cp "$icui18n_path" "$icui18n_path_new" + + # change icui18n's ID referenced by ALS + install_name_tool -change "$icui18n_id" "$icui18n_id_new" "$executable" + + echo "icui18n referenced by ALS" + echo " old ID : $icui18n_id" + echo " new ID : $icui18n_id_new" + echo " old path: $icui18n_path" + echo " new path: $icui18n_path_new" + + ################################################################################ + # icudata + ################################################################################ + + # otool -L "$icui18n_id" | grep icudata | awk '{print $1}' + icudata_id=$(otool -L "$icuuc_path" | grep icudata | awk '{print $1}') + icudata_id_basename=$(basename "$icudata_id") + + icudata_path=$dylib_dir/$icudata_id_basename + icudata_path_new=dylib/$icudata_id_basename + + # copy icudata to the new directory + cp "$icudata_path" "$icudata_path_new" + + # no need of changing the ID because supposely it's already of "@loader_path" + + echo "icudata referenced by icuuc" + echo " old ID : $icudata_id" + echo " old path : $icudata_path" + echo " new path : $icudata_path_new" + + + - name: ๐Ÿ“ฆ Compress files + id: zip + run: | + # locate the data-dir + datadir=$(find "$(stack path --snapshot-install-root)/share" -type d -name "Agda-*") + echo "datadir: $datadir" + + # locate the executable + executable=$(find "$(stack path --local-install-root)/bin" -name "als") + echo "executable: $executable" + + # make a temporary directory for compresssing + mkdir zip + cp -r "$datadir" zip/data + if [[ ${{ runner.os }} == "macOS" ]]; then + cp -r dylib zip/dylib + fi + cp "$executable" zip/ + + # compress + if [[ ${{ runner.os }} == "Linux" ]]; then + cd zip + zip -r als-ubuntu.zip ./* + cd .. + mv zip/als-ubuntu.zip . + fi + if [[ ${{ runner.os }} == "macOS" ]]; then + cd zip + zip -r als-macos.zip ./* + cd .. + mv zip/als-macos.zip . + fi + + - name: ๐Ÿ”จ Build and run tests + run: | + + stack test --ta --als-path=zip/als + + # release (optional) + - name: ๐Ÿšข Release Artifacts + if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ github.ref_name }} als-ubuntu.zip --clobber From aaaad2fed1cd50f2bd011411bc350632152b194f Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 01:07:17 +0800 Subject: [PATCH 06/14] [ ci ] Remove hardcoded Stack root on Windows --- .github/workflows/test-linux.yaml | 111 --------------- .github/workflows/test-mac.yaml | 203 ---------------------------- .github/workflows/test-unix.yaml | 24 ++-- .github/workflows/test-windows.yaml | 56 +++----- 4 files changed, 33 insertions(+), 361 deletions(-) delete mode 100644 .github/workflows/test-linux.yaml delete mode 100644 .github/workflows/test-mac.yaml diff --git a/.github/workflows/test-linux.yaml b/.github/workflows/test-linux.yaml deleted file mode 100644 index 94fd5b2..0000000 --- a/.github/workflows/test-linux.yaml +++ /dev/null @@ -1,111 +0,0 @@ -# modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/linux.yml - -name: CI (Linux) - -on: - push: - branches: [master] - # branches: [master, ci-*, ci] - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - pull_request: - branches: [master] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - - name: ๐Ÿ“ฅ Checkout repository - uses: actions/checkout@v4 - - - name: ๐Ÿ” Determine stack resolver & GHC - run: | - STACK_RESOLVER=$(yq .resolver stack.yaml) - GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) - echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" - echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" - - # things to be restored: - # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. - - - name: ๐Ÿ’พ Restore cached stack global package db - id: stack-global - uses: actions/cache/restore@v3 - with: - path: ~/.stack - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} - restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global - - - name: ๐Ÿ’พ Restore cached .stack-work - id: stack-work - uses: actions/cache/restore@v3 - with: - path: .stack-work - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} - restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work - - # actions: - - - name: โฌ Setup Haskell - uses: haskell-actions/setup@v2 - id: setup-haskell - with: - ghc-version: ${{ env.GHC_VERSION }} - enable-stack: true - stack-version: 'latest' - - - name: โฌ Install dependencies - run: | - stack build --only-dependencies - - - name: ๐Ÿ”จ Build and run tests - run: | - stack test - - # things to be cached - - - name: ๐Ÿ’พ Cache stack global package db - if: always() && steps.stack-global.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 - with: - path: ~/.stack - key: ${{ steps.stack-global.outputs.cache-primary-key }} - - - name: ๐Ÿ’พ Cache .stack-work - if: always() && steps.stack-work.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 - with: - path: .stack-work - key: ${{ steps.stack-work.outputs.cache-primary-key }} - - # release (optional) - - - name: ๐Ÿ“ฆ Compress files - id: zip - run: | - # locate the data-dir - datadir=$(find "$(stack path --snapshot-install-root)/share" -type d -name "Agda-*") - - # locate the executable - executable=$(find "$(stack path --local-install-root)/bin" -name "als") - - # make a temporary directory for compresssing - mkdir zip - cp -r "$datadir" zip/data - cp "$executable" zip/ - - # compress - cd zip - zip -r als-ubuntu.zip ./* - cd .. - mv zip/als-ubuntu.zip . - - - name: ๐Ÿšข Release Artifacts - if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload ${{ github.ref_name }} als-ubuntu.zip --clobber diff --git a/.github/workflows/test-mac.yaml b/.github/workflows/test-mac.yaml deleted file mode 100644 index e7cfad6..0000000 --- a/.github/workflows/test-mac.yaml +++ /dev/null @@ -1,203 +0,0 @@ -# modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/mac.yml - -name: CI (macOS) - -on: - push: - branches: [master, ci-*, ci] - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - pull_request: - branches: [master] - -jobs: - build: - runs-on: macos-latest - steps: - - - name: ๐Ÿ“ฅ Checkout repository - uses: actions/checkout@v4 - - - name: ๐Ÿ” Determine stack resolver & GHC - run: | - STACK_RESOLVER=$(yq .resolver stack.yaml) - GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) - echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" - echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" - - # things to be restored: - # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. - - - name: ๐Ÿ’พ Restore cached stack global package db - id: stack-global - uses: actions/cache/restore@v3 - with: - path: ~/.stack - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} - restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global - - - name: ๐Ÿ’พ Restore cached .stack-work - id: stack-work - uses: actions/cache/restore@v3 - with: - path: .stack-work - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} - restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work - - # actions: - - - name: Set PKG_CONFIG_PATH for the ICU library - run: | - echo PKG_CONFIG_PATH="$(brew --prefix)/opt/icu4c/lib/pkgconfig" >> "${GITHUB_ENV}" - - - name: โฌ Setup Haskell - uses: haskell-actions/setup@v2 - id: setup-haskell - with: - ghc-version: ${{ env.GHC_VERSION }} - enable-stack: true - stack-version: 'latest' - - - name: โฌ Install dependencies - run: | - stack build --only-dependencies - - - name: ๐Ÿ”จ Build and run tests - run: | - stack test - - # things to be cached - - - name: ๐Ÿ’พ Cache stack global package db - if: always() && steps.stack-global.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 - with: - path: ~/.stack - key: ${{ steps.stack-global.outputs.cache-primary-key }} - - - name: ๐Ÿ’พ Cache .stack-work - if: always() && steps.stack-work.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 - with: - path: .stack-work - key: ${{ steps.stack-work.outputs.cache-primary-key }} - - # release (optional) - - - name: ๐Ÿ”— Bundle ICU4C DLLs - run: | # Bundle icu4c DLLs - - # see if icu4c has been installed - if [ "$(brew list | grep icu4c)" = "" ] - then - echo "installing icu4c" - brew install icu4c - fi - - # get the directory of the DDLs we want (icuuc, icui18n, icudata) - dylib_dir=$(dirname "$(brew list icu4c | grep icuuc.dylib)") - - # find the path of "als" - executable=$(find "$(stack path --local-install-root)"/bin -name "als") - - # remove the old dylib, and make a new one - rm -rf dylib - mkdir dylib - - ################################################################################ - # icuuc - ################################################################################ - - icuuc_id=$(otool -L "$executable" | grep icuuc | awk '{print $1}') - icuuc_id_basename=$(basename "$icuuc_id") - - icuuc_path=$dylib_dir/$icuuc_id_basename - icuuc_path_new=dylib/$icuuc_id_basename - icuuc_id_new=@loader_path/dylib/$icuuc_id_basename - - # copy icuuc to the new directory - cp "$icuuc_path" "$icuuc_path_new" - - # change icuuc's ID referenced by ALS - install_name_tool -change "$icuuc_id" "$icuuc_id_new" "$executable" - - echo "icuuc referenced by ALS" - echo " old ID : $icuuc_id" - echo " new ID : $icuuc_id_new" - echo " old path: $icuuc_path" - echo " new path: $icuuc_path_new" - - ################################################################################ - # icui18n - ################################################################################ - - icui18n_id=$(otool -L "$executable" | grep icui18n | awk '{print $1}') - icui18n_id_basename=$(basename "$icui18n_id") - - icui18n_path=$dylib_dir/$icui18n_id_basename - icui18n_path_new=dylib/$icui18n_id_basename - icui18n_id_new=@loader_path/dylib/$icui18n_id_basename - - # copy icui18n to the new directory - cp "$icui18n_path" "$icui18n_path_new" - - # change icui18n's ID referenced by ALS - install_name_tool -change "$icui18n_id" "$icui18n_id_new" "$executable" - - echo "icui18n referenced by ALS" - echo " old ID : $icui18n_id" - echo " new ID : $icui18n_id_new" - echo " old path: $icui18n_path" - echo " new path: $icui18n_path_new" - - ################################################################################ - # icudata - ################################################################################ - - # otool -L "$icui18n_id" | grep icudata | awk '{print $1}' - icudata_id=$(otool -L "$icuuc_path" | grep icudata | awk '{print $1}') - icudata_id_basename=$(basename "$icudata_id") - - icudata_path=$dylib_dir/$icudata_id_basename - icudata_path_new=dylib/$icudata_id_basename - - # copy icudata to the new directory - cp "$icudata_path" "$icudata_path_new" - - # no need of changing the ID because supposely it's already of "@loader_path" - - echo "icudata referenced by icuuc" - echo " old ID : $icudata_id" - echo " old path : $icudata_path" - echo " new path : $icudata_path_new" - - - - name: ๐Ÿ“ฆ Compress files - id: zip - run: | - # locate the data-dir - datadir=$(find "$(stack path --snapshot-install-root)/share" -type d -name "Agda-*") - - # locate the executable - executable=$(find "$(stack path --local-install-root)/bin" -name "als") - - # make a temporary directory for compresssing - mkdir zip - cp -r "$datadir" zip/data - cp -r dylib zip/dylib - cp "$executable" zip/ - - # compress - cd zip - zip -r als-macos.zip ./* - cd .. - mv zip/als-macos.zip . - - - name: ๐Ÿšข Release Artifacts - if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload ${{ github.ref_name }} als-macos.zip --clobber diff --git a/.github/workflows/test-unix.yaml b/.github/workflows/test-unix.yaml index 3d2e561..5d101d0 100644 --- a/.github/workflows/test-unix.yaml +++ b/.github/workflows/test-unix.yaml @@ -22,8 +22,12 @@ jobs: - name: ๐Ÿ“ฅ Checkout repository uses: actions/checkout@v4 + - name: ๐Ÿ— Install yq + uses: frenck/action-setup-yq@v1 + - name: ๐Ÿ” Determine stack resolver & GHC run: | + STACK_ROOT="$(stack path --stack-root)" STACK_RESOLVER=$(yq .resolver stack.yaml) GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" @@ -36,7 +40,7 @@ jobs: id: stack-global uses: actions/cache/restore@v4 with: - path: ~/.stack + path: ${{ env.STACK_ROOT }} key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} restore-keys: | ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global @@ -64,26 +68,24 @@ jobs: enable-stack: true stack-version: 'latest' - - name: โฌ Install dependencies - run: | - stack build + - name: ๐Ÿ”จ Build + run: stack build - - name: ๐Ÿ”จ Build and run tests - run: | - stack test + - name: ๐Ÿงช Run tests + run: stack test # things to be cached - name: ๐Ÿ’พ Cache stack global package db if: always() && steps.stack-global.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 + uses: actions/cache/save@v4 with: - path: ~/.stack + path: ${{ env.STACK_ROOT }} key: ${{ steps.stack-global.outputs.cache-primary-key }} - name: ๐Ÿ’พ Cache .stack-work if: always() && steps.stack-work.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 + uses: actions/cache/save@v4 with: path: .stack-work key: ${{ steps.stack-work.outputs.cache-primary-key }} @@ -215,7 +217,7 @@ jobs: - name: ๐Ÿ”จ Build and run tests run: | - + stack test --ta --als-path=zip/als # release (optional) diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml index 8858cbb..77485c3 100644 --- a/.github/workflows/test-windows.yaml +++ b/.github/workflows/test-windows.yaml @@ -26,12 +26,8 @@ jobs: uses: frenck/action-setup-yq@v1 - name: ๐Ÿ” Determine stack root and resolver and GHC - ## 2023-11-21 https://github.com/commercialhaskell/stack/issues/6340 - ## Asking stack for the stack root unfortunately does not work - ## if stack is not fully operational (meaning e.g. that GHC is installed) - ## so we hardcode its location instead. run: | - STACK_ROOT="C:/Users/runneradmin/AppData/Local/Programs/stack/x86_64-windows" + STACK_ROOT="$(stack path --stack-root)" STACK_RESOLVER=$(yq .resolver stack.yaml) GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" @@ -48,7 +44,7 @@ jobs: - name: ๐Ÿ’พ Restore cached stack global package db id: stack-global - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 with: path: ${{ env.STACK_ROOT }} key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} @@ -57,7 +53,7 @@ jobs: - name: ๐Ÿ’พ Restore cached .stack-work id: stack-work - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 with: path: .stack-work key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} @@ -65,57 +61,44 @@ jobs: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work # actions + - name: Install the icu library + run: | + stack exec -- pacman -S --noconfirm mingw-w64-x86_64-icu mingw-w64-x86_64-pkgconf - # - name: โฌ Install stack - # ## Stack is preinstalled on GHA runners. - # # - # #if: steps.stack-programs-dir.outputs.cache-hit != 'true' - # # this step is needed to get stack.exe into PATH, for now - # # curl -sL https://get.haskellstack.org/stable/windows-x86_64.zip -o stack.zip - # # 7z x stack.zip stack.exe + # - name: ๐Ÿ“ธ Build Snapshot # run: | - # which stack - # stack --version + # stack build --no-terminal --only-snapshot -j1 - # - name: โฌ Install GHC - # # if: steps.stack-programs-dir.outputs.cache-hit != 'true' - # # set PATH=C:\Users\runneradmin\AppData\Local\Programs\stack\local\bin;%PATH% + # - name: ๐Ÿงฐ Build Dependencies # run: | - # stack --no-terminal setup --install-ghc - - - name: Install the icu library - run: | - stack exec -- pacman -S --noconfirm mingw-w64-x86_64-icu mingw-w64-x86_64-pkgconf + # stack build --no-terminal --only-dependencies - - name: ๐Ÿ“ธ Build Snapshot - run: | - stack build --no-terminal --only-snapshot -j1 + # - name: ๐Ÿ”จ Build and run tests + # run: | + # stack test - - name: ๐Ÿงฐ Build Dependencies - run: | - stack build --no-terminal --only-dependencies + - name: ๐Ÿ”จ Build + run: stack build - - name: ๐Ÿ”จ Build and run tests - run: | - stack test + - name: ๐Ÿงช Run tests + run: stack test # things to be cached - name: ๐Ÿ’พ Cache stack global package db if: always() && steps.stack-global.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 + uses: actions/cache/save@v4 with: path: ${{ env.STACK_ROOT }} key: ${{ steps.stack-global.outputs.cache-primary-key }} - name: ๐Ÿ’พ Cache .stack-work if: always() && steps.stack-work.outputs.cache-hit != 'true' - uses: actions/cache/save@v3 + uses: actions/cache/save@v4 with: path: .stack-work key: ${{ steps.stack-work.outputs.cache-primary-key }} - # release (optional) # artifacts: - name: ๐Ÿ“ฆ Compress executable and data files @@ -148,6 +131,7 @@ jobs: cd .. mv zip/als-windows.zip . + # release (optional) - name: ๐Ÿšข Release Artifacts if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts env: From d244592b5f3a85cb3f78edd20ebdc02b0893e929 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 02:02:48 +0800 Subject: [PATCH 07/14] [ ci ] Remove hardcoded Stack root on Unix --- .github/workflows/test-unix.yaml | 65 +++++++++++++++++++++-------- .github/workflows/test-windows.yaml | 55 ++++++++++++++---------- 2 files changed, 79 insertions(+), 41 deletions(-) diff --git a/.github/workflows/test-unix.yaml b/.github/workflows/test-unix.yaml index 5d101d0..183bec5 100644 --- a/.github/workflows/test-unix.yaml +++ b/.github/workflows/test-unix.yaml @@ -2,6 +2,10 @@ name: CI (Unix) +defaults: + run: + shell: bash + on: push: branches: [master, ci-*, ci] @@ -22,16 +26,30 @@ jobs: - name: ๐Ÿ“ฅ Checkout repository uses: actions/checkout@v4 - - name: ๐Ÿ— Install yq + - name: ๐Ÿ— Install yq (Windows) + if: runner.os == 'Windows' uses: frenck/action-setup-yq@v1 - - name: ๐Ÿ” Determine stack resolver & GHC + - name: ๐Ÿ” Determine Stack resolver & GHC version run: | - STACK_ROOT="$(stack path --stack-root)" STACK_RESOLVER=$(yq .resolver stack.yaml) GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" - echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" + + - name: ๐Ÿ— Setup Haskell + if : runner.os == 'macOS' + uses: haskell-actions/setup@v2 + id: setup-haskell + with: + ghc-version: ${{ env.GHC_VERSION }} + enable-stack: true + stack-version: 'latest' + + - name: ๐Ÿ” Determine Stack root + run: | + STACK_ROOT="$(stack path --stack-root)" + echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" # things to be restored: # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. @@ -60,19 +78,27 @@ jobs: run: | echo PKG_CONFIG_PATH="$(brew --prefix)/opt/icu4c/lib/pkgconfig" >> "${GITHUB_ENV}" - - name: โฌ Setup Haskell - uses: haskell-actions/setup@v2 - id: setup-haskell - with: - ghc-version: ${{ env.GHC_VERSION }} - enable-stack: true - stack-version: 'latest' + # - name: โฌ Setup Haskell + # uses: haskell-actions/setup@v2 + # id: setup-haskell + # with: + # ghc-version: ${{ env.GHC_VERSION }} + # enable-stack: true + # stack-version: 'latest' + + - name: ๐Ÿ“ธ Build Snapshot + run: | + stack build --no-terminal --only-snapshot -j1 + + - name: ๐Ÿงฐ Build Dependencies + run: | + stack build --no-terminal --only-dependencies - - name: ๐Ÿ”จ Build - run: stack build + # - name: ๐Ÿ”จ Build + # run: stack build - - name: ๐Ÿงช Run tests - run: stack test + # - name: ๐Ÿงช Run tests + # run: stack test # things to be cached @@ -215,10 +241,13 @@ jobs: mv zip/als-macos.zip . fi - - name: ๐Ÿ”จ Build and run tests - run: | + - name: ๐Ÿงช Run tests + run: stack test --ta --als-path=zip/als + + # - name: ๐Ÿ”จ Build and run tests + # run: | - stack test --ta --als-path=zip/als + # stack test --ta --als-path=zip/als # release (optional) - name: ๐Ÿšข Release Artifacts diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml index 77485c3..68543e7 100644 --- a/.github/workflows/test-windows.yaml +++ b/.github/workflows/test-windows.yaml @@ -22,22 +22,30 @@ jobs: - name: ๐Ÿ“ฅ Checkout repository uses: actions/checkout@v4 - - name: ๐Ÿ— Install yq + - name: ๐Ÿ— Install yq (Windows) + if: runner.os == 'Windows' uses: frenck/action-setup-yq@v1 - - name: ๐Ÿ” Determine stack root and resolver and GHC + - name: ๐Ÿ” Determine Stack resolver & GHC version run: | - STACK_ROOT="$(stack path --stack-root)" STACK_RESOLVER=$(yq .resolver stack.yaml) GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) - echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" - echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" - # run: | - # STACK_ROOT="$(stack --system-ghc --no-install-ghc path --stack-root || echo "C:/Users/runneradmin/AppData/Local/Programs/stack/x86_64-windows")" - # echo "STACK_ROOT = ${STACK_ROOT}" - # echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" - # What about C:/Users/runneradmin/AppData/Roaming/stack ? + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" + + - name: ๐Ÿ— Setup Haskell + if : runner.os == 'macOS' + uses: haskell-actions/setup@v2 + id: setup-haskell + with: + ghc-version: ${{ env.GHC_VERSION }} + enable-stack: true + stack-version: 'latest' + + - name: ๐Ÿ” Determine Stack root + run: | + STACK_ROOT="$(stack path --stack-root)" + echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" # things to be restored: # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. @@ -65,23 +73,20 @@ jobs: run: | stack exec -- pacman -S --noconfirm mingw-w64-x86_64-icu mingw-w64-x86_64-pkgconf - # - name: ๐Ÿ“ธ Build Snapshot - # run: | - # stack build --no-terminal --only-snapshot -j1 + - name: ๐Ÿ“ธ Build Snapshot + run: | + stack build --no-terminal --only-snapshot -j1 - # - name: ๐Ÿงฐ Build Dependencies - # run: | - # stack build --no-terminal --only-dependencies + - name: ๐Ÿงฐ Build Dependencies + run: | + stack build --no-terminal --only-dependencies - # - name: ๐Ÿ”จ Build and run tests - # run: | - # stack test - - name: ๐Ÿ”จ Build - run: stack build + # - name: ๐Ÿ”จ Build + # run: stack build - - name: ๐Ÿงช Run tests - run: stack test + # - name: ๐Ÿงช Run tests + # run: stack test # things to be cached @@ -131,6 +136,10 @@ jobs: cd .. mv zip/als-windows.zip . + - name: ๐Ÿงช Run tests + run: stack test --ta --als-path=zip/als.exe + + # release (optional) - name: ๐Ÿšข Release Artifacts if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts From bb5d5e562d194bd574f3fd11990c84ef179373b3 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 10:40:37 +0800 Subject: [PATCH 08/14] [ ci ] Build ALS before running tests --- .github/workflows/test-unix.yaml | 10 ++++++---- .github/workflows/test-windows.yaml | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-unix.yaml b/.github/workflows/test-unix.yaml index 183bec5..6c5ca0d 100644 --- a/.github/workflows/test-unix.yaml +++ b/.github/workflows/test-unix.yaml @@ -87,12 +87,14 @@ jobs: # stack-version: 'latest' - name: ๐Ÿ“ธ Build Snapshot - run: | - stack build --no-terminal --only-snapshot -j1 + run: stack build --no-terminal --only-snapshot -j1 - name: ๐Ÿงฐ Build Dependencies - run: | - stack build --no-terminal --only-dependencies + run: stack build --no-terminal --only-dependencies + + - name: ๐Ÿงฐ Build ALS + run: stack build + # - name: ๐Ÿ”จ Build # run: stack build diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml index 68543e7..dbca353 100644 --- a/.github/workflows/test-windows.yaml +++ b/.github/workflows/test-windows.yaml @@ -81,6 +81,8 @@ jobs: run: | stack build --no-terminal --only-dependencies + - name: ๐Ÿงช Build ALS + run: stack build # - name: ๐Ÿ”จ Build # run: stack build From a1a7d365006704665f82b3cb926ae988ff2cde51 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 10:56:06 +0800 Subject: [PATCH 09/14] [ ci ] Unify the CI workflow for testing on all platforms --- .../workflows/{test-unix.yaml => test.yaml} | 75 ++++++++++++------- test/Test/LSP.hs | 34 +++++---- 2 files changed, 68 insertions(+), 41 deletions(-) rename .github/workflows/{test-unix.yaml => test.yaml} (80%) diff --git a/.github/workflows/test-unix.yaml b/.github/workflows/test.yaml similarity index 80% rename from .github/workflows/test-unix.yaml rename to .github/workflows/test.yaml index 6c5ca0d..c1699fd 100644 --- a/.github/workflows/test-unix.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,6 @@ # modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/linux.yml -name: CI (Unix) +name: CI defaults: run: @@ -19,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] fail-fast: false steps: @@ -78,13 +78,10 @@ jobs: run: | echo PKG_CONFIG_PATH="$(brew --prefix)/opt/icu4c/lib/pkgconfig" >> "${GITHUB_ENV}" - # - name: โฌ Setup Haskell - # uses: haskell-actions/setup@v2 - # id: setup-haskell - # with: - # ghc-version: ${{ env.GHC_VERSION }} - # enable-stack: true - # stack-version: 'latest' + - name: Install the icu library (on Windows) + if: runner.os == 'Windows' + run: | + stack exec -- pacman -S --noconfirm mingw-w64-x86_64-icu mingw-w64-x86_64-pkgconf - name: ๐Ÿ“ธ Build Snapshot run: stack build --no-terminal --only-snapshot -j1 @@ -95,13 +92,6 @@ jobs: - name: ๐Ÿงฐ Build ALS run: stack build - - # - name: ๐Ÿ”จ Build - # run: stack build - - # - name: ๐Ÿงช Run tests - # run: stack test - # things to be cached - name: ๐Ÿ’พ Cache stack global package db @@ -119,7 +109,7 @@ jobs: key: ${{ steps.stack-work.outputs.cache-primary-key }} - - name: ๐Ÿ”— Bundle ICU4C DLLs (on macOS) + - name: ๐Ÿ“ฆ Bundle executable, DLLs and data files (on macOS) if: runner.os == 'macOS' run: | # Bundle icu4c DLLs @@ -209,8 +199,8 @@ jobs: echo " old path : $icudata_path" echo " new path : $icudata_path_new" - - - name: ๐Ÿ“ฆ Compress files + - name: ๐Ÿ“ฆ Bundle executable, DLLs and data files (on Linux and macOS) + if: runner.os != 'Windows' id: zip run: | # locate the data-dir @@ -243,18 +233,53 @@ jobs: mv zip/als-macos.zip . fi + - name: ๐Ÿ“ฆ Bundle executable, DLLs and data files (on Windows) + if: runner.os == 'Windows' + shell: pwsh + run: | + # locate the data-dir + $snapshot = (stack path --snapshot-install-root) + $datadir = (ls $snapshot\share *Agda-* -Recurse -Directory).FullName + + # locate the executable + $local = (stack path --local-install-root) + $executable = (ls $local\bin *als.exe* -Recurse -File).FullName + + # make a temporary directory for compresssing + mkdir zip + cp -r $datadir zip/data + cp $executable zip/ + + # include text-icu DLLs + $mingw64bin = (stack path --extra-library-dirs).split(", ") -match "\\bin" + ls $mingw64bin + cp (ls $mingw64bin *libicudt*) zip/ + cp (ls $mingw64bin *libicuin*) zip/ + cp (ls $mingw64bin *libicuuc*) zip/ + ls zip + + # compress + cd zip + Compress-Archive * als-windows.zip + cd .. + mv zip/als-windows.zip . + + - name: ๐Ÿงช Run tests run: stack test --ta --als-path=zip/als - # - name: ๐Ÿ”จ Build and run tests - # run: | - - # stack test --ta --als-path=zip/als - # release (optional) - name: ๐Ÿšข Release Artifacts if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ github.ref_name }} als-ubuntu.zip --clobber + if [[ ${{ runner.os }} == "Linux" ]]; then + gh release upload ${{ github.ref_name }} als-ubuntu.zip --clobber + fi + if [[ ${{ runner.os }} == "macOS" ]]; then + gh release upload ${{ github.ref_name }} als-macos.zip --clobber + fi + if [[ ${{ runner.os }} == "Windows" ]]; then + gh release upload ${{ github.ref_name }} als-windows.zip --clobber + fi diff --git a/test/Test/LSP.hs b/test/Test/LSP.hs index 023ca77..62c0f70 100644 --- a/test/Test/LSP.hs +++ b/test/Test/LSP.hs @@ -1,40 +1,42 @@ {-# LANGUAGE OverloadedStrings #-} + module Test.LSP (tests) where -import Control.Applicative.Combinators +import Agda import Control.Monad.IO.Class +import qualified Data.Aeson as JSON import Language.LSP.Protocol.Message -import Language.LSP.Protocol.Types import Language.LSP.Test +import Switchboard (agdaCustomMethod) import Test.Tasty import Test.Tasty.HUnit -import qualified Data.Aeson as JSON -import Switchboard ( agdaCustomMethod ) -import Agda tests :: FilePath -> TestTree -tests alsPath = +tests alsPath = testGroup "LSP" [ testCase "load" (demo alsPath) ] demo :: FilePath -> IO () -demo alsPath = +demo alsPath = do + putStrLn $ "Running LSP tests on the server with the following path to the als executable: " ++ alsPath runSession alsPath fullLatestClientCaps "test/data/" $ do - doc <- openDoc "A.agda" "agda" + doc <- openDoc "A.agda" "agda" - -- Use your favourite favourite combinators. - -- skipManyTill loggingNotification (count 1 publishDiagnosticsNotification) + -- Use your favourite favourite combinators. + -- skipManyTill loggingNotification (count 1 publishDiagnosticsNotification) - testCustomMethod "IOTCM \"test/data/A.agdaa\" NonInteractive Direct( Cmd_load \"test/data/A.agda\" [] )" + testCustomMethod "IOTCM \"test/data/A.agdaa\" NonInteractive Direct( Cmd_load \"test/data/A.agda\" [] )" - -- Or use one of the helper functions - -- getDocumentSymbols doc >>= liftIO . print +-- Or use one of the helper functions +-- getDocumentSymbols doc >>= liftIO . print -- | Sends a custom method request to the server and expects a response of `CmdRes Nothing` testCustomMethod :: String -> Session () -testCustomMethod cmd = do - TResponseMessage _ _ rsp <- request agdaCustomMethod $ - JSON.toJSON $ CmdReq cmd +testCustomMethod cmd = do + TResponseMessage _ _ rsp <- + request agdaCustomMethod $ + JSON.toJSON $ + CmdReq cmd liftIO $ rsp @?= Right (JSON.toJSON (CmdRes Nothing)) \ No newline at end of file From 1db7df345c6fc546626073de6d5f5784524f668c Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 11:11:18 +0800 Subject: [PATCH 10/14] [ ci ] Build dependencies of the testing before caching --- .github/workflows/test-windows.yaml | 151 ---------------------------- .github/workflows/test.yaml | 3 + 2 files changed, 3 insertions(+), 151 deletions(-) delete mode 100644 .github/workflows/test-windows.yaml diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml deleted file mode 100644 index dbca353..0000000 --- a/.github/workflows/test-windows.yaml +++ /dev/null @@ -1,151 +0,0 @@ -# modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/windows.yml - -name: CI (Windows) - -on: - push: - branches: [master, ci-*, ci] - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - pull_request: - branches: [master] - -defaults: - run: - shell: bash - -jobs: - build: - runs-on: windows-latest - steps: - - - name: ๐Ÿ“ฅ Checkout repository - uses: actions/checkout@v4 - - - name: ๐Ÿ— Install yq (Windows) - if: runner.os == 'Windows' - uses: frenck/action-setup-yq@v1 - - - name: ๐Ÿ” Determine Stack resolver & GHC version - run: | - STACK_RESOLVER=$(yq .resolver stack.yaml) - GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) - echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" - echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" - - - name: ๐Ÿ— Setup Haskell - if : runner.os == 'macOS' - uses: haskell-actions/setup@v2 - id: setup-haskell - with: - ghc-version: ${{ env.GHC_VERSION }} - enable-stack: true - stack-version: 'latest' - - - name: ๐Ÿ” Determine Stack root - run: | - STACK_ROOT="$(stack path --stack-root)" - echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" - - # things to be restored: - # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. - - - name: ๐Ÿ’พ Restore cached stack global package db - id: stack-global - uses: actions/cache/restore@v4 - with: - path: ${{ env.STACK_ROOT }} - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} - restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global - - - name: ๐Ÿ’พ Restore cached .stack-work - id: stack-work - uses: actions/cache/restore@v4 - with: - path: .stack-work - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} - restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work - - # actions - - name: Install the icu library - run: | - stack exec -- pacman -S --noconfirm mingw-w64-x86_64-icu mingw-w64-x86_64-pkgconf - - - name: ๐Ÿ“ธ Build Snapshot - run: | - stack build --no-terminal --only-snapshot -j1 - - - name: ๐Ÿงฐ Build Dependencies - run: | - stack build --no-terminal --only-dependencies - - - name: ๐Ÿงช Build ALS - run: stack build - - # - name: ๐Ÿ”จ Build - # run: stack build - - # - name: ๐Ÿงช Run tests - # run: stack test - - # things to be cached - - - name: ๐Ÿ’พ Cache stack global package db - if: always() && steps.stack-global.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 - with: - path: ${{ env.STACK_ROOT }} - key: ${{ steps.stack-global.outputs.cache-primary-key }} - - - name: ๐Ÿ’พ Cache .stack-work - if: always() && steps.stack-work.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 - with: - path: .stack-work - key: ${{ steps.stack-work.outputs.cache-primary-key }} - - # artifacts: - - - name: ๐Ÿ“ฆ Compress executable and data files - shell: pwsh - run: | - # locate the data-dir - $snapshot = (stack path --snapshot-install-root) - $datadir = (ls $snapshot\share *Agda-* -Recurse -Directory).FullName - - # locate the executable - $local = (stack path --local-install-root) - $executable = (ls $local\bin *als.exe* -Recurse -File).FullName - - # make a temporary directory for compresssing - mkdir zip - cp -r $datadir zip/data - cp $executable zip/ - - # include text-icu DLLs - $mingw64bin = (stack path --extra-library-dirs).split(", ") -match "\\bin" - ls $mingw64bin - cp (ls $mingw64bin *libicudt*) zip/ - cp (ls $mingw64bin *libicuin*) zip/ - cp (ls $mingw64bin *libicuuc*) zip/ - ls zip - - # compress - cd zip - Compress-Archive * als-windows.zip - cd .. - mv zip/als-windows.zip . - - - name: ๐Ÿงช Run tests - run: stack test --ta --als-path=zip/als.exe - - - # release (optional) - - name: ๐Ÿšข Release Artifacts - if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload ${{ github.ref_name }} als-windows.zip --clobber diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c1699fd..b157134 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -92,6 +92,9 @@ jobs: - name: ๐Ÿงฐ Build ALS run: stack build + - name: ๐Ÿงฐ Build Testings + run: stack build --test --no-terminal --only-dependencies + # things to be cached - name: ๐Ÿ’พ Cache stack global package db From 87c103617350467082265b6fedaa4e3795cf5a38 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 11:27:11 +0800 Subject: [PATCH 11/14] [ ci ] Support building of macOS x64 executable and differentiate it from the current arm64 one --- .github/workflows/test.yaml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b157134..a8b39c2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -19,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest, macos-13, windows-latest] fail-fast: false steps: @@ -277,12 +277,17 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - if [[ ${{ runner.os }} == "Linux" ]]; then + if [[ ${{ matrix.os }} == "ubuntu-latest" ]]; then gh release upload ${{ github.ref_name }} als-ubuntu.zip --clobber fi - if [[ ${{ runner.os }} == "macOS" ]]; then - gh release upload ${{ github.ref_name }} als-macos.zip --clobber + # arm64 macos + if [[ ${{ matrix.os }} == "macos-latest" ]]; then + gh release upload ${{ github.ref_name }} als-macos-arm64.zip --clobber + fi + # x64 macos + if [[ ${{ matrix.os }} == "macos-13" ]]; then + gh release upload ${{ github.ref_name }} als-macos-x64.zip --clobber fi - if [[ ${{ runner.os }} == "Windows" ]]; then + if [[ ${{ matrix.os }} == "windows-latest" ]]; then gh release upload ${{ github.ref_name }} als-windows.zip --clobber fi From df96e184e391c903f1b188ae0cb772c7bd606331 Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 13:51:48 +0800 Subject: [PATCH 12/14] [ test ] Primitive testing for hover --- .gitignore | 3 +++ test/Test/LSP.hs | 15 ++++++++++----- test/Test/SrcLoc.hs | 35 +++++++++++++++++------------------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 41f3983..14ce36d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ node_modules/ cabal.sandbox.config cabal.project.local *~ + + +*.agdai \ No newline at end of file diff --git a/test/Test/LSP.hs b/test/Test/LSP.hs index 62c0f70..2a78683 100644 --- a/test/Test/LSP.hs +++ b/test/Test/LSP.hs @@ -6,6 +6,7 @@ import Agda import Control.Monad.IO.Class import qualified Data.Aeson as JSON import Language.LSP.Protocol.Message +import Language.LSP.Protocol.Types import Language.LSP.Test import Switchboard (agdaCustomMethod) import Test.Tasty @@ -24,14 +25,18 @@ demo alsPath = do runSession alsPath fullLatestClientCaps "test/data/" $ do doc <- openDoc "A.agda" "agda" - -- Use your favourite favourite combinators. - -- skipManyTill loggingNotification (count 1 publishDiagnosticsNotification) + -- hover + TResponseMessage _ _ rsp <- request SMethod_TextDocumentHover (HoverParams doc (Position 3 9) Nothing) + case rsp of + Right (InL (Hover (InL (MarkupContent _ content)) (Just (Range start end)))) -> liftIO $ do + content @?= "\n```agda-language-server\nAgda.Primitive.Set\n```\n" + start @?= Position 3 9 + end @?= Position 3 9 + _ -> liftIO $ assertFailure "Unexpected response" + -- agda-mode:load testCustomMethod "IOTCM \"test/data/A.agdaa\" NonInteractive Direct( Cmd_load \"test/data/A.agda\" [] )" --- Or use one of the helper functions --- getDocumentSymbols doc >>= liftIO . print - -- | Sends a custom method request to the server and expects a response of `CmdRes Nothing` testCustomMethod :: String -> Session () testCustomMethod cmd = do diff --git a/test/Test/SrcLoc.hs b/test/Test/SrcLoc.hs index af4c3e4..c3928b7 100644 --- a/test/Test/SrcLoc.hs +++ b/test/Test/SrcLoc.hs @@ -1,11 +1,11 @@ module Test.SrcLoc where -import Test.Tasty -import Test.Tasty.HUnit -import Data.List (sort) import Agda.Position -import Data.Text (Text) import qualified Data.IntMap as IntMap +import Data.List (sort) +import Data.Text (Text) +import Test.Tasty +import Test.Tasty.HUnit tests :: TestTree tests = testGroup "Source Location" [positionToOffsetTests, offsetToPositionTests] @@ -16,14 +16,14 @@ positionToOffsetTests :: TestTree positionToOffsetTests = testGroup "Position => Offset" - [ testCase "cached table" $ IntMap.toList (unToOffset table) @?= [(1, 4), (2, 9), (3, 12)] - , testCase "line 0" $ run [(0, 0), (0, 1), (0, 2), (0, 3)] @?= [0, 1, 2, 3] - , testCase "line 1" $ run [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)] @?= [4, 5, 6, 7, 8] - , testCase "line 2" $ run [(2, 0), (2, 1)] @?= [9, 10] - , testCase "line 3" $ run [(3, 0), (3, 1)] @?= [12, 13] + [ testCase "cached table" $ IntMap.toList (unToOffset table) @?= [(1, 4), (2, 9), (3, 12)], + testCase "line 0" $ run [(0, 0), (0, 1), (0, 2), (0, 3)] @?= [0, 1, 2, 3], + testCase "line 1" $ run [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)] @?= [4, 5, 6, 7, 8], + testCase "line 2" $ run [(2, 0), (2, 1)] @?= [9, 10], + testCase "line 3" $ run [(3, 0), (3, 1)] @?= [12, 13] ] where - text :: Text + text :: Text text = "012\n456\r\n90\r23" table :: ToOffset @@ -31,21 +31,21 @@ positionToOffsetTests = run :: [(Int, Int)] -> [Int] run = map (toOffset table) - + -------------------------------------------------------------------------------- offsetToPositionTests :: TestTree offsetToPositionTests = testGroup "Offset => Position" - [ testCase "cached table" $ IntMap.toList (unFromOffset table) @?= [(4, 1), (9, 2), (12, 3)] - , testCase "line 0" $ run [0, 1, 2, 3] @?= [(0, 0), (0, 1), (0, 2), (0, 3)] - , testCase "line 1" $ run [4, 5, 6, 7, 8] @?= [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)] - , testCase "line 2" $ run [9, 10] @?= [(2, 0), (2, 1)] - , testCase "line 3" $ run [12, 13] @?= [(3, 0), (3, 1)] + [ testCase "cached table" $ IntMap.toList (unFromOffset table) @?= [(4, 1), (9, 2), (12, 3)], + testCase "line 0" $ run [0, 1, 2, 3] @?= [(0, 0), (0, 1), (0, 2), (0, 3)], + testCase "line 1" $ run [4, 5, 6, 7, 8] @?= [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)], + testCase "line 2" $ run [9, 10] @?= [(2, 0), (2, 1)], + testCase "line 3" $ run [12, 13] @?= [(3, 0), (3, 1)] ] where - text :: Text + text :: Text text = "012\n456\r\n90\r23" table :: FromOffset @@ -53,4 +53,3 @@ offsetToPositionTests = run :: [Int] -> [(Int, Int)] run = map (fromOffset table) - \ No newline at end of file From 328b2191ab579dbaef730203d930a65d7ebee8eb Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 16:01:26 +0800 Subject: [PATCH 13/14] [ fix ] Disregard the actual content of the hover testing --- test/Test/LSP.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Test/LSP.hs b/test/Test/LSP.hs index 2a78683..ee7a688 100644 --- a/test/Test/LSP.hs +++ b/test/Test/LSP.hs @@ -29,7 +29,9 @@ demo alsPath = do TResponseMessage _ _ rsp <- request SMethod_TextDocumentHover (HoverParams doc (Position 3 9) Nothing) case rsp of Right (InL (Hover (InL (MarkupContent _ content)) (Just (Range start end)))) -> liftIO $ do - content @?= "\n```agda-language-server\nAgda.Primitive.Set\n```\n" + -- disregard the content of the hover message for now + -- because it varies depending on the version of Agda + -- content @?= "\n```agda-language-server\nAgda.Primitive.Set\n```\n" start @?= Position 3 9 end @?= Position 3 9 _ -> liftIO $ assertFailure "Unexpected response" From ed0e99296184f5b8253993d45dc5c5d36ae1d9ed Mon Sep 17 00:00:00 2001 From: Ting-Gian LUA Date: Wed, 4 Dec 2024 16:10:55 +0800 Subject: [PATCH 14/14] [ ci ] Use matrix.os instead of runner.os as cache key --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a8b39c2..19b71b6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -59,18 +59,18 @@ jobs: uses: actions/cache/restore@v4 with: path: ${{ env.STACK_ROOT }} - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} + key: ${{ matrix.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global + ${{ matrix.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global - name: ๐Ÿ’พ Restore cached .stack-work id: stack-work uses: actions/cache/restore@v4 with: path: .stack-work - key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} + key: ${{ matrix.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} restore-keys: | - ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work + ${{ matrix.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work # actions: - name: Set PKG_CONFIG_PATH for the ICU library (on macOS)