Skip to content

Instantly share code, notes, and snippets.

@mstksg
Last active September 30, 2021 08:16
Show Gist options
  • Save mstksg/11f753d891cee5980326a8ea8c865233 to your computer and use it in GitHub Desktop.
Save mstksg/11f753d891cee5980326a8ea8c865233 to your computer and use it in GitHub Desktop.
Stack Project Github Action Template
# Haskell stack project Github Actions template
# https://gist.github.com/mstksg/11f753d891cee5980326a8ea8c865233
#
# To use, mainly change the list in 'plans' and modify 'include' for
# any OS package manager deps.
#
# Currently not working for cabal-install >= 3
#
# Based on https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/travis-complex.yml
#
# TODO:
# * cache (https://github.com/actions/cache)
# but this is too small. native cacheing will come soon
# https://git.521000.bestmunity/t5/GitHub-Actions/Caching-files-between-GitHub-Action-executions/m-p/30974/highlight/true#M630
# so we can wait for then.
# * support for cabal-install >= 3
name: Haskell Stack Project CI
on:
push:
schedule:
- cron: "0 0 * * 1"
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
# use this to specify what resolvers and ghc to use
plan:
- { build: stack, resolver: "--resolver lts-9" } # ghc-8.0.2
- { build: stack, resolver: "--resolver lts-11" } # ghc-8.2.2
- { build: stack, resolver: "--resolver lts-12" } # ghc-8.4.4
# - { build: stack, resolver: "--resolver lts-13" } redundant because lts-14 checks ghc-8.6 already
- { build: stack, resolver: "--resolver lts-14" } # ghc-8.6.5
- { build: stack, resolver: "--resolver nightly" }
- { build: stack, resolver: "" }
- { build: cabal, ghc: 8.0.2, cabal-install: "2.0" } # setup-haskell only supports cabal-install 2.0 and higher
- { build: cabal, ghc: 8.2.2, cabal-install: "2.0" }
- { build: cabal, ghc: 8.4.4, cabal-install: "2.2" }
- { build: cabal, ghc: 8.6.5, cabal-install: "2.4" }
- { build: cabal, ghc: 8.8.1, cabal-install: "2.4" } # currently not working for >= 3.0
# use this to include any dependencies from OS package managers
include: []
# - os: macOS-latest
# brew: anybrewdeps
# - os: ubuntu-latest
# apt-get: happy libblas-dev liblapack-dev
exclude:
- os: macOS-latest
plan:
build: cabal
runs-on: ${{ matrix.os }}
steps:
- name: Install OS Packages
uses: mstksg/get-package@v1
with:
apt-get: ${{ matrix.apt-get }}
brew: ${{ matrix.brew }}
- uses: actions/checkout@v1
- name: Setup stack
uses: mstksg/setup-stack@v1
- name: Setup cabal-install
uses: actions/setup-haskell@v1
with:
ghc-version: ${{ matrix.plan.ghc }}
cabal-version: ${{ matrix.plan.cabal-install }}
if: matrix.plan.build == 'cabal'
- name: Install dependencies
run: |
set -ex
case "$BUILD" in
stack)
stack --no-terminal --install-ghc $ARGS test --bench --only-dependencies
;;
cabal)
cabal --version
cabal update
PACKAGES=$(stack --install-ghc query locals | grep '^ *path' | sed 's@^ *path:@@')
cabal install --only-dependencies --enable-tests --enable-benchmarks --force-reinstalls --ghc-options=-O0 --reorder-goals --max-backjumps=-1 $CABALARGS $PACKAGES
;;
esac
set +ex
env:
ARGS: ${{ matrix.plan.resolver }}
BUILD: ${{ matrix.plan.build }}
- name: Build
run: |
set -ex
case "$BUILD" in
stack)
stack --no-terminal $ARGS test --bench --no-run-benchmarks --haddock --no-haddock-deps
;;
cabal)
PACKAGES=$(stack --install-ghc query locals | grep '^ *path' | sed 's@^ *path:@@')
cabal install --enable-tests --enable-benchmarks --force-reinstalls --ghc-options=-O0 --reorder-goals --max-backjumps=-1 $CABALARGS $PACKAGES
ORIGDIR=$(pwd)
for dir in $PACKAGES
do
cd $dir
cabal check || [ "$CABALVER" == "1.16" ]
cabal sdist
PKGVER=$(cabal info . | awk '{print $2;exit}')
SRC_TGZ=$PKGVER.tar.gz
cd dist
tar zxfv "$SRC_TGZ"
cd "$PKGVER"
cabal configure --enable-tests --ghc-options -O0
cabal build
if [ "$CABALVER" = "1.16" ] || [ "$CABALVER" = "1.18" ]; then
cabal test
else
cabal test --show-details=streaming --log=/dev/stdout
fi
cd $ORIGDIR
done
;;
esac
set +ex
env:
ARGS: ${{ matrix.plan.resolver }}
BUILD: ${{ matrix.plan.build }}
@simonmichael
Copy link

Thanks for this! Very helpful.

Do you think there's anything in this which prevents it working on windows ? For some reason github actions is not recognising windows-latest or windows-2019 for me.

@mstksg
Copy link
Author

mstksg commented Mar 6, 2020

@simonmichael

Glad it was helpful! Most of this is copied from the official stack travis-ci script, which wasn't written with windows in mind. I am not really sure what the best way is to add windows support, unfortunately -- this isn't exactly my wheelhouse :|

@simonmichael
Copy link

@mstksg: I simplified and made some pretty good progress - CI with caching working on three platforms: https://github.com/simonmichael/hledger/tree/master/.github/workflows

@ocramz
Copy link

ocramz commented Mar 26, 2020

@mstksg @simonmichael wow, this is super useful, thanks!

@gillchristian
Copy link

Very cool! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment