From 67ae6eb30b80b59c3c08e3d92cff382d9542a5b0 Mon Sep 17 00:00:00 2001 From: Nikita Volkov Date: Mon, 25 Dec 2023 14:02:33 +0300 Subject: [PATCH] Modernize --- .github/workflows/check.yaml | 45 ++++++++++++++ .../workflows/on-push-to-master-or-pr.yaml | 17 ++++++ .github/workflows/on-push-to-release.yaml | 32 ++++++++++ .travis.yml | 61 ------------------- cabal.project | 1 + conflicts-test/Main.hs | 9 ++- library/Hasql/Transaction.hs | 1 - library/Hasql/Transaction/Private/Prelude.hs | 6 +- library/Hasql/Transaction/Private/Sessions.hs | 2 + .../Hasql/Transaction/Private/Transaction.hs | 6 +- stack.yaml | 1 - stack.yaml.lock | 12 ---- 12 files changed, 107 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/check.yaml create mode 100644 .github/workflows/on-push-to-master-or-pr.yaml create mode 100644 .github/workflows/on-push-to-release.yaml delete mode 100644 .travis.yml create mode 100644 cabal.project delete mode 100644 stack.yaml delete mode 100644 stack.yaml.lock diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..b39bcee --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,45 @@ +name: Compile, test and check the docs + +on: + workflow_call: + +jobs: + + check: + + strategy: + fail-fast: false + matrix: + include: + - ghc: 8.8.1 + ghc-options: "" + ignore-haddock: true + ignore-cabal-check: true + - ghc: latest + ignore-cabal-check: true + + runs-on: ubuntu-latest + + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + + - uses: nikita-volkov/build-and-test-cabal-package.github-action@v1 + with: + ghc: ${{matrix.ghc}} + ghc-options: ${{matrix.ghc-options}} + ignore-haddock: ${{matrix.ignore-haddock}} + ignore-cabal-check: ${{matrix.ignore-cabal-check}} diff --git a/.github/workflows/on-push-to-master-or-pr.yaml b/.github/workflows/on-push-to-master-or-pr.yaml new file mode 100644 index 0000000..79c21f5 --- /dev/null +++ b/.github/workflows/on-push-to-master-or-pr.yaml @@ -0,0 +1,17 @@ +name: Compile, test and check the docs + +on: + push: + branches: + - master + pull_request: + +jobs: + + format: + uses: nikita-volkov/haskell-hackage-lib-github-actions-workflows/.github/workflows/format.yaml@v2 + secrets: inherit + + check: + uses: ./.github/workflows/check.yaml + secrets: inherit diff --git a/.github/workflows/on-push-to-release.yaml b/.github/workflows/on-push-to-release.yaml new file mode 100644 index 0000000..9024112 --- /dev/null +++ b/.github/workflows/on-push-to-release.yaml @@ -0,0 +1,32 @@ +name: Release the lib to Hackage + +on: + push: + branches: + - supermajor + - major + - minor + - patch + +concurrency: + group: release + cancel-in-progress: false + +jobs: + + format: + uses: nikita-volkov/haskell-hackage-lib-github-actions-workflows/.github/workflows/format.yaml@v2 + secrets: inherit + + check: + uses: ./.github/workflows/check.yaml + secrets: inherit + + release: + needs: + - format + - check + uses: nikita-volkov/haskell-hackage-lib-github-actions-workflows/.github/workflows/release.yaml@v2 + secrets: inherit + with: + prefix-tag-with-v: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6c4882d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,61 +0,0 @@ -if: tag IS blank - -env: - - ghc=8.6.1 - - ghc=8.8.1 - - ghc=8.10.2 benchmarks=1 tests=1 - - ghc=9.0.1 - -matrix: - allow_failures: - - env: ghc=9.0.1 - -services: - - postgresql - -install: - # Set up the Shell to treat the semicolon as && - - set -eo pipefail - # Install GHC and Cabal - - - cabal=${cabal=2.4}; - travis_retry sudo add-apt-repository -y ppa:hvr/ghc; - travis_retry sudo apt-get update; - travis_retry sudo apt-get install cabal-install-$cabal ghc-$ghc; - export PATH=/opt/ghc/$ghc/bin:/opt/cabal/$cabal/bin:$PATH; - # Update the Cabal database - - cabal update - # Switch to the distro: - - - export pkg_name=$(cabal info . | awk '{print $2;exit}'); - cabal sdist; - cd dist; - tar xzvf $pkg_name.tar.gz; - cd $pkg_name; - # Install the lower bound dependencies - - - if [ "$lower_bound_dependencies" = "1" ]; - then - constraint_options=( - ); - fi; - # Install the library dependencies - - cabal v1-install --only-dependencies --reorder-goals --force-reinstalls - ${constraint_options[@]} - $([ "$tests" = "1" ] && echo "--enable-tests") - $([ "$benchmarks" = "1" ] && echo "--enable-benchmarks") - # Build the library - - cabal v1-build - # Configure and build the remaining stuff - - cabal v1-configure - $([ "$tests" = "1" ] && echo "--enable-tests") - $([ "$benchmarks" = "1" ] && echo "--enable-benchmarks") - -f doctest - - cabal v1-build - -script: - - | - if [ "$tests" = "1" ]; - then - cabal v1-test --show-details=always; - fi; diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..e6fdbad --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/conflicts-test/Main.hs b/conflicts-test/Main.hs index b12fbb6..2a0929b 100644 --- a/conflicts-test/Main.hs +++ b/conflicts-test/Main.hs @@ -9,6 +9,7 @@ import qualified Main.Statements as D import qualified Main.Transactions as E import Prelude +main :: IO () main = bracket acquire release use where @@ -16,9 +17,9 @@ main = (,) <$> acquire <*> acquire where acquire = - join $ - fmap (either (fail . show) return) $ - A.acquire connectionSettings + join + $ fmap (either (fail . show) return) + $ A.acquire connectionSettings where connectionSettings = A.settings "localhost" 5432 "postgres" "" "postgres" @@ -41,10 +42,12 @@ main = tests = [readAndWriteTransactionsTest, transactionsTest, transactionAndQueryTest] +session :: A.Connection -> B.Session a -> IO a session connection session = B.run session connection >>= either (fail . show) return +transaction :: A.Connection -> C.Transaction a -> IO a transaction connection transaction = session connection (G.transaction G.RepeatableRead G.Write transaction) diff --git a/library/Hasql/Transaction.hs b/library/Hasql/Transaction.hs index b6bc424..9c0de9a 100644 --- a/library/Hasql/Transaction.hs +++ b/library/Hasql/Transaction.hs @@ -9,5 +9,4 @@ module Hasql.Transaction ) where -import Hasql.Transaction.Config import Hasql.Transaction.Private.Transaction diff --git a/library/Hasql/Transaction/Private/Prelude.hs b/library/Hasql/Transaction/Private/Prelude.hs index 79bf394..89bf947 100644 --- a/library/Hasql/Transaction/Private/Prelude.hs +++ b/library/Hasql/Transaction/Private/Prelude.hs @@ -32,7 +32,7 @@ import Data.Either as Exports import Data.Fixed as Exports import Data.Foldable as Exports hiding (toList) import Data.Function as Exports hiding (id, (.)) -import Data.Functor as Exports +import Data.Functor as Exports hiding (unzip) import Data.Functor.Contravariant as Exports import Data.Functor.Contravariant.Divisible as Exports import Data.Functor.Identity as Exports @@ -71,13 +71,11 @@ import System.IO.Unsafe as Exports import System.Mem as Exports import System.Mem.StableName as Exports import System.Timeout as Exports -import Text.ParserCombinators.ReadP as Exports (ReadP, ReadS, readP_to_S, readS_to_P) -import Text.ParserCombinators.ReadPrec as Exports (ReadPrec, readP_to_Prec, readPrec_to_P, readPrec_to_S, readS_to_Prec) import Text.Printf as Exports (hPrintf, printf) import Text.Read as Exports (Read (..), readEither, readMaybe) import Unsafe.Coerce as Exports import Prelude as Exports hiding (all, and, any, concat, concatMap, elem, fail, foldl, foldl1, foldr, foldr1, id, mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum, (.)) -tryError :: MonadError e m => m a -> m (Either e a) +tryError :: (MonadError e m) => m a -> m (Either e a) tryError m = catchError (liftM Right m) (return . Left) diff --git a/library/Hasql/Transaction/Private/Sessions.hs b/library/Hasql/Transaction/Private/Sessions.hs index 5f4fcc7..200ca16 100644 --- a/library/Hasql/Transaction/Private/Sessions.hs +++ b/library/Hasql/Transaction/Private/Sessions.hs @@ -31,11 +31,13 @@ tryTransaction level mode body preparable = do handleTransactionError error $ return Nothing Nothing -> return Nothing +commitOrAbort :: Bool -> Bool -> Session () commitOrAbort commit preparable = if commit then statement () (Statements.commitTransaction preparable) else statement () (Statements.abortTransaction preparable) +handleTransactionError :: QueryError -> Session a -> Session a handleTransactionError error onTransactionError = case error of QueryError _ _ (ResultError (ServerError "40001" _ _ _ _)) -> onTransactionError error -> throwError error diff --git a/library/Hasql/Transaction/Private/Transaction.hs b/library/Hasql/Transaction/Private/Transaction.hs index d36a9da..e2a0343 100644 --- a/library/Hasql/Transaction/Private/Transaction.hs +++ b/library/Hasql/Transaction/Private/Transaction.hs @@ -5,7 +5,6 @@ import qualified Hasql.Statement as A import Hasql.Transaction.Config import Hasql.Transaction.Private.Prelude import qualified Hasql.Transaction.Private.Sessions as D -import qualified Hasql.Transaction.Private.Statements as C -- | -- A composable abstraction over the retryable transactions. @@ -17,12 +16,11 @@ newtype Transaction a = Transaction (StateT Bool B.Session a) deriving (Functor, Applicative, Monad) -instance Semigroup a => Semigroup (Transaction a) where +instance (Semigroup a) => Semigroup (Transaction a) where (<>) = liftA2 (<>) -instance Monoid a => Monoid (Transaction a) where +instance (Monoid a) => Monoid (Transaction a) where mempty = pure mempty - mappend = liftA2 mappend -- | -- Execute the transaction using the provided isolation level and mode. diff --git a/stack.yaml b/stack.yaml deleted file mode 100644 index 4998b20..0000000 --- a/stack.yaml +++ /dev/null @@ -1 +0,0 @@ -resolver: nightly-2022-11-23 diff --git a/stack.yaml.lock b/stack.yaml.lock deleted file mode 100644 index e9b8153..0000000 --- a/stack.yaml.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file was autogenerated by Stack. -# You should not edit this file by hand. -# For more information, please see the documentation at: -# https://docs.haskellstack.org/en/stable/lock_files - -packages: [] -snapshots: -- completed: - sha256: f19b7679d0a1094c09ac025c8cfbd4bcdfb0f1f991110094f78ce5a8e299cb39 - size: 546437 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/11/23.yaml - original: nightly-2022-11-23