Skip to content
Merged
3 changes: 3 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -46,8 +52,12 @@ commandLineParser :: Opts.ParserInfo Options
commandLineParser =
let
optConfigFilePath = Opts.argument Opts.str (Opts.metavar "<config-file>")
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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions hoff.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -61,6 +62,8 @@ library
, wai
, warp
, warp-tls
other-modules: Paths_hoff
Comment thread
rudymatela marked this conversation as resolved.
autogen-modules: Paths_hoff

executable hoff
default-language: Haskell2010
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hoff.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions package/check-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Checks if the version number is consistent between hoff.cabal and hoff.nix
cabal_version=$(
grep "^version:" <hoff.cabal |
sed 's/.*version: *//; s/ .*//'
)
nix_version=$(
grep "^[\t ]*version *=" <hoff.nix |
sed 's/.*version *= *"//; s/".*//'
)

[ "$cabal_version" = "$nix_version" ] && exit 0

cat <<MESSAGE
mismatch in versions between hoff.cabal and hoff.nix:
* hoff.cabal: $cabal_version
* hoff.nix: $nix_version
MESSAGE
exit 1
8 changes: 6 additions & 2 deletions src/WebInterface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import Data.ByteArray.Encoding (Base (Base64, Base64URLUnpadded), convertToBase)
import Data.FileEmbed (embedStringFile)
import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Version (showVersion)
import Prelude hiding (div, head, id, span)
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
Expand All @@ -37,6 +38,8 @@ import Types (PullRequestId (..), Username (..))

import qualified Project

import Paths_hoff (version)

-- TODO: Minify this css at inclusion time.
stylesheet :: Text
stylesheet = $(embedStringFile "static/style.css")
Expand Down Expand Up @@ -79,8 +82,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 (showVersion version)

-- Integrity attribute for subresource integrity. Blaze doesn't have
-- this yet, but this is what their implementation would look like.
Expand Down