Skip to content

Commit fc37bcb

Browse files
committed
enable CI via github actions
1 parent 0272748 commit fc37bcb

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Tests for the Haskell Phrasebook
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
test:
7+
name: Test the examples
8+
runs-on: ubuntu-latest
9+
continue-on-error: ${{ matrix.channel == 'nixos-unstable' }}
10+
11+
strategy:
12+
matrix:
13+
channel:
14+
- nixos-unstable
15+
- nixos-20.09
16+
17+
steps:
18+
- uses: actions/checkout@v2.3.4
19+
20+
- uses: cachix/install-nix-action@v12
21+
with:
22+
nix_path: nixpkgs=channel:${{ matrix.channel }}
23+
24+
- uses: cachix/cachix-action@v8
25+
with:
26+
name: typeclasses
27+
28+
- run: ./tools/test

tools/haskell.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
haskell.packages.ghc8103.ghcWithPackages (p: [
44
p.async
5+
p.bytestring
56
p.containers
67
p.cryptonite
8+
p.directory
9+
p.filepath
710
p.generic-deriving
811
p.hashable
912
p.memory

tools/test

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure
3+
#! nix-shell --keep NIX_PATH
4+
#! nix-shell -i runhaskell
5+
#! nix-shell -p ghc nix rsync cacert
6+
7+
{-# language ScopedTypeVariables #-}
8+
9+
-- This is the test script run by the CI server.
10+
11+
import Control.Monad
12+
import System.Directory
13+
import System.Process
14+
import System.Exit
15+
import System.FilePath ((</>))
16+
import qualified Data.ByteString as ByteString
17+
18+
main = (build >>= copy) *> (findProblems >>= conclude)
19+
20+
-- Builds all of the example outputs in the Nix store and returns the path.
21+
build :: IO FilePath =
22+
fmap (head . lines) $ readProcess "nix-build" ["--attr", "outputs", "--no-out-link", "tools/default.nix"] ""
23+
24+
-- Copies the example outputs from the Nix store into the "outputs-test" directory.
25+
copy (src :: FilePath) =
26+
callProcess "rsync" ["--copy-links", "--recursive", "--chmod=ugo=rwX", src <> "/", "outputs-test"]
27+
28+
-- The "outputs" and "outputs-test" directories should be identical. This action returns a list of the filenames that differ.
29+
findProblems :: IO [FilePath] =
30+
listDirectory "outputs" >>= filterM isProblem
31+
32+
-- Given an output file name, determines whether the file in "outputs" differs from the corresponding file in "outputs-test".
33+
isProblem (filename :: FilePath) =
34+
pure (/=)
35+
<*> ByteString.readFile ("outputs" </> filename)
36+
<*> ByteString.readFile ("outputs-test" </> filename)
37+
38+
-- If the problem list is non-empty, prints the list of problems and exits with a nonzero status code to indicate failure.
39+
conclude (problems :: [FilePath]) =
40+
if null problems then putStrLn "Okay!"
41+
else die ("Problems: " <> show problems)

0 commit comments

Comments
 (0)