-
Notifications
You must be signed in to change notification settings - Fork 81
290 lines (284 loc) · 11.2 KB
/
workflow.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
name: Continuous integration
on:
push:
branches: master
pull_request:
branches: master
workflow_dispatch: # allows manual triggering
env:
# Bump this number to invalidate the GH actions cache
cache-version: 0
jobs:
lint:
name: Format & Lint
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-lint
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
[[ ${{ runner.os }} == Linux ]] && sudo sysctl -w net.ipv4.tcp_keepalive_time=60
if [ -z "$BUILDBUDDY_API_KEY" ]; then
cache_setting='--noremote_upload_local_results'
else
cache_setting="--remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY"
fi
cat >.bazelrc.local <<EOF
common --config=ci
build $cache_setting
EOF
cat >~/.netrc <<EOF
machine api.github.com
password ${{ secrets.GITHUB_TOKEN }}
EOF
- run: |
bazelisk test buildifier:buildifier_test
test-nixpkgs:
name: Build & Test - Nixpkgs
needs:
- lint
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.module }}-${{ matrix.bzlmod }}-${{ matrix.ghc }}-nixpkgs
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-11]
module: [rules_haskell, rules_haskell_nix, rules_haskell_tests]
bzlmod: [true, false]
ghc:
- 9.2.8
- 9.4.6
exclude:
- module: rules_haskell_nix
bzlmod: false
# TODO: in a MODULE.bazel file we declare version specific dependencies, would need to use stack snapshot json
# and stack config per GHC version
- ghc: 9.4.6
bzlmod: true
runs-on: ${{ matrix.os }}
steps:
- if: ${{ matrix.os == 'ubuntu-latest' }}
run: |-
sudo swapoff -a
sudo rm -rf /swapfile /usr/share/dotnet /usr/local/lib/android /opt/ghc
docker rmi $(docker images -q) -f
- uses: actions/checkout@v4
- name: Mount Bazel cache
uses: actions/cache@v3
with:
path: ~/repo-cache
key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=./nixpkgs/default.nix
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
extra-substituters = https://cache.iog.io
- name: Configure
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
[[ ${{ runner.os }} == Linux ]] && sudo sysctl -w net.ipv4.tcp_keepalive_time=60
case ${{ runner.os }} in
macOS) BUILD_CONFIG=ci-macos-nixpkgs;;
Linux) BUILD_CONFIG=ci-linux-nixpkgs;;
esac
if [ -z "$BUILDBUDDY_API_KEY" ]; then
cache_setting='--noremote_upload_local_results'
else
cache_setting="--remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY"
fi
cat >.bazelrc.local <<EOF
common --config=ci
build --config=$BUILD_CONFIG
build $cache_setting
common --enable_bzlmod=${{ matrix.bzlmod }}
EOF
cp .bazelrc.local rules_haskell_nix
cp .bazelrc.local rules_haskell_tests
cat >~/.netrc <<EOF
machine api.github.com
password ${{ secrets.GITHUB_TOKEN }}
EOF
- name: Check Bazel version
run: |
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run .ci/check-bazel-version
- name: Build & test - rules_haskell
if: matrix.module == 'rules_haskell'
run: |
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run '
set -euo pipefail
bazel test //...
bazel build //docs:api_html
bazel build //docs:guide_html
'
- name: Build & test - rules_haskell_nix
if: matrix.module == 'rules_haskell_nix'
run: |
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run '
set -euo pipefail
cd rules_haskell_nix
bazel test //...
'
- name: Build & test - rules_haskell_tests
if: matrix.module == 'rules_haskell_tests'
run: |
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run '
set -euo pipefail
cd rules_haskell_tests
# XXX run start script `--with-bzlmod=true` when supported
if ! ${{ matrix.bzlmod }}; then
./tests/run-start-script.sh --use-nix --with-bzlmod=${{ matrix.bzlmod }}
fi
bazel build //tests:run-tests
./bazel-ci-bin/tests/run-tests
bazel coverage //...
'
test-bindist:
name: Build & Test - bindist
needs:
- lint
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.module }}-${{ matrix.bzlmod }}-${{ matrix.ghc }}-bindist
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-11, windows-latest]
module: [rules_haskell, rules_haskell_tests]
bzlmod: [true, false]
ghc:
- 9.2.8
- 9.4.6
exclude:
# TODO: in a MODULE.bazel file we declare version specific dependencies, would need to use stack snapshot json
# and stack config per GHC version
- ghc: 9.4.6
bzlmod: true
env:
# prevent auto-detection of system compilers on Windows
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN: ${{ matrix.os == 'windows-latest' && 1 || 0 }}
# do not use Xcode on macOS
BAZEL_USE_CPP_ONLY_TOOLCHAIN: ${{ matrix.os == 'macos-11' && 1 || 0 }}
GHC_VERSION: ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
steps:
- if: ${{ matrix.os == 'ubuntu-latest' }}
run: |-
sudo swapoff -a
sudo rm -rf /swapfile /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo apt-get update
sudo apt-get install --no-install-recommends -yy libtinfo5
sudo apt clean
docker rmi $(docker images -q) -f
- uses: actions/checkout@v4
- name: Mount Bazel cache
uses: actions/cache@v3
with:
path: ~/repo-cache
key: repo-cache-${{ runner.os }}-bindist-${{ env.cache-version }}
- name: Install Bazel
shell: bash
run: |
BAZEL_DIR="$(.ci/fetch-bazel-bindist)"
mv $BAZEL_DIR $HOME/bazel
echo "$HOME/bazel" >> "$GITHUB_PATH"
- name: Configure
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
shell: bash
run: |
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
[[ ${{ runner.os }} == Linux ]] && sudo sysctl -w net.ipv4.tcp_keepalive_time=60
case "${{ runner.os }},${{ matrix.module }}" in
macOS,*) BUILD_CONFIG=ci-macos-bindist;;
Linux,*) BUILD_CONFIG=ci-linux-bindist;;
Windows,rules_haskell) BUILD_CONFIG=ci-windows-bindist-rules-haskell;;
Windows,rules_haskell_tests) BUILD_CONFIG=ci-windows-bindist-rules-haskell-tests;;
esac
if [ -z "$BUILDBUDDY_API_KEY" ]; then
cache_setting='--noremote_upload_local_results'
else
cache_setting="--remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY"
fi
if [[ ${{ runner.os }} == Windows ]]; then
output_root_setting="startup --output_user_root=C:/_bzl"
# On windows, we use a separate remote cache for bzlmod,
# because the c dependency analysis is leaking absolute paths which are different
if ${{ matrix.bzlmod }}; then
bzlmod_cache_silo_key='build --remote_default_exec_properties=bzlmod-cache-silo-key=bzlmod'
else
bzlmod_cache_silo_key='build --remote_default_exec_properties=bzlmod-cache-silo-key=workspace'
fi
else
output_root_setting=""
bzlmod_cache_silo_key=""
fi
cat >.bazelrc.local <<EOF
common --config=ci
build --config=$BUILD_CONFIG
build $cache_setting
$output_root_setting
$bzlmod_cache_silo_key
common --enable_bzlmod=${{ matrix.bzlmod }}
EOF
cp .bazelrc.local rules_haskell_tests
cat >~/.netrc <<EOF
machine api.github.com
password ${{ secrets.GITHUB_TOKEN }}
EOF
- name: Build & test - rules_haskell
if: matrix.module == 'rules_haskell'
shell: bash
run: |
if [[ ${{ runner.os }} == Windows ]]; then
# On Windows `//...` expands to `/...`.
bazel test ///...
else
bazel test //...
fi
- name: Build & test - rules_haskell_tests
if: matrix.module == 'rules_haskell_tests'
shell: bash
run: |
cd rules_haskell_tests
./tests/run-start-script.sh --use-bindists --with-bzlmod=${{ matrix.bzlmod }}
if [[ ${{ runner.os }} == Windows ]]; then
# On Windows `//...` expands to `/...`.
bazel test ///...
else
bazel test //...
fi
# Test stack_snapshot pinning
# NOTE keep in sync with tests/RunTests.hs
bazel run @stackage-pinning-test-unpinned//:pin
bazel build @stackage-pinning-test//:hspec
- name: Collect Logs
id: collect_logs
if: failure()
shell: bash
run: |
mkdir -p logs
if [[ ${{ matrix.module }} == 'rules_haskell_tests' ]]; then
dir=rules_haskell_tests
else
dir=.
fi
base=$( cd "$dir" ; bazel info output_base )
find "$base" -mindepth 1 -maxdepth 1 -name "java*.log.*" -print0 | xargs -0rI % cp % logs/
- name: Upload Logs
if: ${{ failure() && steps.collect_logs.conclusion == 'success' }}
uses: actions/upload-artifact@v3
with:
name: Logs ${{ matrix.os }} ${{ matrix.module }} ${{ matrix.bzlmod }}
path: logs