From 5095e476f02e2e9763fbe58ca763296c6d9ad94a Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 14:48:03 +0200 Subject: [PATCH 01/11] Add --version command line switch ... and report version upon starting Hoff. --- app/Main.hs | 5 ++++- hoff.cabal | 2 ++ src/Version.hs | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/Version.hs diff --git a/app/Main.hs b/app/Main.hs index 34ac7f29..effdd255 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -36,6 +36,7 @@ import qualified GithubApi import qualified Logic import qualified Project import qualified Time +import qualified Version data Options = Options { configFilePath :: FilePath @@ -47,7 +48,8 @@ commandLineParser = let optConfigFilePath = Opts.argument Opts.str (Opts.metavar "") optReadOnly = Opts.switch (Opts.long "read-only") - opts = Options <$> optConfigFilePath <*> optReadOnly + optVersion = Opts.infoOption ("Hoff v" <> Version.version) (Opts.long "version") + opts = Options <$> optConfigFilePath <*> optReadOnly <* optVersion help = Opts.fullDesc <> Opts.header "A gatekeeper for your commits" in Opts.info (opts <**> Opts.helper) help @@ -92,6 +94,7 @@ runMain options = do hSetBuffering stdout LineBuffering hSetBuffering stderr LineBuffering + putStrLn $ "Starting Hoff v" ++ Version.version putStrLn $ "Config file: " ++ (configFilePath options) putStrLn $ "Read-only: " ++ (show $ readOnly options) diff --git a/hoff.cabal b/hoff.cabal index 291b0463..82f37333 100644 --- a/hoff.cabal +++ b/hoff.cabal @@ -1,4 +1,5 @@ name: hoff +-- please also update src/Version.hs version: 0.27.0 category: Development synopsis: A gatekeeper for your commits @@ -29,6 +30,7 @@ library , Server , Time , Types + , Version , WebInterface build-depends: aeson diff --git a/src/Version.hs b/src/Version.hs new file mode 100644 index 00000000..81453b2a --- /dev/null +++ b/src/Version.hs @@ -0,0 +1,13 @@ +-- Hoff -- A gatekeeper for your commits +-- Copyright 2022 Channable +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- A copy of the License has been included in the root of the repository. +module Version (version) where + +-- | Hoff's version number encoded in a String. +-- +-- To be displayed on the web interface or by running @ hoff --version @. +version :: String +version = "0.26.2" -- please also update hoff.cabal From 9300f0177fce02d32acc1cef65538d595416b2a6 Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 15:27:36 +0200 Subject: [PATCH 02/11] Display version on the web interface --- src/WebInterface.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/WebInterface.hs b/src/WebInterface.hs index 5db6c3dd..8e06325c 100644 --- a/src/WebInterface.hs +++ b/src/WebInterface.hs @@ -23,7 +23,7 @@ import Text.Blaze (toValue, (!)) import Text.Blaze.Html.Renderer.Utf8 import Text.Blaze.Html5 (Html, a, body, div, docTypeHtml, h1, h2, h3, head, link, meta, p, span, title, toHtml) -import Text.Blaze.Html5.Attributes (charset, class_, content, href, id, name, rel) +import Text.Blaze.Html5.Attributes (charset, class_, content, href, id, name, rel, style) import Text.Blaze.Internal (Attribute, AttributeValue, attribute) import qualified Data.ByteString.Lazy as LazyByteString @@ -36,6 +36,7 @@ import Project (Approval (..), BuildStatus (..), IntegrationStatus (..), Owner, import Types (PullRequestId (..), Username (..)) import qualified Project +import qualified Version -- TODO: Minify this css at inclusion time. stylesheet :: Text @@ -79,8 +80,9 @@ renderPage pageTitle bodyHtml = renderHtml $ docTypeHtml $ do link ! rel "stylesheet" ! href (toValue googlefontsUrl) link ! rel "stylesheet" ! href (toValue stylesheetUrl) ! integrity (toValue $ "sha256-" <> stylesheetBase64Digest) body $ - div ! id "content" $ + div ! id "content" $ do bodyHtml + p ! style "text-align:right;font-size:smaller;margin-top:2em" $ "Hoff v" <> toHtml Version.version -- Integrity attribute for subresource integrity. Blaze doesn't have -- this yet, but this is what their implementation would look like. From 86ed6996a4825f935f02d2395dbb91a65582db04 Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 15:32:28 +0200 Subject: [PATCH 03/11] Add (CI) check that versions in cabal&src match --- .semaphore/semaphore.yml | 3 +++ package/check-version.sh | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100755 package/check-version.sh diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 7a94ebf8..3e9cd92c 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -79,6 +79,9 @@ blocks: # Print working directory for debugging purposes - "pwd" + # Check if version in source is the same as in the cabal file + - "./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/package/check-version.sh b/package/check-version.sh new file mode 100755 index 00000000..50f60455 --- /dev/null +++ b/package/check-version.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# +# Checks if the version number in hoff.cabal is the same as src/Version.hs + +cabal_version=$( grep "^version:" Date: Tue, 16 Aug 2022 15:32:49 +0200 Subject: [PATCH 04/11] Document CI check alternative --- package/check-version.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/package/check-version.sh b/package/check-version.sh index 50f60455..72a3bd20 100755 --- a/package/check-version.sh +++ b/package/check-version.sh @@ -1,6 +1,16 @@ #!/bin/bash # # Checks if the version number in hoff.cabal is the same as src/Version.hs +# +# This is intended to be called on Semaphore. +# +# One alternative to this scripts would be to add this test directly on +# test/*.hs while imposing a dependency on Cabal-syntax there. +# Then we could "properly" parse the Cabal file to get the version: +# +# https://hackage.haskell.org/package/Cabal-syntax-3.8.1.0/docs/Distribution-Types-GenericPackageDescription.html#t:GenericPackageDescription +# +# But for a simple check like this, that may be overengineering. cabal_version=$( grep "^version:" Date: Tue, 16 Aug 2022 15:40:43 +0200 Subject: [PATCH 05/11] Document --version and --read-only options --- app/Main.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index effdd255..1c5fe197 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -47,8 +47,11 @@ commandLineParser :: Opts.ParserInfo Options commandLineParser = let optConfigFilePath = Opts.argument Opts.str (Opts.metavar "") - optReadOnly = Opts.switch (Opts.long "read-only") - optVersion = Opts.infoOption ("Hoff v" <> Version.version) (Opts.long "version") + optReadOnly = Opts.switch $ Opts.long "read-only" + <> Opts.help "Run in read-only mode" + optVersion = Opts.infoOption ("Hoff v" <> Version.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 From a84da2d86ff7108f09c8f38ad3fddb0cfeabe9e6 Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 15:58:39 +0200 Subject: [PATCH 06/11] check-version: include nix version check --- package/check-version.sh | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/package/check-version.sh b/package/check-version.sh index 72a3bd20..9351f74a 100755 --- a/package/check-version.sh +++ b/package/check-version.sh @@ -1,25 +1,42 @@ #!/bin/bash # -# Checks if the version number in hoff.cabal is the same as src/Version.hs +# Checks if the version number is consistent across different files: +# * hoff.cabal +# * hoff.nix +# * src/Version.hs # -# This is intended to be called on Semaphore. +# This is intended to be called on CI (Semaphore). # -# One alternative to this scripts would be to add this test directly on -# test/*.hs while imposing a dependency on Cabal-syntax there. -# Then we could "properly" parse the Cabal file to get the version: +# We could overengineer this by: # -# https://hackage.haskell.org/package/Cabal-syntax-3.8.1.0/docs/Distribution-Types-GenericPackageDescription.html#t:GenericPackageDescription +# * Including the check in test/Spec.hs or test/*.hs; # -# But for a simple check like this, that may be overengineering. +# * using Cabal-syntax's GenericPackageDescription function +# to "properly" parse the version in the cabal file; +# +# * similarly "properly" parsing hoff.nix thorugh Haskell. +# +# This is simpler, easier and effective. -cabal_version=$( grep "^version:" Date: Tue, 16 Aug 2022 16:02:26 +0200 Subject: [PATCH 07/11] semaphore.yml: update comment --- .semaphore/semaphore.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 3e9cd92c..5b4d6eb8 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -79,7 +79,8 @@ blocks: # Print working directory for debugging purposes - "pwd" - # Check if version in source is the same as in the cabal file + # Check version consistency between + # hoff.cabal, hoff.nix and src/Version.hs. - "./package/check-version.sh" # Run build and tests in Nix From c73cbd1a416d8e3d199cb3296ff415342a5d6075 Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 16:04:42 +0200 Subject: [PATCH 08/11] Improve consistency comments. --- hoff.cabal | 2 +- hoff.nix | 2 +- src/Version.hs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hoff.cabal b/hoff.cabal index 82f37333..49e91327 100644 --- a/hoff.cabal +++ b/hoff.cabal @@ -1,5 +1,5 @@ name: hoff --- please also update src/Version.hs +-- please keep version consistent with hoff.nix and src/Version.hs version: 0.27.0 category: Development synopsis: A gatekeeper for your commits diff --git a/hoff.nix b/hoff.nix index 0ca42646..dc965e43 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 and src/Version.hs src = let diff --git a/src/Version.hs b/src/Version.hs index 81453b2a..64d55b75 100644 --- a/src/Version.hs +++ b/src/Version.hs @@ -10,4 +10,4 @@ module Version (version) where -- -- To be displayed on the web interface or by running @ hoff --version @. version :: String -version = "0.26.2" -- please also update hoff.cabal +version = "0.26.2" -- please also update hoff.cabal and hoff.nix From 33a95d38e12d8242dda0f466572861fa7b3c02f1 Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 16:06:00 +0200 Subject: [PATCH 09/11] update notice --- src/Version.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Version.hs b/src/Version.hs index 64d55b75..2dfca27f 100644 --- a/src/Version.hs +++ b/src/Version.hs @@ -1,5 +1,6 @@ -- Hoff -- A gatekeeper for your commits -- Copyright 2022 Channable +-- Copyright 2016 Ruud van Asseldonk -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. From de3d3a32bb5054edb1cbac1df16d46097adeb7f7 Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 16:32:18 +0200 Subject: [PATCH 10/11] Remove Version.hs in favour of Paths_hoff --- .semaphore/semaphore.yml | 3 +-- app/Main.hs | 11 ++++++++--- hoff.cabal | 5 +++-- hoff.nix | 2 +- package/check-version.sh | 28 +++------------------------- src/Version.hs | 14 -------------- src/WebInterface.hs | 6 ++++-- 7 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 src/Version.hs diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 5b4d6eb8..29cbed5e 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -79,8 +79,7 @@ blocks: # Print working directory for debugging purposes - "pwd" - # Check version consistency between - # hoff.cabal, hoff.nix and src/Version.hs. + # Check version consistency between hoff.cabal and hoff.nix - "./package/check-version.sh" # Run build and tests in Nix diff --git a/app/Main.hs b/app/Main.hs index 1c5fe197..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 @@ -36,7 +39,9 @@ import qualified GithubApi import qualified Logic import qualified Project import qualified Time -import qualified Version + +version :: String +version = showVersion Paths_hoff.version data Options = Options { configFilePath :: FilePath @@ -49,7 +54,7 @@ commandLineParser = optConfigFilePath = Opts.argument Opts.str (Opts.metavar "") optReadOnly = Opts.switch $ Opts.long "read-only" <> Opts.help "Run in read-only mode" - optVersion = Opts.infoOption ("Hoff v" <> Version.version) + optVersion = Opts.infoOption ("Hoff v" <> version) $ Opts.long "version" <> Opts.help "Displays version and exit" opts = Options <$> optConfigFilePath <*> optReadOnly <* optVersion @@ -97,7 +102,7 @@ runMain options = do hSetBuffering stdout LineBuffering hSetBuffering stderr LineBuffering - putStrLn $ "Starting Hoff v" ++ Version.version + 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 49e91327..ae0b6a0f 100644 --- a/hoff.cabal +++ b/hoff.cabal @@ -1,5 +1,5 @@ name: hoff --- please keep version consistent with hoff.nix and src/Version.hs +-- please keep version consistent with hoff.nix version: 0.27.0 category: Development synopsis: A gatekeeper for your commits @@ -30,7 +30,6 @@ library , Server , Time , Types - , Version , WebInterface build-depends: aeson @@ -63,6 +62,7 @@ library , wai , warp , warp-tls + other-modules: Paths_hoff executable hoff default-language: Haskell2010 @@ -78,6 +78,7 @@ executable hoff , monad-logger , optparse-applicative , text + other-modules: Paths_hoff test-suite spec default-language: Haskell2010 diff --git a/hoff.nix b/hoff.nix index dc965e43..24d98d06 100644 --- a/hoff.nix +++ b/hoff.nix @@ -4,7 +4,7 @@ let in haskellPackages.mkDerivation { pname = "hoff"; - version = "0.27.0"; # please keep consistent with hoff.cabal and src/Version.hs + version = "0.27.0"; # please keep consistent with hoff.cabal src = let diff --git a/package/check-version.sh b/package/check-version.sh index 9351f74a..746e9809 100755 --- a/package/check-version.sh +++ b/package/check-version.sh @@ -1,42 +1,20 @@ #!/bin/bash # -# Checks if the version number is consistent across different files: -# * hoff.cabal -# * hoff.nix -# * src/Version.hs -# -# This is intended to be called on CI (Semaphore). -# -# We could overengineer this by: -# -# * Including the check in test/Spec.hs or test/*.hs; -# -# * using Cabal-syntax's GenericPackageDescription function -# to "properly" parse the version in the cabal file; -# -# * similarly "properly" parsing hoff.nix thorugh Haskell. -# -# This is simpler, easier and effective. - +# Checks if the version number is consistent between hoff.cabal and hoff.nix cabal_version=$( grep "^version:" toHtml Version.version + 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. From 770f4ad4e66ed83745d4eac3c0b998b87cbd439a Mon Sep 17 00:00:00 2001 From: Rudy Matela Date: Tue, 16 Aug 2022 16:38:28 +0200 Subject: [PATCH 11/11] Add Paths_hoff to autogen-modules --- hoff.cabal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hoff.cabal b/hoff.cabal index ae0b6a0f..67eb8f4b 100644 --- a/hoff.cabal +++ b/hoff.cabal @@ -63,6 +63,7 @@ library , warp , warp-tls other-modules: Paths_hoff + autogen-modules: Paths_hoff executable hoff default-language: Haskell2010 @@ -79,6 +80,7 @@ executable hoff , optparse-applicative , text other-modules: Paths_hoff + autogen-modules: Paths_hoff test-suite spec default-language: Haskell2010