From e9cd43723dd785a94a942e7d92494dac0bcdf609 Mon Sep 17 00:00:00 2001
From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Date: Sat, 24 Apr 2021 12:04:16 -0400
Subject: [PATCH] Publish docs to GitHub Pages (#15)
---
.github/workflows/docs.yaml | 28 ++++++++++++++++++++++++++++
.gitignore | 3 ++-
README.md | 8 ++++++++
docs/Main.hs | 6 ++++++
ema.cabal | 10 +++++++++-
flake.nix | 16 ++++++++++++----
hie.yaml | 2 ++
7 files changed, 67 insertions(+), 6 deletions(-)
create mode 100644 .github/workflows/docs.yaml
create mode 100644 docs/Main.hs
diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml
new file mode 100644
index 0000000..32e7a4f
--- /dev/null
+++ b/.github/workflows/docs.yaml
@@ -0,0 +1,28 @@
+name: "Publish Ema Docs"
+on:
+ # Run only when pushing to master branch
+ push:
+ branches:
+ - master
+jobs:
+ docs:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: cachix/install-nix-action@v13
+ with:
+ install_url: https://nixos-nix-install-tests.cachix.org/serve/lb41az54kzk6j12p81br4bczary7m145/install
+ install_options: "--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve"
+ extra_nix_config: |
+ experimental-features = nix-command flakes
+ # This builds neuron, as well as run tests
+ - name: Build and generate docs HTML 🔧
+ run: |
+ nix run -- generate ./docs-output
+ - name: Deploy to GitHub Pages 🚀
+ uses: JamesIves/github-pages-deploy-action@3.7.1
+ with:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ BRANCH: gh-pages
+ FOLDER: docs-output
+ CLEAN: true
diff --git a/.gitignore b/.gitignore
index f62f6bd..f84fac6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,4 +22,5 @@ cabal.project.local~
.HTF/
.ghc.environment.*
result
-result-*
\ No newline at end of file
+result-*
+docs-output/
\ No newline at end of file
diff --git a/README.md b/README.md
index d115576..1a8b395 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,14 @@ main = do
encodeUtf8 $ "Hello, from " <> name
```
+## Quick Preview
+
+If you have Nix installed with Flakes, give Ema a test-drive by running it to serve its own documentation:
+
+```bash
+PORT=8000 nix run
+```
+
## Hacking
Run `bin/run` (or Ctrl+Shift+B in VSCode). This runs the clock example; modify `./.ghcid` to run a different example.
diff --git a/docs/Main.hs b/docs/Main.hs
new file mode 100644
index 0000000..fa006f7
--- /dev/null
+++ b/docs/Main.hs
@@ -0,0 +1,6 @@
+module Main where
+
+import qualified Ema.Example.Ex03_Documentation as Doc
+
+main :: IO ()
+main = Doc.main
diff --git a/ema.cabal b/ema.cabal
index 1d139ca..395d15d 100644
--- a/ema.cabal
+++ b/ema.cabal
@@ -113,10 +113,18 @@ library
Ema.Server
if flag(with-examples)
- other-modules:
+ exposed-modules:
Ema.Example.Ex01_HelloWorld
Ema.Example.Ex02_Clock
Ema.Example.Ex03_Documentation
hs-source-dirs: src
default-language: Haskell2010
+
+executable ema-docs
+ hs-source-dirs: docs
+ default-language: Haskell2010
+ main-is: Main.hs
+ build-depends:
+ , base
+ , ema
\ No newline at end of file
diff --git a/flake.nix b/flake.nix
index 804956c..df181da 100644
--- a/flake.nix
+++ b/flake.nix
@@ -11,14 +11,14 @@
outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
let
+ name = "ema";
overlays = [ ];
pkgs = import nixpkgs {
inherit system overlays;
};
emaProject = returnShellEnv:
pkgs.haskellPackages.developPackage {
- inherit returnShellEnv;
- name = "ema";
+ inherit name returnShellEnv;
root = ./.;
withHoogle = false;
modifier = drv:
@@ -32,12 +32,20 @@
haskell-language-server
]);
};
+ ema = emaProject false;
in
- {
+ rec {
# Used by `nix build`
- defaultPackage = emaProject false;
+ defaultPackage = ema;
# Used by `nix develop`
devShell = emaProject true;
+
+ # Used by `nix run` (for docs)
+ apps.${name} = flake-utils.lib.mkApp {
+ drv = ema;
+ exePath = "/bin/ema-docs";
+ };
+ defaultApp = apps.${name};
});
}
diff --git a/hie.yaml b/hie.yaml
index 08ab24f..566ec27 100644
--- a/hie.yaml
+++ b/hie.yaml
@@ -2,3 +2,5 @@ cradle:
cabal:
- path: "./src"
component: "library:ema"
+ - path: "./docs"
+ component: "exe:ema-docs"