[Haskell-cafe] Picking up the CI buildnumber during build
Magnus Therning
magnus at therning.org
Fri May 4 18:51:15 UTC 2018
Vanessa McHale <vanessa.mchale at iohk.io> writes:
> Hi Magnus,
>
> I would use getEnv
> <http://hackage.haskell.org/package/base-4.11.1.0/docs/System-Environment.html#v:getEnv>
> or lookupEnv, along with Template Haskell and the runIO
> <http://hackage.haskell.org/package/template-haskell-2.13.0.0/docs/Language-Haskell-TH-Syntax.html#v:runIO>
> function. This would allow you to embed environment variables at
> compile
> time.
Thanks! That were indeed the functions I was looking for. I ended
up with
the following:
```haskell
import Data.Maybe (fromMaybe)
import Language.Haskell.TH (ExpQ, runIO, stringE)
import System.Environment (lookupEnv)
getBuildEnv :: String -> String -> ExpQ
getBuildEnv def varname = (runIO $ fromMaybe def <$> lookupEnv
varname) >>= stringE
```
/M
--
Magnus Therning OpenPGP: 0x927912051716CE39
email: magnus at therning.org jabber: magnus at therning.org
twitter: magthe http://therning.org/magnus
Ah, good taste! What a dreadful thing! Taste is the enemy of
creativeness.
— Pablo Picasso
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180504/b919e019/attachment.sig>
More information about the Haskell-Cafe
mailing list