Skip to content

Commit

Permalink
CI: Massive rewrite
Browse files Browse the repository at this point in the history
Based on GHA from node and build with ghc-9.2.4 as well.
  • Loading branch information
erikd committed Nov 29, 2022
1 parent f4c8738 commit 34a7156
Showing 1 changed file with 144 additions and 35 deletions.
179 changes: 144 additions & 35 deletions .github/workflows/haskell.yml
@@ -1,73 +1,182 @@
name: Haskell CI

on: [push]
on:
push:
workflow_dispatch:
inputs:
tests:
description: 'Tests'
required: false
default: 'some'
options:
- some
- all
create:

jobs:
build:
runs-on: ${{ matrix.os }}

defaults:
run:
shell: bash
shell: ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}

strategy:
fail-fast: false
matrix:
ghc: ["8.10.2"]
# Add more elements to this list to run multiple instances of the build in CI. Increasing the
# number instances is a good way to trigger flaky build failures
n: [1]

ghc: ["8.10.7", "9.2.4"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v1

- name: Select build directory
run: echo "CABAL_BUILDDIR=dist" >> $GITHUB_ENV

- name: Add build script path
run: echo "$(pwd)/.github/bin" >> $GITHUB_PATH

- name: Install pkgconfiglite
if: matrix.os == 'windows-latest'
run: retry 3 choco install -y pkgconfiglite

- uses: actions/setup-haskell@v1
- name: "WIN: Setup MSYS2 and libraries"
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
update: true
install: >-
base-devel
autoconf-wrapper
autoconf
automake
libtool
make
git
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-libsodium
mingw-w64-x86_64-jq
- name: "LINUX,MAC: Setup haskell"
if: runner.os != 'Windows'
uses: haskell/actions/setup@v1
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: '3.4.0.0'
cabal-version: 3.8.1.0

- name: Patch GHC 8.10.2 linker
if: matrix.os == 'windows-latest' && matrix.ghc == '8.10.2'
- name: "WIN: Setup Haskell"
id: win-setup-haskell
if: runner.os == 'Windows'
run: |
sed -i \
's|C:/GitLabRunner/builds/2WeHDSFP/0/ghc/ghc/inplace/mingw/bin/ld.exe|C:/ProgramData/chocolatey/lib/ghc.8.10.2/tools/ghc-8.10.2/mingw/bin/ld.exe|g' \
C:/ProgramData/chocolatey/lib/ghc.8.10.2/tools/ghc-8.10.2/lib/settings
# see https://gitlab.haskell.org/haskell/ghcup-hs/-/blob/master/scripts/bootstrap/bootstrap-haskell
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | \
BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
BOOTSTRAP_HASKELL_ADJUST_CABAL_CONFIG=1 \
BOOTSTRAP_HASKELL_ADJUST_BASHRC=1 \
BOOTSTRAP_HASKELL_GHC_VERSION="${{ matrix.ghc }}" \
BOOTSTRAP_HASKELL_CABAL_VERSION="3.6.2.0" \
sh
# MSYS2 doesn't inherit $GITHUB_PATH so this is needed
cat <(echo "source /c/ghcup/env") ~/.bashrc > ~/.bashrc.new
mv ~/.bashrc.new ~/.bashrc
source ~/.bashrc
# There is an issue with crt libraries, fixed by prepending the ghc
# mingw32 libraries directory to every other library directory.
echo "# Original cabal config extra-lib-dirs"
grep extra-lib-dirs /c/cabal/config
sed -i 's/C:\\msys64\\mingw64\\lib/C:\\ghcup\\ghc\\8.10.7\\mingw\\x86_64-w64-mingw32\\lib, C:\\msys64\\mingw64\\lib/g' /c/cabal/config
echo "# Modified cabal config extra-lib-dirs"
grep extra-lib-dirs /c/cabal/config
ghc --version
cabal --version
echo "cabal-store=$(cabal --help | tail -1 | tr -d ' ' | rev | cut -d '/' -f2- | rev)\\store" >> $GITHUB_OUTPUT
- name: Set cache version
run: echo "CACHE_VERSION=grFfw8r" >> $GITHUB_ENV

- uses: actions/checkout@v2

- name: Install build environment
if: matrix.os == 'ubuntu-latest'
- name: Add build script path
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
# MSYS2 doesn't inherit $GITHUB_PATH, so this workaround is needed
cat <(echo "export PATH=$PATH:$(pwd)/.github/bin") ~/.bashrc > ~/.bashrc.new
mv ~/.bashrc.new ~/.bashrc
else
# MacOS and Linux use $GITUB_PATH
echo "$(pwd)/.github/bin" >> $GITHUB_PATH
fi
- name: "LINUX: Install build environment (apt-get)"
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get -y install libsodium23 libsodium-dev
sudo apt-get -y install libsystemd0 libsystemd-dev
sudo apt-get -y remove --purge software-properties-common
sudo apt-get -y autoremove
- name: "MAC: Install build environment (brew)"
if: runner.os == 'macOS'
run: |
brew install libsodium
- name: "List all pkg-config packages"
run: |
if [ "${{ runner.os }}" == "macOS" ]; then
echo "=== Not printing every package detail in MacOS"
# due to the location of the installed libraries this fails on MacOS with stuff not related to us
else
echo "=== Package list ==="
pkg-config --list-all
echo "=== Package details ==="
for x in $(pkg-config --list-all | cut -d ' ' -f 1); do
echo "# $x"
pkg-config "$x" --cflags --libs
done
fi
- name: Cabal update
run: retry 3 cabal update
run: retry 2 cabal update

- name: Cabal Configure
run: retry 3 cabal configure --enable-tests --enable-benchmarks --write-ghc-environment-files=always
- name: Configure build
run: |
if [ "${{github.event.inputs.tests}}" == "all" ]; then
echo "Reconfigure cabal projects to run tests for all dependencies"
sed -i 's|tests: False|tests: True|g' cabal.project
fi
- uses: actions/cache@v2
name: Cache cabal store
- name: Record dependencies
id: record-deps
run: |
cabal build all --dry-run
cat ${{ env.PLAN_JSON }} | jq -r '."install-plan"[].id' | sort | uniq > dependencies.txt
date > date.txt
echo "weeknum=$(/bin/date -u "+%W")" >> $GITHUB_OUTPUT
- name: Cache Cabal store
uses: actions/cache@v2
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: cache-${{ runner.os }}-${{ matrix.ghc }}-v1-${{ hashFiles('cabal-cache.cabal') }}-${{ github.sha }}
restore-keys: cache-${{ runner.os }}-${{ matrix.ghc }}-v1-${{ hashFiles('cabal-cache.cabal') }}-
path: ${{ runner.os == 'Windows' && steps.win-setup-haskell.outputs.cabal-store || steps.setup-haskell.outputs.cabal-store }}
key: cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}-${{ hashFiles('date.txt') }}
restore-keys: |
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}
- name: Install dependencies
run: retry 3 cabal build all --only-dependencies
- uses: actions/cache@v2
name: "Cache `dist-newstyle`"
with:
path: |
dist-newstyle
!dist-newstyle/**/.git
key: cache-dist-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ steps.record-deps.outputs.weeknum }}
restore-keys: cache-dist-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}

- name: Build
run: retry 3 cabal build all
run: cabal build all

- name: Run tests
run: TMPDIR="${{ runner.temp }}" TMP="${{ runner.temp }}" cabal test all
run: |
TMPDIR="${{ runner.temp }}" TMP="${{ runner.temp }}" KEEP_WORKSPACE=1 cabal test all;

0 comments on commit 34a7156

Please sign in to comment.