Skip to content

Commit f0c62df

Browse files
authored
Update workflow to try and take advantage of caching (#521)
* Update workflow to try and take advantage of caching Our CI runs take 15-30 mins, which is too long IMO. * Fix * Fix * Fix * Try this * Don't haddock, it forces rebuilding for some reason * Not sure what's going on tbh * A bit more
1 parent 1c40fbf commit f0c62df

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

.github/workflows/haskell.yml

+42-23
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,60 @@ on:
77
pull_request:
88

99
jobs:
10+
# Broadly copied from https://github.com/haskell/actions/tree/main/setup
1011
build:
1112

1213
runs-on: ${{ matrix.os }}
13-
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
ghc: ['9.6', '9.4', '9.2', '9.0', '8.10']
17+
ghc-version: ['9.6', '9.4', '9.2', '9.0', '8.10']
1818
# Unlikely that we'll succeed on windows and fail on macos,
1919
# including it is just burning CI time. But windows could have
2020
# path or IO issues, so worth including
2121
os: [ubuntu-latest, windows-latest]
2222

2323
steps:
24-
- uses: actions/checkout@v3
25-
- uses: haskell/actions/setup@v2
26-
with:
27-
ghc-version: ${{ matrix.ghc }}
28-
29-
- name: Cabal cache
30-
uses: actions/cache@v3
31-
env:
32-
cache-name: cache-cabal
33-
with:
34-
path: ~/.cabal
35-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
36-
restore-keys: |
37-
${{ runner.os }}-build-${{ env.cache-name }}-
38-
39-
- name: Cabal update
40-
run: cabal update
41-
- name: Build using cabal
42-
run: cabal build all
43-
- name: Test
44-
run: cabal test all
24+
- uses: actions/checkout@v3
25+
26+
- name: Set up Haskell toolchain
27+
uses: haskell/actions/setup@v2
28+
id: setup
29+
with:
30+
ghc-version: ${{ matrix.ghc-version }}
31+
32+
- name: Configure the build
33+
run: |
34+
cabal build all --dry-run
35+
# The last step generates dist-newstyle/cache/plan.json for the cache key.
36+
37+
- name: Restore cached dependencies
38+
uses: actions/cache/restore@v3
39+
id: cache
40+
env:
41+
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
42+
with:
43+
path: ${{ steps.setup.outputs.cabal-store }}
44+
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
45+
restore-keys: ${{ env.key }}-
46+
47+
- name: Install dependencies
48+
run: cabal build all --only-dependencies
49+
50+
# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
51+
- name: Save cached dependencies
52+
uses: actions/cache/save@v3
53+
# Caches are immutable, trying to save with the same key would error.
54+
if: ${{ steps.cache.outputs.cache-primary-key != steps.cache.outputs.cache-matched-key }}
55+
with:
56+
path: ${{ steps.setup.outputs.cabal-store }}
57+
key: ${{ steps.cache.outputs.cache-primary-key }}
58+
59+
- name: Build
60+
run: cabal build all
61+
62+
- name: Run tests
63+
run: cabal test all
4564

4665
haskell_post_job:
4766
runs-on: ubuntu-latest

cabal.project

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
index-state: 2023-07-09T00:00:00Z
2+
13
packages:
24
./lsp
35
./lsp-types/
46
./lsp-test/
57

8+
tests: True
9+
test-show-details: direct
10+
11+
benchmarks: True
12+
613
package lsp
714
flags: +demo
815

9-
index-state: 2023-07-09T00:00:00Z
16+
package lsp-types
17+
-- This makes a big difference here as lsp-types
18+
-- has very many independent modules
19+
ghc-options: -j4
1020

11-
tests: True
12-
benchmarks: True
13-
test-show-details: direct
14-
haddock-quickjump: True

0 commit comments

Comments
 (0)