diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 7a94ebf8..29cbed5e 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -79,6 +79,9 @@ blocks: # Print working directory for debugging purposes - "pwd" + # Check version consistency between hoff.cabal and hoff.nix + - "./package/check-version.sh" + # Run build and tests in Nix # Because this is a public repository, and not everyone is using Nix, # we keep the stack setup around. The Nix build however is used in production. diff --git a/app/Main.hs b/app/Main.hs index 34ac7f29..668d11d9 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -14,6 +14,7 @@ import Control.Monad (forM, unless, void) import Control.Monad.IO.Class (liftIO) import Control.Monad.Logger (runStdoutLoggingT) import Data.List (zip4) +import Data.Version (showVersion) import System.Exit (die) import System.IO (BufferMode (LineBuffering), hSetBuffering, stderr, stdout) @@ -29,6 +30,8 @@ import Project (ProjectState, emptyProjectState, loadProjectState, saveProjectSt import Project (ProjectInfo (ProjectInfo), Owner) import Server (buildServer) +import qualified Paths_hoff (version) + import qualified Configuration as Config import qualified Git import qualified Github @@ -37,6 +40,9 @@ import qualified Logic import qualified Project import qualified Time +version :: String +version = showVersion Paths_hoff.version + data Options = Options { configFilePath :: FilePath , readOnly :: Bool @@ -46,8 +52,12 @@ commandLineParser :: Opts.ParserInfo Options commandLineParser = let optConfigFilePath = Opts.argument Opts.str (Opts.metavar "") - optReadOnly = Opts.switch (Opts.long "read-only") - opts = Options <$> optConfigFilePath <*> optReadOnly + optReadOnly = Opts.switch $ Opts.long "read-only" + <> Opts.help "Run in read-only mode" + optVersion = Opts.infoOption ("Hoff v" <> version) + $ Opts.long "version" + <> Opts.help "Displays version and exit" + opts = Options <$> optConfigFilePath <*> optReadOnly <* optVersion help = Opts.fullDesc <> Opts.header "A gatekeeper for your commits" in Opts.info (opts <**> Opts.helper) help @@ -92,6 +102,7 @@ runMain options = do hSetBuffering stdout LineBuffering hSetBuffering stderr LineBuffering + putStrLn $ "Starting Hoff v" ++ version putStrLn $ "Config file: " ++ (configFilePath options) putStrLn $ "Read-only: " ++ (show $ readOnly options) diff --git a/hoff.cabal b/hoff.cabal index 291b0463..67eb8f4b 100644 --- a/hoff.cabal +++ b/hoff.cabal @@ -1,4 +1,5 @@ name: hoff +-- please keep version consistent with hoff.nix version: 0.27.0 category: Development synopsis: A gatekeeper for your commits @@ -61,6 +62,8 @@ library , wai , warp , warp-tls + other-modules: Paths_hoff + autogen-modules: Paths_hoff executable hoff default-language: Haskell2010 @@ -76,6 +79,8 @@ executable hoff , monad-logger , optparse-applicative , text + other-modules: Paths_hoff + autogen-modules: Paths_hoff test-suite spec default-language: Haskell2010 diff --git a/hoff.nix b/hoff.nix index 0ca42646..24d98d06 100644 --- a/hoff.nix +++ b/hoff.nix @@ -4,7 +4,7 @@ let in haskellPackages.mkDerivation { pname = "hoff"; - version = "0.27.0"; + version = "0.27.0"; # please keep consistent with hoff.cabal src = let diff --git a/package/check-version.sh b/package/check-version.sh new file mode 100755 index 00000000..746e9809 --- /dev/null +++ b/package/check-version.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Checks if the version number is consistent between hoff.cabal and hoff.nix +cabal_version=$( + grep "^version:" stylesheetBase64Digest) body $ - div ! id "content" $ + div ! id "content" $ do bodyHtml + p ! style "text-align:right;font-size:smaller;margin-top:2em" $ "Hoff v" <> toHtml (showVersion version) -- Integrity attribute for subresource integrity. Blaze doesn't have -- this yet, but this is what their implementation would look like.