Skip to content

Commit e622744

Browse files
jneiramichaelpj
andauthored
Reuse build setup using a dedicated github action (#2563)
* Extract out ci build setup * Correct action path * Add required shell property * Remove unused cabal version * Update .github/actions/setup-build/action.yml Co-authored-by: Michael Peyton Jones <[email protected]> * Update .github/actions/setup-build/action.yml Co-authored-by: Michael Peyton Jones <[email protected]> * Update .github/actions/setup-build/action.yml Co-authored-by: Michael Peyton Jones <[email protected]> * Update .github/actions/setup-build/action.yml Co-Authored-By: @michaelpj * Copy alt project file unconditionally * Make freeze strict Co-authored-by: Michael Peyton Jones <[email protected]>
1 parent a8aa016 commit e622744

File tree

6 files changed

+137
-372
lines changed

6 files changed

+137
-372
lines changed
+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: "Cached build"
2+
description: "Setup the build using cache"
3+
inputs:
4+
ghc:
5+
description: "Ghc version"
6+
required: true
7+
cabal:
8+
description: "Cabal version"
9+
required: false
10+
default: "3.6"
11+
os:
12+
description: "Operating system: Linux, Windows or macOS"
13+
required: true
14+
runs:
15+
using: "composite"
16+
steps:
17+
- uses: haskell/actions/setup@v1
18+
id: HaskEnvSetup
19+
with:
20+
ghc-version : ${{ inputs.ghc }}
21+
cabal-version: ${{ inputs.cabal }}
22+
enable-stack: false
23+
24+
- if: inputs.os == 'Windows'
25+
name: (Windows) Platform config
26+
run: |
27+
echo "CABAL_PKGS_DIR=C:\\cabal\\packages" >> $GITHUB_ENV
28+
shell: bash
29+
- if: ( inputs.os == 'Linux' ) || ( inputs.os == 'macOS' )
30+
name: (Linux,macOS) Platform config
31+
run: |
32+
echo "CABAL_PKGS_DIR=~/.cabal/packages" >> $GITHUB_ENV
33+
shell: bash
34+
35+
# This copy an alternative cabal-ghc${GHCVER}.project (for example cabal-ghc921.project)
36+
# as main cabal-project, for not fully supported ghc versions
37+
# Needs to be before the caching step so that the cache can detect changes to the modified cabal.project file
38+
- name: Use possible modified `cabal.project`
39+
env:
40+
GHCVER: ${{ inputs.ghc }}
41+
run: |
42+
# File has some protections preventing regular `rm`.
43+
# (most probably sticky bit is set on $HOME)
44+
# `&&` insures `rm -f` return is positive.
45+
# Many platforms aslo have `alias cp='cp -i'`.
46+
ALT_PROJECT_FILE=cabal-ghc${GHCVER//./}.project
47+
if [[ -f "$ALT_PROJECT_FILE" ]]; then
48+
rm -f -v cabal.project && cp -v "$ALT_PROJECT_FILE" cabal.project
49+
fi
50+
shell: bash
51+
52+
- if: inputs.os == 'Windows' && inputs.ghc == '8.8.4'
53+
name: (Windows,GHC 8.8) Modify `cabal.project` to workaround segfaults
54+
run: |
55+
echo "package floskell" >> cabal.project
56+
echo " ghc-options: -O0" >> cabal.project
57+
shell: bash
58+
59+
# Shorten binary names as a workaround for filepath length limits in Windows,
60+
# but since tests are hardcoded on this workaround -
61+
# all platforms (in 2021-12-07) need it.
62+
# All workflows which distinquishes cache on `cabal.project` needs this.
63+
- name: Workaround shorten binary names
64+
run: |
65+
sed -i.bak -e 's/haskell-language-server/hls/g' \
66+
-e 's/haskell_language_server/hls/g' \
67+
haskell-language-server.cabal cabal.project
68+
sed -i.bak -e 's/Paths_haskell_language_server/Paths_hls/g' \
69+
src/**/*.hs exe/*.hs
70+
shell: bash
71+
72+
- name: Retrieving `cabal.project` Hackage timestamp
73+
run: |
74+
# Form: index-state: 2021-11-29T08:11:08Z
75+
INDEX_STATE_ENTRY=$(grep index-state cabal.project)
76+
# Form: 2021-11-29T08-11-08Z
77+
INDEX_STATE1=$(echo "$INDEX_STATE_ENTRY" | cut -d' ' -f2 | tr ':' '-')
78+
echo "INDEX_STATE=$INDEX_STATE1" >> $GITHUB_ENV
79+
shell: bash
80+
81+
# We have to restore package sources before `cabal update`
82+
# because it overwrites the hackage index with the cached one
83+
- name: Hackage sources cache
84+
uses: actions/cache@v2
85+
env:
86+
cache-name: hackage-sources
87+
with:
88+
path: ${{ env.CABAL_PKGS_DIR }}
89+
key: ${{ env.cache-name }}-${{ env.INDEX_STATE }}
90+
restore-keys: ${{ env.cache-name }}-
91+
92+
# To ensure we get the latest hackage index without relying on the haskell action logic
93+
# It has to be done before `cabal freeze` to make it aware of the new index
94+
- run: cabal update
95+
shell: bash
96+
97+
- name: Form the package list ('cabal.project.freeze')
98+
run: |
99+
cabal v2-freeze && \
100+
echo "" && \
101+
echo 'Output:' && \
102+
echo "" && \
103+
cat 'cabal.project.freeze'
104+
shell: bash
105+
106+
- name: Compiled deps cache
107+
id: compiled-deps
108+
uses: actions/cache@v2
109+
env:
110+
cache-name: compiled-deps
111+
with:
112+
path: ${{ steps.HaskEnvSetup.outputs.cabal-store }}
113+
key: ${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-${{ env.INDEX_STATE }}-${{ hashFiles('cabal.project.freeze') }}
114+
restore-keys: |
115+
${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-${{ env.INDEX_STATE }}-
116+
${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-
117+
${{ env.cache-name }}-${{ inputs.os }}-
118+
119+
# We remove the freeze file because it could interfere with the build
120+
- name: "Remove freeze file"
121+
run: rm -f cabal.project.freeze
122+
shell: bash

.github/workflows/bench.yml

+3-65
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747
matrix:
4848
ghc: ['8.10.7']
4949
os: [ubuntu-latest]
50-
cabal: ['3.6']
5150

5251
# This code is fitted to the strategy: assumes Linux is used ... etc,
5352
# change of the strategy may require changing the bootstrapping/run code
@@ -57,71 +56,10 @@ jobs:
5756

5857
- run: git fetch origin master # check the master branch for benchmarking
5958

60-
- uses: haskell/actions/setup@v1
61-
id: HaskEnvSetup
62-
with:
63-
ghc-version : ${{ matrix.ghc }}
64-
cabal-version: ${{ matrix.cabal }}
65-
enable-stack: false
66-
67-
- name: Linux Platform config
68-
run: |
69-
echo "CABAL_PKGS_DIR=~/.cabal/packages" >> $GITHUB_ENV
70-
71-
# All workflows which distinquishes cache on `cabal.project` needs this.
72-
- name: Workaround shorten binary names
73-
run: |
74-
sed -i.bak -e 's/haskell-language-server/hls/g' \
75-
-e 's/haskell_language_server/hls/g' \
76-
haskell-language-server.cabal cabal.project
77-
sed -i.bak -e 's/Paths_haskell_language_server/Paths_hls/g' \
78-
src/**/*.hs exe/*.hs
79-
80-
- name: Retrieving `cabal.project` Hackage timestamp
81-
run: |
82-
# Form: index-state: 2021-11-29T08:11:08Z
83-
INDEX_STATE_ENTRY=$(grep index-state cabal.project)
84-
# Form: 2021-11-29T08-11-08Z
85-
INDEX_STATE1=$(echo "$INDEX_STATE_ENTRY" | cut -d' ' -f2 | tr ':' '-')
86-
echo "INDEX_STATE=$INDEX_STATE1" >> $GITHUB_ENV
87-
88-
# We have to restore package sources before `cabal update`
89-
# cause it overwrites the hackage index with the cached one
90-
- name: Hackage sources cache
91-
uses: actions/cache@v2
92-
env:
93-
cache-name: hackage-sources
94-
with:
95-
path: ${{ env.CABAL_PKGS_DIR }}
96-
key: ${{ env.cache-name }}-${{ env.INDEX_STATE }}
97-
restore-keys: ${{ env.cache-name }}-
98-
99-
# To ensure we get the lastest hackage index and not relying on haskell action logic
100-
# It has to be done before `cabal freeze` to make it aware of the new index
101-
- run: cabal update
102-
103-
- name: Form the package list ('cabal.project.freeze')
104-
run: |
105-
cabal v2-freeze && \
106-
echo "" && \
107-
echo 'Output:' && \
108-
echo "" && \
109-
cat 'cabal.project.freeze' && \
110-
echo '' || \
111-
echo 'WARNING: Could not produce the `freeze`.'
112-
113-
- name: Compiled deps cache
114-
id: compiled-deps
115-
uses: actions/cache@v2
116-
env:
117-
cache-name: compiled-deps
59+
- uses: ./.github/actions/setup-build
11860
with:
119-
path: ${{ steps.HaskEnvSetup.outputs.cabal-store }}
120-
key: ${{ env.cache-name }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.INDEX_STATE }}-${{ hashFiles('cabal.project.freeze') }}
121-
restore-keys: |
122-
${{ env.cache-name }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.INDEX_STATE }}-
123-
${{ env.cache-name }}-${{ runner.os }}-${{ matrix.ghc }}-
124-
${{ env.cache-name }}-${{ runner.os }}-
61+
ghc: ${{ matrix.ghc }}
62+
os: ${{ runner.os }}
12563

12664
# max-backjumps is increased as a temporary solution
12765
# for dependency resolution failure

.github/workflows/caching.yml

+3-93
Original file line numberDiff line numberDiff line change
@@ -86,104 +86,14 @@ jobs:
8686
, "macOS-latest"
8787
, "windows-latest"
8888
]
89-
cabal: ['3.6']
9089

9190
steps:
9291
- uses: actions/checkout@v2
9392

94-
- uses: haskell/actions/setup@v1
95-
id: HaskEnvSetup
93+
- uses: ./.github/actions/setup-build
9694
with:
97-
ghc-version : ${{ matrix.ghc }}
98-
cabal-version: ${{ matrix.cabal }}
99-
enable-stack: false
100-
101-
- if: runner.os == 'Windows'
102-
name: (Windows) Platform config
103-
run: |
104-
echo "CABAL_PKGS_DIR=C:\\cabal\\packages" >> $GITHUB_ENV
105-
- if: ( runner.os == 'Linux' ) || ( runner.os == 'macOS' )
106-
name: (Linux,macOS) Platform config
107-
run: |
108-
echo "CABAL_PKGS_DIR=~/.cabal/packages" >> $GITHUB_ENV
109-
110-
# Needs to be before Cache Cabal so the cache can detect changes to the modified cabal.project file
111-
- if: matrix.ghc == '9.0.1'
112-
name: (GHC 9.0.1) Use modified `cabal.project`
113-
run: |
114-
# File has some protections preventing regular `rm`.
115-
# (most probably sticky bit is set on $HOME)
116-
# `&&` insures `rm -f` return is positive.
117-
# Many platforms also have `alias cp='cp -i'`.
118-
rm -f -v cabal.project && cp -v cabal-ghc901.project cabal.project
119-
- if: runner.os == 'Windows' && matrix.ghc == '8.8.4'
120-
name: (Windows,GHC 8.8) Modify `cabal.project` to workaround segfaults
121-
run: |
122-
echo "package floskell" >> cabal.project
123-
echo " ghc-options: -O0" >> cabal.project
124-
125-
# Shorten binary names as a workaround for filepath length limits in Windows,
126-
# but since tests are hardcoded on this workaround -
127-
# all platforms (in 2021-12-07) need it.
128-
# All workflows which distinquishes cache on `cabal.project` needs this.
129-
- name: Workaround shorten binary names
130-
run: |
131-
sed -i.bak -e 's/haskell-language-server/hls/g' \
132-
-e 's/haskell_language_server/hls/g' \
133-
haskell-language-server.cabal cabal.project
134-
sed -i.bak -e 's/Paths_haskell_language_server/Paths_hls/g' \
135-
src/**/*.hs exe/*.hs
136-
137-
- name: Retrieving `cabal.project` Hackage timestamp
138-
run: |
139-
# Form: index-state: 2021-11-29T08:11:08Z
140-
INDEX_STATE_ENTRY=$(grep index-state cabal.project)
141-
# Form: 2021-11-29T08-11-08Z
142-
INDEX_STATE1=$(echo "$INDEX_STATE_ENTRY" | cut -d' ' -f2 | tr ':' '-')
143-
echo "INDEX_STATE=$INDEX_STATE1" >> $GITHUB_ENV
144-
145-
# 2021-12-02: NOTE: Cabal Hackage source tree storage does not depend on OS or GHC really,
146-
# but can depend on `base`.
147-
# But this caching is happens only inside `master` for `master` purposes of compiling the deps
148-
# so having a shared pool here that depends only on Hackage pin & does not depend on `base` is "good enough"
149-
# & used such because it preserves 10% of a global cache storage pool.
150-
# We have to restore package sources before `cabal update`
151-
# cause it overwrites the hackage index with the cached one
152-
- name: Hackage sources cache
153-
uses: actions/cache@v2
154-
env:
155-
cache-name: hackage-sources
156-
with:
157-
path: ${{ env.CABAL_PKGS_DIR }}
158-
key: ${{ env.cache-name }}-${{ env.INDEX_STATE }}
159-
restore-keys: ${{ env.cache-name }}-
160-
161-
# To ensure we get the lastest hackage index and not relying on haskell action logic
162-
# It has to be done before `cabal freeze` to make it aware of the new index
163-
- run: cabal update
164-
165-
- name: Form the package list ('cabal.project.freeze')
166-
run: |
167-
cabal v2-freeze && \
168-
echo "" && \
169-
echo 'Output:' && \
170-
echo "" && \
171-
cat 'cabal.project.freeze' && \
172-
echo '' || \
173-
echo 'WARNING: Could not produce the `freeze`.'
174-
175-
- name: Compiled deps cache
176-
id: compiled-deps
177-
uses: actions/cache@v2
178-
env:
179-
cache-name: compiled-deps
180-
with:
181-
path: ${{ steps.HaskEnvSetup.outputs.cabal-store }}
182-
key: ${{ env.cache-name }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.INDEX_STATE }}-${{ hashFiles('cabal.project.freeze') }}
183-
restore-keys: |
184-
${{ env.cache-name }}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.INDEX_STATE }}-
185-
${{ env.cache-name }}-${{ runner.os }}-${{ matrix.ghc }}-
186-
${{ env.cache-name }}-${{ runner.os }}-
95+
ghc: ${{ matrix.ghc }}
96+
os: ${{ runner.os }}
18797

18898
- if: steps.compiled-deps.outputs.cache-hit != 'true' && runner.os == 'Linux' && matrix.ghc == '8.10.7'
18999
name: Download sources for bench

0 commit comments

Comments
 (0)