Skip to content

Commit

Permalink
Setup formatters in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Oct 3, 2024
1 parent 58e885e commit 052e3be
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 3 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Sources
# * https://github.com/haskell-actions/setup/tree/v2/?tab=readme-ov-file#model-cabal-workflow-with-caching
# * https://github.com/actions/starter-workflows/blob/main/pages/static.yml
#
name: Documentation

on:
push:
branches: [ "main" ]
workflow_dispatch:

permissions:
contents: read

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:

build-documentation:
name: Build documentation

runs-on: ubuntu-latest

strategy:
fail-fast: false

env:
ghc: "9.6.6"
cabal: "3.12.1.0"
os: ubuntu-latest"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ env.ghc }}
cabal-version: ${{ env.cabal }}
cabal-update: true

- name: Configure the build
run: |
cabal configure --disable-tests --disable-benchmarks --enable-documentation
cabal build all --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Cache cabal store
uses: actions/cache@v4
env:
cache-name: ${{ runner.os }}-${{ env.ghc }}-documentation-cabal-store
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ env.cache-name }}-${{ hashFiles('**/plan.json') }}
restore-keys: |
${{ env.cache-name }}-${{ hashFiles('**/plan.json') }}
${{ env.cache-name }}-
- name: Build haddocks
run: |
cabal haddock-project --internal --hackage --haddock-options="--gen-index --gen-contents --quickjump" all
tar vzcf haddocks.tgz ./haddocks
- name: Upload haddocks as an artifact
uses: actions/upload-artifact@v4
with:
name: haddocks
path: haddocks.tgz
retention-days: 1


# deploy-documentation:
# name: Deploy documentation to GitHub Pages

# needs: build-documentation

# runs-on: ubuntu-latest

# strategy:
# fail-fast: false

# # https://github.com/actions/deploy-pages
# permissions:
# pages: write
# id-token: write

# environment:
# name: github-pages
# url: ${{ steps.deployment.outputs.page_url }}

# steps:
# - name: Checkout
# uses: actions/checkout@v4

# - name: Setup Pages
# uses: actions/configure-pages@v5

# - name: Download haddocks artifact
# uses: actions/download-artifact@v4
# with:
# name: haddocks

# - name: Unpack haddocks artifact
# run: |
# tar vzxf haddocks.tgz

# - name: Upload haddocks artifact to pages
# uses: actions/upload-pages-artifact@v3
# with:
# path: ./docs/haddocks

# - name: Deploy to GitHub pages
# id: deployment
# uses: actions/deploy-pages@v4
163 changes: 163 additions & 0 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,166 @@ jobs:
- name: Run tests
run: |
cabal test -j1 all
# Check formatting for Haskell files
stylish-haskell:
name: "stylish-haskell"
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
ghc: ["9.6"]
cabal: ["3.12.1.0"]
os: [ubuntu-latest]

# Fix the index-state so we can get proper caching effects. Change this to a
# more recent time if you want to use a newer version of stylish-haskell, or
# if you want stylish-haskell to use updated dependencies.
#
# We use this environment variable in the primary key of our caches, and as
# an argument to cabal install. This ensures that we never rebuild
# dependencies because of newly uploaded packages unless we want to.
env:
hackage-index-state: "2024-05-30T00:00:00Z"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install system dependencies (apt-get)
run: |
sudo apt-get update
sudo apt-get -y install fd-find
- name: Setup Haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
cabal-update: false

- name: Cabal update
run: cabal update

- name: Setup cabal bin path
run: echo "$HOME/.cabal/bin" >> $GITHUB_PATH

- name: Cache cabal store
uses: actions/cache@v4
env:
cache-name: cache-cabal-stylish
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ env.cache-name }}-${{ env.hackage-index-state }}
restore-keys: |
${{ runner.os }}-${{ matrix.ghc }}-${{ env.cache-name }}-
- name: Install stylish-haskell
run: cabal install --ignore-project --index-state="${{ env.hackage-index-state }}" stylish-haskell --constraint 'stylish-haskell == 0.14.6.0'

- name: Record stylish-haskell version
run: |
which stylish-haskell
stylish-haskell --version
- name: Run stylish-haskell
run: |
./scripts/format-stylish.sh -p . -d
git diff --exit-code
# Check formatting for cabal files
cabal-gild:
name: "cabal-gild"
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
ghc: ["9.6"]
cabal: ["3.12.1.0"]
os: [ubuntu-latest]

# See the comment on the hackage-index-state environment variable for the
# stylish-haskell job.
env:
hackage-index-state: "2024-07-01T14:40:46Z"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install system dependencies (apt-get)
run: |
sudo apt-get update
sudo apt-get -y install fd-find
- name: Setup Haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
cabal-update: false

- name: Cabal update
run: cabal update

- name: Setup cabal bin path
run: echo "$HOME/.cabal/bin" >> $GITHUB_PATH

- name: Cache cabal store
uses: actions/cache@v4
env:
cache-name: cache-cabal-cabal-fmt
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ env.cache-name }}-${{ env.hackage-index-state }}
restore-keys: |
${{ runner.os }}-${{ matrix.ghc }}-${{ env.cache-name }}-
- name: Install cabal-gild
run: cabal install --ignore-project cabal-gild --constraint 'cabal-gild == 1.5.0.1'

- name: Record cabal-gild version
run: |
which cabal-gild
cabal-gild --version
- name: Run cabal-gild
run: |
./scripts/format-cabal.sh
git diff --exit-code
# Check cabal files
cabal-check:
name: "cabal check"
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
ghc: ["9.6"]
cabal: ["3.12.1.0"]
os: [ubuntu-latest]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
cabal-update: false

- name: Cabal update
run: cabal update

- name: Run cabal check
run: |
./scripts/check-cabal.sh
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ cabal.sandbox.config
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
.ghc.environment.*

docs/
haddocks/
2 changes: 1 addition & 1 deletion cardano-lmdb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description:
LMDB is a read-optimized Berkeley DB replacement developed by Symas
for the OpenLDAP project. LMDB has impressive performance characteristics
and a friendly BSD-style OpenLDAP license. See <http://symas.com/mdb/>.
.

This library has Haskell bindings to the LMDB library. You must install
the lmdb development files before installing this library,
e.g. `sudo apt-get install liblmdb-dev` works for Ubuntu.
Expand Down
12 changes: 12 additions & 0 deletions scripts/check-cabal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -euo pipefail

for x in $(find . -name '*.cabal' | grep -v dist-newstyle | cut -c 3-); do
(
d=$(dirname $x)
echo "== $d =="
cd $d
cabal check
)
done
2 changes: 1 addition & 1 deletion src/simple/Database/LMDB/Simple/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ size view = viewIO view $ \(txn, dbi) -> do
-- | Is the key a member of the view? See also 'notMember'.
member :: Serialise k => k -> View k v -> Bool
member key view = viewIO view $ \(txn, dbi) ->
marshalOut key (fmap isJust . mdb_get' txn dbi kval)
marshalOut key (fmap isJust . mdb_get' txn dbi)

-- | Is the key not a member of the view? See also 'member'.
notMember :: Serialise k => k -> View k v -> Bool
Expand Down

0 comments on commit 052e3be

Please sign in to comment.