-
Notifications
You must be signed in to change notification settings - Fork 24
116 lines (101 loc) · 4.5 KB
/
Copy pathhls.yml
File metadata and controls
116 lines (101 loc) · 4.5 KB
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
name: "Haskell Language Server works"
on:
merge_group:
pull_request:
push:
branches:
- master
permissions:
contents: read
jobs:
test-hls-works:
env:
# Modify this value to "invalidate" the cache.
HLS_CACHE_VERSION: "2024-06-25"
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v6
- name: Check if changes were trivial
id: check_trivial_changes
run: |
if [ -z "${{ github.base_ref }}" ]; then
exception=false
else
git fetch origin ${{ github.base_ref }} --unshallow
base_ref=origin/${{ github.base_ref }}
head_ref=HEAD
changed_files=$(git diff-tree --name-status -r "$base_ref".."$head_ref" -- | cut -f2 -d$'\t')
# Flag to check whether we do the rest of checks
exception=true
for file in $changed_files; do
# If changes were to a markdown file we don't mind
if [[ $file == *.md ]]; then
echo "$file: is markdown, so it doesn't matter (trivial change)"
continue
fi
# If changes were to a .cabal file, we ensure only the version changed
if [[ $file == *.cabal ]]; then
# If file doesn't exist it means it was moved or removed
if [ ! -f "$file" ]; then
echo "$file: was moved or removed and is a cabal file (non-trivial change)"
exception=false
break
fi
# We ensure the only change was to the version field
diff_version=$(git diff "$base_ref".."$head_ref" -- "$file" | perl -ne 'print if /^-(?!version:)/' | wc -l)
diff_no_version=$(git diff "$base_ref".."$head_ref" -- "$file" | perl -ne 'print if /^\+(?!version:)/' | wc -l)
if [ "$diff_version" -gt 1 ] || [ "$diff_no_version" -gt 1 ]; then
echo "$file: was modified beyond the version tag (non-trivial change)"
exception=false
break
fi
echo "In $file, at most the version field was modified"
else
# If other types of files were changed, do not skip the checks
echo "$file: was changed and is not a markdown nor a cabal file (non-trivial change)"
exception=false
break
fi
done
fi
if $exception; then
echo "CHECK_HLS_WORKS=0" >> "$GITHUB_OUTPUT"
echo "All changes are trival, skipping rest of checks..."
else
echo "CHECK_HLS_WORKS=1" >> "$GITHUB_OUTPUT"
echo "Some changes are non-trivial. We need to do the checks!"
fi
- uses: cachix/install-nix-action@v31
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
substituters = https://cache.iog.io/ https://cache.nixos.org/
- uses: rrbutani/use-nix-shell-action@v1
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
- name: Update dependencies
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
run: cabal update; cabal freeze
- name: Obtain GHC version
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
run: |
echo "VERSION=$(ghc --numeric-version)" >> "$GITHUB_OUTPUT"
id: ghc
- name: HLS caching
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
uses: actions/cache@v4
with:
path: |
/home/runner/.cache/hie-bios
/home/runner/.cache/ghcide
/home/runner/.local/state/cabal
.ghc.environment.x86_64-linux-*
dist-newstyle
key: hls-cache-${{ env.HLS_CACHE_VERSION }}-${{ runner.os }}-${{ steps.ghc.outputs.VERSION }}-${{ hashFiles('**/cabal.project.freeze') }}-${{ hashFiles('**/*.cabal', '**/cabal.project') }}
restore-keys: |
hls-cache-${{ env.HLS_CACHE_VERSION }}-${{ runner.os }}-${{ steps.ghc.outputs.VERSION }}-${{ hashFiles('**/cabal.project.freeze') }}-
- name: Test HLS works
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
run: haskell-language-server