Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 45 additions & 203 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,230 +1,72 @@
# This file is generated by `bellroy-github-actions`.
# Think twice before editing it directly.
name: Haskell CI

on:
pull_request:
branches:
- master
workflow_dispatch: {}
workflow_dispatch:

permissions:
contents: read

env:
CABAL_FILE_RELATIVE_PATH_NO_EXTENSION: github-actions
CABAL_VERSION: 3.16.0.0
GHCUP_VERSION: 0.1.50.2
LANG: C.UTF-8
LANGUAGE_EDITION: Haskell2010
LC_ALL: C.UTF-8
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
generate-matrix:
name: Generate matrix from cabal
runs-on: ubuntu-24.04
timeout-minutes: 30
matrix:
name: Generate matrix from cabal file
runs-on: ubuntu-slim
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Extract the tested GHC versions
id: set-matrix
id: matrix
uses: kleidukos/get-tested@a55a250eac23bcc4bcd1cb22d77be61baea5a7e2
with:
cabal-file: github-actions.cabal
ubuntu-version: 24.04
ubuntu-version: latest

tests:
name: ${{ matrix.ghc }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs:
- generate-matrix
needs: [matrix]
timeout-minutes: 30
container:
image: buildpack-deps:jammy
strategy:
matrix:
include:
- ${{ (fromJSON(needs.generate-matrix.outputs.matrix)).include }}
env:
HCKIND: ghc
HCNAME: ghc-${{ matrix.ghc }}
HCVER: ${{ matrix.ghc }}
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
steps:
- name: apt
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git libtinfo5
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/$GHCUP_VERSION/x86_64-linux-ghcup-$GHCUP_VERSION > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal $CABAL_VERSION || (cat "$HOME"/.ghcup/logs/*.* && false)

- name: Set PATH and environment variables
run: |
echo "$HOME/.cabal/bin" >> $GITHUB_PATH

HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')

{
echo "LANG=C.UTF-8"
echo "CABAL_DIR=$HOME/.cabal"
echo "CABAL_CONFIG=$HOME/.cabal/config"
echo "HC=$HC"
echo "HCPKG=$HCPKG"
echo "HADDOCK=$HADDOCK"
echo "CABAL=$HOME/.ghcup/bin/cabal-$CABAL_VERSION -vnormal+nowrap"
echo "HCNUMVER=$HCNUMVER"
echo "ARG_TESTS=--enable-tests"
echo "ARG_BENCH=--enable-benchmarks"
echo "HEADHACKAGE=false"
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC"
echo "GHCJSARITH=0"
} >> $GITHUB_ENV

- name: env
run: |
env

- name: write cabal config
run: |
mkdir -p $CABAL_DIR
cat >> $CABAL_CONFIG <<EOF
remote-build-reporting: anonymous
write-ghc-environment-files: never
remote-repo-cache: $CABAL_DIR/packages
logs-dir: $CABAL_DIR/logs
world-file: $CABAL_DIR/world
extra-prog-path: $CABAL_DIR/bin
symlink-bindir: $CABAL_DIR/bin
installdir: $CABAL_DIR/bin
build-summary: $CABAL_DIR/logs/build.log
store-dir: $CABAL_DIR/store
install-dirs user
prefix: $CABAL_DIR
repository hackage.haskell.org
url: http://hackage.haskell.org/
EOF
cat >> $CABAL_CONFIG <<EOF
program-default-options
ghc-options: $GHCJOBS +RTS -M3G -RTS
EOF
cat $CABAL_CONFIG

- name: versions
run: |
$HC --version || true
$HC --print-project-git-commit-id || true
$CABAL --version || true

- name: update cabal index
run: |
$CABAL v2-update -v

- name: restore cache (~/.haskell-ci-tools)
uses: actions/cache@v6
- name: Generate App token
id: token
uses: actions/create-github-app-token@v3
with:
key: ${{ runner.os }}-${{ matrix.ghc }}-tools-ac1dc7e1
path: ~/.haskell-ci-tools

- name: install cabal-plan
run: |
mkdir -p $HOME/.cabal/bin
curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.7.3.0/cabal-plan-0.7.3.0-x86_64-linux.xz > cabal-plan.xz
echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c -
xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan
rm -f cabal-plan.xz
chmod a+x $HOME/.cabal/bin/cabal-plan
cabal-plan --version

- name: install doctest
run: |
$CABAL --store-dir=$HOME/.haskell-ci-tools/store v2-install $ARG_COMPILER --ignore-project -j2 doctest --constraint='doctest ^>=0.24.0'
doctest --version
client-id: ${{ vars.ACTIONS_CHECKOUT_APP_CLIENT_ID }}
private-key: ${{ secrets.ACTIONS_CHECKOUT_APP_PRIVATE_KEY }}
repositories: actions

- name: checkout
- name: Checkout action
uses: actions/checkout@v7
with:
clean: false
path: source

- name: initial cabal.project for sdist
run: |
touch cabal.project
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
cat cabal.project

- name: sdist
run: |
mkdir -p sdist
$CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist

- name: unpack
run: |
mkdir -p unpacked
find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \;

- name: generate cabal.project
run: |
PKGDIR_PROJECT="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*\/'$CABAL_FILE_RELATIVE_PATH_NO_EXTENSION'-[0-9.]*')"
echo "PKGDIR_PROJECT=${PKGDIR_PROJECT}" >> "$GITHUB_ENV"
rm -f cabal.project cabal.project.local
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_PROJECT}" >> cabal.project
echo "package $CABAL_FILE_RELATIVE_PATH_NO_EXTENSION" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^('$CABAL_FILE_RELATIVE_PATH_NO_EXTENSION')$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local

- name: dump install plan
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all
cabal-plan
repository: bellroy/actions
token: ${{ steps.token.outputs.token }}
sparse-checkout: haskell-os-ci
ref: haskell-os-ci-v1

- name: restore cache (~/.cabal/store)
uses: actions/cache@v6
- name: Validate build, tests, and packaging
uses: ./haskell-os-ci
with:
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal') }}
path: ~/.cabal/store
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-

- name: install dependencies
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all

- name: build w/o tests
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all

- name: build
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always

- name: tests
run: |
$CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct

- name: doctest
run: |
cd ${PKGDIR_PROJECT} || false
doctest -X$LANGUAGE_EDITION src

- name: cabal check
run: |
cd ${PKGDIR_PROJECT} || false
${CABAL} -vnormal check

- name: haddock
run: |
$CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all

- name: unconstrained build
run: |
rm -f cabal.project.local
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
cabal-file-relative-path: github-actions
language-edition: Haskell2010

tests-completion:
name: All tests jobs completed
runs-on: ubuntu-slim
if: ${{ !cancelled() }}
needs: [tests]
steps:
- name: Fan in matrix
run: |
if [[ "${{ needs.tests.result }}" == "failure" ]]; then
echo "::error::Testing one or more GHC versions have failed"
exit 1
else
echo "::info::All tests have succeeded"
fi
Loading