summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-04-01 19:33:07 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-04-01 19:33:07 +0200
commit10327858acc48286cec97ebc4f01b6aa2e7ae460 (patch)
tree35a4e45a03b16b046c18646206e65832308f7343
parent1eacd0f0b02c40c94d063d4cebc2343c882f50bb (diff)
Derive version number from git if available
-rw-r--r--.gitignore5
-rw-r--r--Makefile9
-rw-r--r--erebos-webapp.cabal8
-rw-r--r--src/Main.hs3
-rw-r--r--src/Version.hs16
-rw-r--r--src/Version/Git.hs3
6 files changed, 42 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ca8c0c9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+/gen/
+/dist-newstyle/
+/ghc_wasm_jsffi.js
+/.minici/
+/.test/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9bba516
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+all: gen/Version/Git.hs
+ wasm32-wasi-cabal build
+ $(shell wasm32-wasi-ghc --print-libdir)/post-link.mjs -i $(shell wasm32-wasi-cabal list-bin erebos-webapp) -o ghc_wasm_jsffi.js
+
+gen/Version/Git.hs: FORCE
+ @mkdir -p gen/Version
+ @if [ -d .git ]; then echo "module Version.Git where gitVersion :: Maybe String; gitVersion = Just \"$$(git describe --always --dirty=' (dirty)')\"" > $@; fi
+
+FORCE: ;
diff --git a/erebos-webapp.cabal b/erebos-webapp.cabal
index c59829d..11cd6dd 100644
--- a/erebos-webapp.cabal
+++ b/erebos-webapp.cabal
@@ -28,9 +28,12 @@ executable erebos-webapp
main-is: Main.hs
other-modules:
JavaScript
+ Paths_erebos_webapp
Storage.Cache
Storage.IndexedDB
Storage.WatchList
+ Version
+ Version.Git
WebSocket
default-extensions:
@@ -69,5 +72,8 @@ executable erebos-webapp
time ^>= { 1.14 },
uuid-types ^>= { 1.0.4 },
- hs-source-dirs: src
+ hs-source-dirs:
+ gen
+ src
+
default-language: GHC2021
diff --git a/src/Main.hs b/src/Main.hs
index 54e121b..795cabe 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -43,6 +43,7 @@ import Text.Blaze.Html.Renderer.String
import JavaScript qualified as JS
import Storage.Cache
import Storage.IndexedDB
+import Version
import WebSocket (startClient, receiveMessage)
main :: IO ()
@@ -208,7 +209,7 @@ setup = do
H.button ! A.type_ "submit" $ "set name"
H.div ! A.id "version" $ do
- "v0.1.0"
+ H.toHtml versionLine
when (js_string_is_null experimentalAccepted) $ do
H.div ! A.id "experimental_warning" $ do
diff --git a/src/Version.hs b/src/Version.hs
new file mode 100644
index 0000000..cca3c6d
--- /dev/null
+++ b/src/Version.hs
@@ -0,0 +1,16 @@
+module Version (
+ versionLine,
+) where
+
+import Paths_erebos_webapp (version)
+import Data.Version (showVersion)
+import Version.Git
+
+{-# NOINLINE versionLine #-}
+versionLine :: String
+versionLine = do
+ let ver = case gitVersion of
+ Just gver
+ -> "git " <> gver
+ _ -> "v" <> showVersion version
+ in ver
diff --git a/src/Version/Git.hs b/src/Version/Git.hs
new file mode 100644
index 0000000..ecf8715
--- /dev/null
+++ b/src/Version/Git.hs
@@ -0,0 +1,3 @@
+module Version.Git where
+gitVersion :: Maybe String
+gitVersion = Nothing