Skip to content

Commit

Permalink
websocket bump, doctests added (#10)
Browse files Browse the repository at this point in the history
* websocket bump, doctests added

* CI fixes
  • Loading branch information
tonyday567 authored Oct 12, 2024
1 parent a986a38 commit da64054
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 112 deletions.
76 changes: 31 additions & 45 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
name: build
on: [push]
name: haskell-ci

# INFO: The following configuration block ensures that only one build runs per branch,
# which may be desirable for projects with a costly build process.
# Remove this block from the CI workflow to let each CI job run to completion.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
hlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: haskell-actions/hlint-setup@v2
- uses: haskell-actions/hlint-run@v2
with:
Expand All @@ -13,90 +21,68 @@ jobs:
ormolu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: haskell-actions/run-ormolu@v14
cabal:
- uses: actions/checkout@v4
- uses: haskell-actions/run-ormolu@v16
build:
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: ['9.8', '9.6', '9.4', '9.2', '8.10']
docspec: [false]
experimental: [false]
ghc-version: ['9.10', '9.8', '9.6']

include:
- os: windows-latest
ghc-version: '9.6'
ghc-version: '9.8'
- os: macos-latest
ghc-version: '9.6'
- os: ubuntu-latest
ghc-version: '9.6'
docspec: true
experimental: true
name: docspec
ghc-version: '9.8'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up GHC ${{ matrix.ghc-version }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}

- name: Installed minor versions of GHC and Cabal
shell: bash
run: |
GHC_VERSION=$(ghc --numeric-version)
CABAL_VERSION=$(cabal --numeric-version)
echo "GHC_VERSION=${GHC_VERSION}" >> "${GITHUB_ENV}"
echo "CABAL_VERSION=${CABAL_VERSION}" >> "${GITHUB_ENV}"
- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
cabal build --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Restore cached dependencies
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: |
${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
# If we had an exact cache hit, the dependencies will be up to date.
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
uses: actions/cache/save@v3
# Caches are immutable, trying to save with the same key would error.
if: ${{ !steps.cache.outputs.cache-hit
|| steps.cache.outputs.cache-primary-key != steps.cache.outputs.cache-matched-key }}
uses: actions/cache/save@v4
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal build all

- if: ${{ matrix.os == 'ubuntu-latest' && matrix.ghc-version == '9.8'}}
name: doctests
run: cabal run doctests

- name: Check cabal file
run: cabal check

- if: matrix.docspec
name: cabal-docspec
run: |
mkdir -p $HOME/.cabal/bin
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
curl -sL https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20230406/cabal-docspec-0.0.0.20230406-x86_64-linux.xz > cabal-docspec.xz
echo '68fa9addd5dc453d533a74a763950499d4593b1297c9a05c3ea5bd1acc04c9dd cabal-docspec.xz' | sha256sum -c -
xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec
rm -f cabal-docspec.xz
chmod a+x $HOME/.cabal/bin/cabal-docspec
$HOME/.cabal/bin/cabal-docspec --version
cabal-docspec
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/docs/
/cabal.project.local*
/.hkgr/
/.ghc.environment.aarch64-darwin-9.10.1
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
packages:
web-rep.cabal

write-ghc-environment-files: always

tests: True

allow-newer: websockets:containers
72 changes: 72 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

# Table of Contents

1. [web-rep](#orgebbc06e)
2. [library reference](#org8d29302)
3. [Development](#orgddf3f50)


<a id="orgebbc06e"></a>

# web-rep

[![img](https://img.shields.io/hackage/v/web-rep.svg)](https://hackage.haskell.org/package/web-rep) [![img](https://github.com/tonyday567/web-rep/workflows/haskell-ci/badge.svg)](https://github.com/tonyday567/web-rep/actions?query=workflow%3Ahaskell-ci)

Various functions and representations for a web page.

The best way to understand functionality is via running the example app:

cabal install
page-example --apptype SharedTest

&#x2026; and then tune in to:

<http://localhost:9160/>


<a id="org8d29302"></a>

# library reference

- [scotty](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/flags.html#flag-reference)
- [bootstrap](https://getbootstrap.com/)
- [bootstrap-slider](https://seiyria.com/bootstrap-slider)


<a id="orgddf3f50"></a>

# Development

(setq haskell-process-args-cabal-repl '("web-rep:exe:web-rep-example"))

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">


<colgroup>
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">web-rep:exe:web-rep-example</td>
</tr>
</tbody>
</table>

:r
:set -Wno-type-defaults
:set -Wno-name-shadowing
:set -XOverloadedStrings
:set -XOverloadedLabels
:set -XDataKinds
import Prelude
import Box
import Web.Rep
import Optics.Core
import FlatParse.Basic
import MarkupParse
putStrLn "ok"

Ok, 11 modules loaded.
ghci
ok

7 changes: 3 additions & 4 deletions src/Web/Rep/Bootstrap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ cardify (h, hatts) t (b, batts) =
<> element
"div"
([Attr "class" "card-body"] <> batts)
( maybe mempty (elementc "h5" [Attr "class" "card-title"]) t <> b
)
(maybe mempty (elementc "h5" [Attr "class" "card-title"]) t <> b)

-- | A Html object based on the bootstrap accordion card concept.
accordionCard :: Bool -> [Attr] -> ByteString -> ByteString -> ByteString -> ByteString -> Markup -> Markup
Expand Down Expand Up @@ -173,7 +172,7 @@ accordion ::
m Markup
accordion pre x hs = do
idp' <- genNamePre pre
element "div" [Attr "class" "accordion m-1", Attr "id" idp'] <$> (mconcat <$> aCards idp')
element "div" [Attr "class" "accordion m-1", Attr "id" idp'] . mconcat <$> aCards idp'
where
aCards par = mapM (aCard par) hs
aCard par (t, b) = do
Expand All @@ -185,7 +184,7 @@ accordion pre x hs = do
accordionChecked :: (MonadState Int m) => ByteString -> [(ByteString, Markup, Markup)] -> m Markup
accordionChecked pre hs = do
idp' <- genNamePre pre
element "div" [Attr "class" "accordion m-1", Attr "id" idp'] <$> (mconcat <$> aCards idp')
element "div" [Attr "class" "accordion m-1", Attr "id" idp'] . mconcat <$> aCards idp'
where
aCards par = mapM (aCard par) hs
aCard par (l, bodyhtml, checkhtml) = do
Expand Down
3 changes: 1 addition & 2 deletions src/Web/Rep/Html/Input.hs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ markupInput _ (Input _ l i (Checkbox checked)) =
]
<> bool [] [Attr "checked" ""] checked
)
( maybe mempty (elementc "label" [Attr "for" i, Attr "class" "form-label-check mb-0"]) l
)
(maybe mempty (elementc "label" [Attr "for" i, Attr "class" "form-label-check mb-0"]) l)
)
markupInput _ (Input _ l i (Toggle pushed lab)) =
element
Expand Down
3 changes: 1 addition & 2 deletions src/Web/Rep/SharedReps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ repChoice initt xs =
element
"div"
[]
( dd' <> mconcat (zipWith (addSubtype t0) ts cs')
)
(dd' <> mconcat (zipWith (addSubtype t0) ts cs'))
mmap dd' cs' = maybe (List.head cs') (cs' List.!!) (List.elemIndex dd' ts)

-- | select test keys from a Map
Expand Down
8 changes: 8 additions & 0 deletions test/doctests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Main where

import System.Environment (getArgs)
import Test.DocTest (mainFromCabal)
import Prelude (IO, (=<<))

main :: IO ()
main = mainFromCabal "web-rep" =<< getArgs
76 changes: 18 additions & 58 deletions web-rep.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: web-rep
version: 0.12.1.0
version: 0.12.2.0
license: BSD-3-Clause
license-file: LICENSE
copyright: Tony Day (c) 2015
Expand All @@ -14,10 +14,13 @@ description:
An applicative-based, shared-data representation of a web page.

build-type: Simple
tested-with: GHC == 8.10.7 || ==9.2.7 || ==9.4.7 || ==9.6.3 || ==9.8.1
tested-with:
, GHC == 9.10.1
, GHC == 9.6.5
, GHC == 9.8.2
extra-doc-files:
ChangeLog.md
readme.org
readme.md

source-repository head
type: git
Expand All @@ -42,60 +45,7 @@ common ghc-options-stanza
-Wredundant-constraints

common ghc2021-stanza
if impl ( ghc >= 9.2 )
default-language: GHC2021

if impl ( ghc < 9.2 )
default-language: Haskell2010
default-extensions:
BangPatterns
BinaryLiterals
ConstrainedClassMethods
ConstraintKinds
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DoAndIfThenElse
EmptyCase
EmptyDataDecls
EmptyDataDeriving
ExistentialQuantification
ExplicitForAll
FlexibleContexts
FlexibleInstances
ForeignFunctionInterface
GADTSyntax
GeneralisedNewtypeDeriving
HexFloatLiterals
ImplicitPrelude
InstanceSigs
KindSignatures
MonomorphismRestriction
MultiParamTypeClasses
NamedFieldPuns
NamedWildCards
NumericUnderscores
PatternGuards
PolyKinds
PostfixOperators
RankNTypes
RelaxedPolyRec
ScopedTypeVariables
StandaloneDeriving
StarIsType
TraditionalRecordSyntax
TupleSections
TypeApplications
TypeOperators
TypeSynonymInstances

if impl ( ghc < 9.2 ) && impl ( ghc >= 8.10 )
default-extensions:
ImportQualifiedPost
StandaloneKindSignatures
default-language: GHC2021

library
import: ghc-options-stanza
Expand All @@ -121,7 +71,7 @@ library
, unordered-containers >=0.2 && <0.3
, wai-middleware-static >=0.9 && <0.10
, wai-websockets >=3.0.1.2 && <3.1
, websockets >=0.12 && <0.13
, websockets >=0.12 && <0.14
exposed-modules:
Web.Rep
Web.Rep.Bootstrap
Expand All @@ -148,3 +98,13 @@ executable web-rep-example
, optics-core >=0.4 && <0.5
, optparse-applicative >=0.17 && <0.19
, web-rep

test-suite doctests
import: ghc2021-stanza
main-is: doctests.hs
hs-source-dirs: test
build-depends:
, base >=4.14 && <5
, doctest-parallel >=0.3 && <0.4
ghc-options: -threaded
type: exitcode-stdio-1.0
2 changes: 1 addition & 1 deletion readme.org → web-rep.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* web-rep

[[https://hackage.haskell.org/package/numhask-array][file:https://img.shields.io/hackage/v/web-rep.svg]] [[https://github.com/tonyday567/numhask-array/actions?query=workflow%3Ahaskell-ci][file:https://github.com/tonyday567/web-rep/workflows/haskell-ci/badge.svg]]
[[https://hackage.haskell.org/package/web-rep][file:https://img.shields.io/hackage/v/web-rep.svg]] [[https://github.com/tonyday567/web-rep/actions?query=workflow%3Ahaskell-ci][file:https://github.com/tonyday567/web-rep/workflows/haskell-ci/badge.svg]]

Various functions and representations for a web page.

Expand Down

0 comments on commit da64054

Please sign in to comment.