/
action.yml
147 lines (134 loc) · 5.63 KB
/
action.yml
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
name: "Cached build"
description: "Setup the build using cache"
inputs:
ghc:
description: "Ghc version"
required: true
cabal:
description: "Cabal version"
required: false
default: "3.6"
os:
description: "Operating system: Linux, Windows or macOS"
required: true
cache-prefix:
description: "To allow make unique the cache key"
required: false
default: ""
shorten-hls:
description: "Whether we have to shorten haskell language server to hls"
required: false
default: "true"
runs:
using: "composite"
steps:
- uses: haskell/actions/setup@v1
id: HaskEnvSetup
with:
ghc-version : ${{ inputs.ghc }}
cabal-version: ${{ inputs.cabal }}
enable-stack: false
- if: inputs.os == 'Windows'
name: (Windows) Platform config
run: |
echo "CABAL_PKGS_DIR=C:\\cabal\\packages" >> $GITHUB_ENV
shell: bash
- if: ( inputs.os == 'Linux' ) || ( inputs.os == 'macOS' )
name: (Linux,macOS) Platform config
run: |
echo "CABAL_PKGS_DIR=~/.cabal/packages" >> $GITHUB_ENV
shell: bash
# This copy an alternative cabal-ghc${GHCVER}.project (for example cabal-ghc921.project)
# as main cabal-project, for not fully supported ghc versions
# Needs to be before the caching step so that the cache can detect changes to the modified cabal.project file
- name: Use possible modified `cabal.project`
env:
GHCVER: ${{ inputs.ghc }}
run: |
# File has some protections preventing regular `rm`.
# (most probably sticky bit is set on $HOME)
# `&&` insures `rm -f` return is positive.
# Many platforms also have `alias cp='cp -i'`.
GHCVER2=${GHCVER//./}
ALT_PROJECT_FILE_MINOR=cabal-ghc${GHCVER2}.project
ALT_PROJECT_FILE_MAJOR=cabal-ghc${GHCVER2:0:2}.project
if [[ -f "$ALT_PROJECT_FILE_MINOR" ]]; then
rm -f -v cabal.project && cp -v "$ALT_PROJECT_FILE_MINOR" cabal.project
elif [[ -f "$ALT_PROJECT_FILE_MAJOR" ]]; then
rm -f -v cabal.project && cp -v "$ALT_PROJECT_FILE_MAJOR" cabal.project
fi
shell: bash
# The default build for haskell-language-server executable is dynamic for linux and macOS
# to get a executable which works for Template Haskell
# However we continue providing full static executables in releases so we have to disable it
# *for all workflows*, including test, flags and release builds
# It has to be in cabal.project to include `-dynamic` in the cabal.project.freeze
# used to compute the cache key
- name: Disable -dynamic
run: |
echo -e "package haskell-language-server\n flags: -dynamic" >> cabal.project
shell: bash
- if: inputs.os == 'Windows' && inputs.ghc == '8.8.4'
name: (Windows,GHC 8.8) Modify `cabal.project` to workaround segfaults
run: |
echo -e 'package floskell\n ghc-options: -O0' >> cabal.project.local
shell: bash
# Shorten binary names as a workaround for filepath length limits in Windows,
# but since tests are hardcoded on this workaround all platforms need it.
# All workflows which distinguishes cache on `cabal.project` needs this.
# Except hackage one, which needs the original name
- if: inputs.shorten-hls == 'true'
name: Workaround shorten binary names
run: |
sed -i.bak -e 's/haskell-language-server/hls/g' \
-e 's/haskell_language_server/hls/g' \
haskell-language-server.cabal cabal.project
sed -i.bak -e 's/Paths_haskell_language_server/Paths_hls/g' \
src/**/*.hs exe/*.hs
shell: bash
- name: Retrieving `cabal.project` Hackage timestamp
run: |
# Form: index-state: 2021-11-29T08:11:08Z
INDEX_STATE_ENTRY=$(grep index-state cabal.project)
# Form: 2021-11-29T08-11-08Z
INDEX_STATE1=$(echo "$INDEX_STATE_ENTRY" | cut -d' ' -f2 | tr ':' '-')
echo "INDEX_STATE=$INDEX_STATE1" >> $GITHUB_ENV
shell: bash
# We have to restore package sources before `cabal update`
# because it overwrites the hackage index with the cached one
- name: Hackage sources cache
uses: actions/cache@v2
env:
cache-name: hackage-sources
with:
path: ${{ env.CABAL_PKGS_DIR }}
key: ${{ env.cache-name }}-${{ env.INDEX_STATE }}
restore-keys: ${{ env.cache-name }}-
# To ensure we get the latest hackage index without relying on the haskell action logic
# It has to be done before `cabal freeze` to make it aware of the new index
- run: cabal update
shell: bash
- name: Form the package list ('cabal.project.freeze')
run: |
cabal v2-freeze && \
echo "" && \
echo 'Output:' && \
echo "" && \
cat 'cabal.project.freeze'
shell: bash
- name: Compiled deps cache
id: compiled-deps
uses: actions/cache@v2
env:
cache-name: compiled-deps
with:
path: ${{ steps.HaskEnvSetup.outputs.cabal-store }}
key: ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-${{ env.INDEX_STATE }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: |
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-${{ env.INDEX_STATE }}-
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-
${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-
# We remove the freeze file because it could interfere with the build
- name: "Remove freeze file"
run: rm -f cabal.project.freeze
shell: bash