packages feed

releaser 0.3.0.0 → 0.3.0.1

raw patch · 5 files changed

+98/−76 lines, 5 filesdep +bytestringdep ~Cabalsetup-changednew-uploader

Dependencies added: bytestring

Dependency ranges changed: Cabal

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for releaser +## 0.3.0.1 -- 2023-10-31++* Repo is now [github.com/hercules-ci/haskell-releaser](https://github.com/hercules-ci/haskell-releaser)++* Cabal 3.8 support+ ## 0.3.0.0 -- 2020-05-04  * Upload to haddock support
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
releaser.cabal view
@@ -1,10 +1,10 @@ cabal-version: 2.4 name: releaser synopsis: Automation of Haskell package release process-version: 0.3.0.0+version: 0.3.0.1 license: Apache-2.0 license-file: LICENSE-maintainer: domen@dev.si+maintainer: info@hercules-ci.com author: Domen Kozar category: Development extra-source-files:@@ -12,7 +12,7 @@  source-repository head   type:     git-  location: https://github.com/domenkozar/releaser/+  location: https://github.com/hercules-ci/haskell-releaser/  library     exposed-modules:@@ -22,7 +22,8 @@     default-extensions: OverloadedStrings     build-depends:         base >=4.7 && <5,-        Cabal -any,+        bytestring,+        Cabal >=3.6,         regex-tdfa -any,         process -any,         pretty-terminal -any,
releaser/Main.hs view
@@ -1,7 +1,7 @@ module Main (main) where  import Releaser.Primitives-import System.IO (hSetBuffering, stdout, stderr, BufferMode(..))+import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)  main :: IO () main = do
src/Releaser/Primitives.hs view
@@ -1,59 +1,65 @@-module Releaser.Primitives (-  -- cabal utilities-    CabalInfo(..)-  , cabalRead-  , cabalWriteVersion-  , cabalBumpVersion-  , cabalSdist-  , cabalUpload-  , cabalMakeHaddocks-  , cabalUploadDocs-  -- git primitives-  , gitCheckout-  , gitGetTags-  , gitTag-  , gitCommit-  , gitPush-  , gitPushTags-  , gitAssertEmptyStaging-  -- utilities-  , prompt-  , abort-  , logStep-  , changelogPrepare-  ) where+{-# LANGUAGE CPP #-} -import System.IO -import System.Process-import System.Console.Pretty (Color(..), color)-import System.Environment (lookupEnv)-import System.Exit (ExitCode(..), exitFailure)-import Text.Regex.TDFA-import Text.Regex.TDFA.Text+module Releaser.Primitives+  ( -- cabal utilities+    CabalInfo (..),+    cabalRead,+    cabalWriteVersion,+    cabalBumpVersion,+    cabalSdist,+    cabalUpload,+    cabalMakeHaddocks,+    cabalUploadDocs,+    -- git primitives+    gitCheckout,+    gitGetTags,+    gitTag,+    gitCommit,+    gitPush,+    gitPushTags,+    gitAssertEmptyStaging,+    -- utilities+    prompt,+    abort,+    logStep,+    changelogPrepare,+  )+where++import qualified Data.ByteString as BS+import Data.Foldable (toList) import Data.Functor (void) import Data.List (intercalate) import qualified Data.Text as T import qualified Data.Text.IO as T-import Text.ParserCombinators.ReadP (ReadP, readP_to_S) import Data.Version (parseVersion) import Distribution.PackageDescription.Parsec-import Distribution.Verbosity (silent)-import Distribution.Types.PackageId (pkgVersion, pkgName)+import Distribution.Parsec (PWarning (..), showPError)+import Distribution.Simple.Utils (die', tryFindPackageDesc)+import Distribution.Types.GenericPackageDescription (GenericPackageDescription, packageDescription) import Distribution.Types.PackageDescription (package)-import Distribution.Types.GenericPackageDescription (packageDescription)-import Distribution.Types.Version (versionNumbers, mkVersion')-import Distribution.Simple.Utils (tryFindPackageDesc)+import Distribution.Types.PackageId (pkgName, pkgVersion) import Distribution.Types.PackageName (unPackageName)+import Distribution.Types.Version (mkVersion', versionNumbers)+import Distribution.Verbosity (Verbosity, normal, silent)+import System.Console.Pretty (Color (..), color)+import System.Environment (lookupEnv)+import System.Exit (ExitCode (..), exitFailure)+import System.IO+import System.Process+import Text.ParserCombinators.ReadP (ReadP, readP_to_S)+import Text.Regex.TDFA+import Text.Regex.TDFA.Text  logStep :: String -> IO ()-logStep str = +logStep str =   putStrLn $ color Green ">> " <> str  prompt :: String -> IO String prompt str = do   putStr $ color Blue ">> " <> str   hFlush stdout-  getLine  +  getLine  promptRetry :: String -> IO () promptRetry str =@@ -64,11 +70,20 @@   putStrLnErr $ color Red ">> " <> str   exitFailure -data CabalInfo = CabalInfo -  { name :: String-  , version :: String+data CabalInfo = CabalInfo+  { name :: String,+    version :: String   } +#if MIN_VERSION_Cabal(3,8,0)+readGenericPackageDescription :: Verbosity -> FilePath -> IO GenericPackageDescription+readGenericPackageDescription v p = do+  bs <- BS.readFile p+  case runParseResult (parseGenericPackageDescription bs) of+    (_warnings, Right gpd) -> pure gpd+    (_warnings, Left (v, e)) -> fail $ "Cabal file " ++ p ++ " has problems:\n" ++ unlines (map (showPError p) (toList e))+#endif+ -- | Given a folder, find a Cabal file and read the package version cabalRead :: FilePath -> IO CabalInfo cabalRead dir = do@@ -77,10 +92,11 @@   genericPackageDescription <- readGenericPackageDescription silent cabalFile   let pkgversion = pkgVersion $ package $ packageDescription genericPackageDescription       pkgname = pkgName $ package $ packageDescription genericPackageDescription-      cabalinfo = CabalInfo -        { version = intercalate "." $ show <$> versionNumbers pkgversion-        , name = unPackageName pkgname-        }+      cabalinfo =+        CabalInfo+          { version = intercalate "." $ show <$> versionNumbers pkgversion,+            name = unPackageName pkgname+          }   logStep $ "Found " <> name cabalinfo <> "-" <> version cabalinfo   return cabalinfo @@ -88,21 +104,20 @@ cabalWriteVersion :: FilePath -> String -> IO () cabalWriteVersion dir versionStr = do   if validCabalVersion versionStr-  then do-    cabalFile <- tryFindPackageDesc silent dir-    cabalinfo <- cabalRead dir-    cabal <- T.readFile cabalFile-    let versionPrev :: T.Text-        versionPrev = cabal =~ ("version:[ \t]*" ++ version cabalinfo)-    if versionPrev == ""-    then abort $ "Failed to replace version in " <> cabalFile <> ", please open an issue at https://github.com/domenkozar/releaser/issues"+    then do+      cabalFile <- tryFindPackageDesc silent dir+      cabalinfo <- cabalRead dir+      cabal <- T.readFile cabalFile+      let versionPrev :: T.Text+          versionPrev = cabal =~ ("version:[ \t]*" ++ version cabalinfo)+      if versionPrev == ""+        then abort $ "Failed to replace version in " <> cabalFile <> ", please open an issue at https://github.com/domenkozar/releaser/issues"+        else do+          T.writeFile cabalFile $ T.replace versionPrev ("version: " <> T.pack versionStr) cabal+          logStep $ "Bumped " <> name cabalinfo <> " to " <> versionStr     else do-      T.writeFile cabalFile $ T.replace versionPrev ("version: " <> T.pack versionStr) cabal-      logStep $ "Bumped " <> name cabalinfo <> " to " <> versionStr-  else do-    promptRetry "Cabal version does not match /^[0-9]+([.][0-9]+)*$/"-    void $ cabalBumpVersion dir-    +      promptRetry "Cabal version does not match /^[0-9]+([.][0-9]+)*$/"+      void $ cabalBumpVersion dir  validCabalVersion :: String -> Bool validCabalVersion version =@@ -151,7 +166,7 @@   interactiveProcess (proc "cabal" ["upload", "--publish", sdistTarball]) $ \_ -> do     promptRetry "cabal upload"     cabalUpload sdistTarball-    + gitGetTags :: IO [String] gitGetTags = do   lines <$> readProcess "git" ["tag"] mempty@@ -161,7 +176,7 @@ gitCheckout tag = do   logStep $ "Running $ git checkout -b " <> tag   -- TODO: check for existing branch-  interactiveProcess (proc "git" ["checkout", "-b", tag]) $ \i -> do +  interactiveProcess (proc "git" ["checkout", "-b", tag]) $ \i -> do     promptRetry "git checkout failed"     gitCheckout tag @@ -170,23 +185,22 @@   logStep $ "Running $ git tag --annotate --sign " <> tag   tags <- gitGetTags   if elem tag tags-  then abort "git tag already exists, please delete it and start over"-  else interactiveProcess (proc "git" ["tag", "--annotate", "--sign", tag]) $ \i -> do -    promptRetry "git tag failed"-    gitTag tag+    then abort "git tag already exists, please delete it and start over"+    else interactiveProcess (proc "git" ["tag", "--annotate", "--sign", tag]) $ \i -> do+      promptRetry "git tag failed"+      gitTag tag  gitCommit :: String -> IO () gitCommit message = do   logStep $ "Running $ git commit "-  interactiveProcess (proc "git" ["commit", "-a", "-m", message]) $ \i -> do +  interactiveProcess (proc "git" ["commit", "-a", "-m", message]) $ \i -> do     promptRetry "git commit failed"     gitCommit message - gitPush :: String -> IO () gitPush remote = do   logStep $ "Pushing git to " <> remote-  interactiveProcess (proc "git" ["push", remote, "HEAD"]) $ \i -> do +  interactiveProcess (proc "git" ["push", remote, "HEAD"]) $ \i -> do     promptRetry "git push"     gitPush remote @@ -200,8 +214,8 @@   logStep "Assserting there are no uncommitted files"   output <- readProcess "git" ["status", "--untracked-files=no", "--porcelain"] mempty   if output == ""-  then return ()-  else abort "git status is not clean"+    then return ()+    else abort "git status is not clean"  changelogPrepare :: IO () changelogPrepare = do