Skip to content

Commit bedbdec

Browse files
authored
CI on GitHub Actions using a patched haskell-ci generated workflow (#189)
* Vanilla ci on github generated by haskell-ci Builds alex and runs the testsuite. * GHA: turn on cabal check * Test GHC without boot files * GHA: include build-tools: happy * GHA: restrict to 9.0.1 for now * GHA: include build-tools: alex * GHA: install alex and happy prior to build * Revert "Test GHC without boot files" This reverts commit e888beb. * GHA: run alex and happy like in make sdist * GHA: let tests/Makefile find alex and ghc * Revert "GHA: restrict to 9.0.1 for now" This reverts commit dc8e0fa. * GHA: document changes to tests/Makefile Trust settings of ALEX and HC from the environment, so that we can pass them in from the CI. * GHA: A patch file to the auto-generated haskell-ci.yml
1 parent ef34928 commit bedbdec

File tree

5 files changed

+339
-6
lines changed

5 files changed

+339
-6
lines changed

.github/haskell-ci.patch

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--- .github/workflows/haskell-ci.yml 2021-06-15 15:05:48.000000000 +0200
2+
+++ .github/workflows/haskell-ci.yml.patched 2021-06-15 15:05:35.000000000 +0200
3+
@@ -162,10 +162,23 @@
4+
rm -f cabal-plan.xz
5+
chmod a+x $HOME/.cabal/bin/cabal-plan
6+
cabal-plan --version
7+
+
8+
+ - name: install alex and happy
9+
+ run: |
10+
+ $CABAL v2-install $ARG_COMPILER alex happy
11+
+
12+
- name: checkout
13+
uses: actions/checkout@v2
14+
with:
15+
path: source
16+
+
17+
+ - name: generate Parser.hs and Scan.hs
18+
+ run: |
19+
+ happy -agc $GITHUB_WORKSPACE/source/src/Parser.y -o $GITHUB_WORKSPACE/source/src/Parser.hs
20+
+ alex -g $GITHUB_WORKSPACE/source/src/Scan.x -o $GITHUB_WORKSPACE/source/src/Scan.hs
21+
+ mv $GITHUB_WORKSPACE/source/src/Parser.y $GITHUB_WORKSPACE/source/src/Parser.y.boot
22+
+ mv $GITHUB_WORKSPACE/source/src/Scan.x $GITHUB_WORKSPACE/source/src/Scan.x.boot
23+
+
24+
- name: initial cabal.project for sdist
25+
run: |
26+
touch cabal.project
27+
@@ -208,15 +221,21 @@
28+
run: |
29+
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all
30+
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all
31+
- - name: build w/o tests
32+
+
33+
+ - name: build w/o tests and install
34+
run: |
35+
- $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
36+
+ $CABAL v2-install --reinstall --overwrite-policy=always $ARG_COMPILER --disable-tests --disable-benchmarks all
37+
+
38+
- name: build
39+
run: |
40+
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always
41+
- name: tests
42+
run: |
43+
+ # echo "ALEX=$HOME/.cabal/bin/alex" >> "$GITHUB_ENV"
44+
+ export ALEX=$HOME/.cabal/bin/alex
45+
+ export HC=$HC
46+
$CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct
47+
+
48+
- name: cabal check
49+
run: |
50+
cd ${PKGDIR_alex} || false

.github/workflows/haskell-ci.yml

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
# This GitHub workflow config has been generated by a script via
2+
#
3+
# haskell-ci 'github' 'alex.cabal'
4+
#
5+
# To regenerate the script (for example after adjusting tested-with) run
6+
#
7+
# haskell-ci regenerate
8+
#
9+
# For more information, see https://github.com/haskell-CI/haskell-ci
10+
#
11+
# version: 0.13.20210606
12+
#
13+
# REGENDATA ("0.13.20210606",["github","alex.cabal"])
14+
#
15+
name: Haskell-CI
16+
on:
17+
- push
18+
- pull_request
19+
jobs:
20+
linux:
21+
name: Haskell-CI - Linux - ${{ matrix.compiler }}
22+
runs-on: ubuntu-18.04
23+
container:
24+
image: buildpack-deps:bionic
25+
continue-on-error: ${{ matrix.allow-failure }}
26+
strategy:
27+
matrix:
28+
include:
29+
- compiler: ghc-9.0.1
30+
compilerKind: ghc
31+
compilerVersion: 9.0.1
32+
setup-method: hvr-ppa
33+
allow-failure: false
34+
- compiler: ghc-8.10.4
35+
compilerKind: ghc
36+
compilerVersion: 8.10.4
37+
setup-method: hvr-ppa
38+
allow-failure: false
39+
- compiler: ghc-8.8.4
40+
compilerKind: ghc
41+
compilerVersion: 8.8.4
42+
setup-method: hvr-ppa
43+
allow-failure: false
44+
- compiler: ghc-8.6.5
45+
compilerKind: ghc
46+
compilerVersion: 8.6.5
47+
setup-method: hvr-ppa
48+
allow-failure: false
49+
- compiler: ghc-8.4.4
50+
compilerKind: ghc
51+
compilerVersion: 8.4.4
52+
setup-method: hvr-ppa
53+
allow-failure: false
54+
- compiler: ghc-8.2.2
55+
compilerKind: ghc
56+
compilerVersion: 8.2.2
57+
setup-method: hvr-ppa
58+
allow-failure: false
59+
- compiler: ghc-8.0.2
60+
compilerKind: ghc
61+
compilerVersion: 8.0.2
62+
setup-method: hvr-ppa
63+
allow-failure: false
64+
- compiler: ghc-7.10.3
65+
compilerKind: ghc
66+
compilerVersion: 7.10.3
67+
setup-method: hvr-ppa
68+
allow-failure: false
69+
- compiler: ghc-7.8.4
70+
compilerKind: ghc
71+
compilerVersion: 7.8.4
72+
setup-method: hvr-ppa
73+
allow-failure: false
74+
- compiler: ghc-7.6.3
75+
compilerKind: ghc
76+
compilerVersion: 7.6.3
77+
setup-method: hvr-ppa
78+
allow-failure: false
79+
- compiler: ghc-7.4.2
80+
compilerKind: ghc
81+
compilerVersion: 7.4.2
82+
setup-method: hvr-ppa
83+
allow-failure: false
84+
- compiler: ghc-7.0.4
85+
compilerKind: ghc
86+
compilerVersion: 7.0.4
87+
setup-method: hvr-ppa
88+
allow-failure: false
89+
fail-fast: false
90+
steps:
91+
- name: apt
92+
run: |
93+
apt-get update
94+
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
95+
apt-add-repository -y 'ppa:hvr/ghc'
96+
apt-get update
97+
apt-get install -y "$HCNAME" cabal-install-3.4
98+
env:
99+
HCKIND: ${{ matrix.compilerKind }}
100+
HCNAME: ${{ matrix.compiler }}
101+
HCVER: ${{ matrix.compilerVersion }}
102+
- name: Set PATH and environment variables
103+
run: |
104+
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
105+
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
106+
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
107+
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
108+
HCDIR=/opt/$HCKIND/$HCVER
109+
HC=$HCDIR/bin/$HCKIND
110+
echo "HC=$HC" >> "$GITHUB_ENV"
111+
echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV"
112+
echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV"
113+
echo "CABAL=/opt/cabal/3.4/bin/cabal -vnormal+nowrap" >> "$GITHUB_ENV"
114+
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
115+
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
116+
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
117+
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
118+
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
119+
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
120+
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
121+
env:
122+
HCKIND: ${{ matrix.compilerKind }}
123+
HCNAME: ${{ matrix.compiler }}
124+
HCVER: ${{ matrix.compilerVersion }}
125+
- name: env
126+
run: |
127+
env
128+
- name: write cabal config
129+
run: |
130+
mkdir -p $CABAL_DIR
131+
cat >> $CABAL_CONFIG <<EOF
132+
remote-build-reporting: anonymous
133+
write-ghc-environment-files: never
134+
remote-repo-cache: $CABAL_DIR/packages
135+
logs-dir: $CABAL_DIR/logs
136+
world-file: $CABAL_DIR/world
137+
extra-prog-path: $CABAL_DIR/bin
138+
symlink-bindir: $CABAL_DIR/bin
139+
installdir: $CABAL_DIR/bin
140+
build-summary: $CABAL_DIR/logs/build.log
141+
store-dir: $CABAL_DIR/store
142+
install-dirs user
143+
prefix: $CABAL_DIR
144+
repository hackage.haskell.org
145+
url: http://hackage.haskell.org/
146+
EOF
147+
cat $CABAL_CONFIG
148+
- name: versions
149+
run: |
150+
$HC --version || true
151+
$HC --print-project-git-commit-id || true
152+
$CABAL --version || true
153+
- name: update cabal index
154+
run: |
155+
$CABAL v2-update -v
156+
- name: install cabal-plan
157+
run: |
158+
mkdir -p $HOME/.cabal/bin
159+
curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.6.2.0/cabal-plan-0.6.2.0-x86_64-linux.xz > cabal-plan.xz
160+
echo 'de73600b1836d3f55e32d80385acc055fd97f60eaa0ab68a755302685f5d81bc cabal-plan.xz' | sha256sum -c -
161+
xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan
162+
rm -f cabal-plan.xz
163+
chmod a+x $HOME/.cabal/bin/cabal-plan
164+
cabal-plan --version
165+
166+
- name: install alex and happy
167+
run: |
168+
$CABAL v2-install $ARG_COMPILER alex happy
169+
170+
- name: checkout
171+
uses: actions/checkout@v2
172+
with:
173+
path: source
174+
175+
- name: generate Parser.hs and Scan.hs
176+
run: |
177+
happy -agc $GITHUB_WORKSPACE/source/src/Parser.y -o $GITHUB_WORKSPACE/source/src/Parser.hs
178+
alex -g $GITHUB_WORKSPACE/source/src/Scan.x -o $GITHUB_WORKSPACE/source/src/Scan.hs
179+
mv $GITHUB_WORKSPACE/source/src/Parser.y $GITHUB_WORKSPACE/source/src/Parser.y.boot
180+
mv $GITHUB_WORKSPACE/source/src/Scan.x $GITHUB_WORKSPACE/source/src/Scan.x.boot
181+
182+
- name: initial cabal.project for sdist
183+
run: |
184+
touch cabal.project
185+
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
186+
cat cabal.project
187+
- name: sdist
188+
run: |
189+
mkdir -p sdist
190+
$CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist
191+
- name: unpack
192+
run: |
193+
mkdir -p unpacked
194+
find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \;
195+
- name: generate cabal.project
196+
run: |
197+
PKGDIR_alex="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/alex-[0-9.]*')"
198+
echo "PKGDIR_alex=${PKGDIR_alex}" >> "$GITHUB_ENV"
199+
rm -f cabal.project cabal.project.local
200+
touch cabal.project
201+
touch cabal.project.local
202+
echo "packages: ${PKGDIR_alex}" >> cabal.project
203+
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package alex" >> cabal.project ; fi
204+
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
205+
cat >> cabal.project <<EOF
206+
EOF
207+
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(alex)$/; }' >> cabal.project.local
208+
cat cabal.project
209+
cat cabal.project.local
210+
- name: dump install plan
211+
run: |
212+
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all
213+
cabal-plan
214+
- name: cache
215+
uses: actions/cache@v2
216+
with:
217+
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
218+
path: ~/.cabal/store
219+
restore-keys: ${{ runner.os }}-${{ matrix.compiler }}-
220+
- name: install dependencies
221+
run: |
222+
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all
223+
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all
224+
225+
- name: build w/o tests and install
226+
run: |
227+
$CABAL v2-install --reinstall --overwrite-policy=always $ARG_COMPILER --disable-tests --disable-benchmarks all
228+
229+
- name: build
230+
run: |
231+
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always
232+
- name: tests
233+
run: |
234+
# echo "ALEX=$HOME/.cabal/bin/alex" >> "$GITHUB_ENV"
235+
export ALEX=$HOME/.cabal/bin/alex
236+
export HC=$HC
237+
$CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct
238+
239+
- name: cabal check
240+
run: |
241+
cd ${PKGDIR_alex} || false
242+
${CABAL} -vnormal check
243+
- name: unconstrained build
244+
run: |
245+
rm -f cabal.project.local
246+
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all

DEVELOPER.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
This document holds some useful information for developing Alex.
2+
3+
CI on GitHub Actions
4+
====================
5+
6+
2021-06-15
7+
8+
The GHC workflow file `.github/workflows/haskell-ci.yml` is generated by:
9+
10+
haskell-ci github alex.cabal
11+
patch --input=.github/haskell-ci.patch .github/workflows/haskell-ci.yml
12+
13+
The patch introduces alex specifics to the build and test process that
14+
are not covered by a vanilla instance of the haskell-ci workflow.
15+
16+
When new GHC versions become available, CI can be updated by
17+
18+
- adding these versions to the `tested-with` field in `alex.cabal`
19+
(possibly removing obsolete minor versions)
20+
21+
- generate the `haskell-ci.yml` by the steps above.
22+
23+
This should work as long as `haskell-ci` does not change its generated
24+
workflow too much. Otherwise, the patch might not apply cleanly and
25+
the workflow has to be patched manually.

alex.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ description:
2121
category: Development
2222
build-type: Simple
2323

24-
-- Keep the contents of `tested-with` in sync with `env` in `.travis.yml`.
2524
tested-with:
2625
GHC == 7.0.4
2726
GHC == 7.4.2
@@ -32,8 +31,9 @@ tested-with:
3231
GHC == 8.2.2
3332
GHC == 8.4.4
3433
GHC == 8.6.5
35-
GHC == 8.8.3
36-
GHC == 8.10.1
34+
GHC == 8.8.4
35+
GHC == 8.10.4
36+
GHC == 9.0.1
3737

3838
data-dir: data/
3939

tests/Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@
66
# ../dist/build/alex/alex to support running tests via "runghc
77
# Setup.hs test".
88
#
9+
# If ALEX has been set outside, e.g. in the environment, we trust this setting.
10+
# This way, we can pass in the correct Alex executable from a CI environment
11+
# without danger of it being "fixed" by the logic below.
12+
# [2021-06-15, PR #189](https://github.com/simonmar/alex/pull/189)
13+
#
14+
ifndef ALEX
915
ALEX=$(shell which alex)
1016
ifeq "$(filter $(dir $(shell pwd))%,$(ALEX))" ""
1117
ALEX=../dist/build/alex/alex
1218
endif
19+
endif
1320

14-
# NOTE: This assumes that a working `ghc` is on $PATH; this may not necessarily be the same GHC used by `cabal` for building `alex`.
15-
HC = ghc
21+
# NOTE: This assumes that a working `ghc` is on $PATH; this may not
22+
# necessarily be the same GHC used by `cabal` for building `alex`.
23+
#
24+
# Again, if HC has been set in the environment (e.g. by the CI), we keep this setting.
25+
# [2021-06-15, PR #189](https://github.com/simonmar/alex/pull/189)
26+
#
27+
HC ?= ghc
1628

1729
# Some GHC warnings are only available from a certain version on
1830
# Get the GHC version
19-
GHC_VERSION:=$(shell ghc --numeric-version)
31+
GHC_VERSION:=$(shell $(HC) --numeric-version)
2032
GHC_VERSION_WORDS=$(subst ., ,$(GHC_VERSION))
2133
GHC_MAJOR_VERSION=$(word 1,$(GHC_VERSION_WORDS))
2234
GHC_MINOR_VERSION=$(word 2,$(GHC_VERSION_WORDS))

0 commit comments

Comments
 (0)