Skip to content

Commit

Permalink
Improve CI and build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rudymatela committed Jul 6, 2023
1 parent f280b63 commit 7ff228a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
37 changes: 20 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Builds and tests this Haskell project on "GitHub Actions"
#
# 2021 Rudy Matela
# 2021-2023 Rudy Matela
#
# some docs: https://github.com/haskell/actions/tree/main/setup
#
# The official haskell docker image: https://hub.docker.com/_/haskell
name: build
on: [push]
jobs:
Expand All @@ -11,34 +13,37 @@ jobs:
steps:

- name: Cache ~/.cabal/packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cabal/packages
key: v1-${{ runner.os }}-cabal-packages-${{ hashFiles('hello.cabal') }}
key: v1-${{ runner.os }}-cabal-packages-${{ hashFiles('*.cabal') }}
restore-keys: v1-${{ runner.os }}-cabal-packages-

- name: Cache ~/.cabal and ~/.ghc
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cabal
!~/.cabal/packages
~/.ghc
key: v1-${{ runner.os }}-cabal-ghc-latest-${{ hashFiles('hello.cabal') }}
key: v1-${{ runner.os }}-cabal-ghc-latest-${{ hashFiles('*.cabal') }}
restore-keys: v1-${{ runner.os }}-cabal-ghc-latest-

- run: du -hd3 ~/.cabal ~/.ghc || true

- run: make --version

- run: haddock --version || sudo apt-get install ghc-haddock
- run: ghc --version
- run: cabal --version
- run: haddock --version
- run: ghc-pkg list

- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- run: git --version

- run: cabal update
- run: make install-dependencies

- run: make
Expand All @@ -62,26 +67,25 @@ jobs:
- '8.2'
- '8.0'
- '7.10'
- '7.8'
runs-on: ubuntu-latest
needs: build-and-test
container: haskell:${{ matrix.ghc }}
steps:
- name: Cache ~/.cabal/packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cabal/packages
key: v1-${{ runner.os }}-cabal-packages-${{ hashFiles('hello.cabal') }}
key: v1-${{ runner.os }}-cabal-packages-${{ hashFiles('*.cabal') }}
restore-keys: v1-${{ runner.os }}-cabal-packages-

- name: Cache ~/.cabal and ~/.ghc
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cabal
!~/.cabal/packages
~/.ghc
key: v1-${{ runner.os }}-cabal-ghc-${{ matrix.ghc }}-${{ hashFiles('hello.cabal') }}
key: v1-${{ runner.os }}-cabal-ghc-${{ matrix.ghc }}-${{ hashFiles('*.cabal') }}
restore-keys: v1-${{ runner.os }}-cabal-ghc-${{ matrix.ghc }}-

- run: du -hd3 ~/.cabal ~/.ghc || true
Expand All @@ -96,9 +100,8 @@ jobs:
- run: ghc-pkg list

- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- run: cabal update
- run: make install-dependencies

- run: make
Expand All @@ -112,12 +115,12 @@ jobs:
needs: build-and-test
steps:
- name: Setup Haskell's GHC and Cabal as required by current Stackage LTS
uses: haskell/actions/setup@v1
uses: haskell/actions/setup@v2
with: # lts-19.19
ghc-version: '9.0.2'
cabal-version: '3.4'

- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/.stack
key: v1-${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}
Expand All @@ -126,5 +129,5 @@ jobs:
- run: stack --version

- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: make test-via-stack
9 changes: 6 additions & 3 deletions mk/haskell.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Implicit rules for compiling Haskell code.
#
# Copyright (c) 2015-2021 Rudy Matela.
# Copyright (c) 2015-2023 Rudy Matela.
# Distributed under the 3-Clause BSD licence.
#
# You can optionally configure the "Configuration variables" below in your main
Expand All @@ -21,7 +21,7 @@ GHCFLAGS ?=
GHC ?= ghc
GHCCMD = $(GHC) -i$(GHCIMPORTDIRS) $(GHCFLAGS)
HADDOCK ?= haddock
CABAL_INSTALL = $(shell cabal --version | grep -q "version [0-2]\." && echo 'cabal install' || echo 'cabal v1-install')
CABAL_INSTALL = $(shell cabal --version | grep -q "version [0-2]\." && echo 'cabal install' || echo 'cabal install --lib')

# Hugs Parameters
HUGSIMPORTDIRS ?= "/usr/lib/hugs/packages/*"
Expand Down Expand Up @@ -90,7 +90,10 @@ depend:
find $(ALL_HSS) | ./mk/ghcdeps -i$(GHCIMPORTDIRS) $(GHCFLAGS) > $(DEPMK)

install-dependencies:
$(CABAL_INSTALL) $(INSTALL_DEPS)
if [ -n "$(INSTALL_DEPS)" ]; then \
cabal update && \
$(CABAL_INSTALL) $(INSTALL_DEPS); \
fi

# haddock rules
haddock: doc/index.html
Expand Down
8 changes: 6 additions & 2 deletions test/sdist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# test/sdist: tests the package generated by "cabal sdist".
#
# Copyright (c) 2015-2021 Rudy Matela.
# Copyright (c) 2015-2023 Rudy Matela.
# Distributed under the 3-Clause BSD licence.

set -xe
Expand All @@ -29,7 +29,11 @@ tar -tf $pkg | sort --ignore-case > $tmp/ls-cabal-i
tar -tf $pkg | sort --ignore-case --unique > $tmp/ls-cabal-iu
diff -rud $tmp/ls-cabal-i $tmp/ls-cabal-iu

if [ -d .git ]
# Check if we have a clone of the repo and git is available
# The check that we can run git ls-files is needed to avoid:
# fatal: detected dubious ownership in repository at '/__w/.../hello-haskell'
# on CI.
if [ -d .git ] && git --version && git ls-files >/dev/null
then
# Test if files included by cabal are the same as files tracked in git.
git ls-files | sort > $tmp/ls-git
Expand Down

0 comments on commit 7ff228a

Please sign in to comment.