Skip to content

Commit 457b7eb

Browse files
authored
Merge pull request #811 from IntersectMBO/skip-hls-on-trivial-changes
Skip HLS on trivial changes
2 parents efa2f44 + e94281f commit 457b7eb

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/hls.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,80 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323

24+
- name: Check if changes were trivial
25+
id: check_trivial_changes
26+
run: |
27+
git fetch origin ${{ github.base_ref }} --unshallow
28+
base_ref=origin/${{ github.base_ref }}
29+
head_ref=HEAD
30+
changed_files=$(git diff-tree --name-status -r "$base_ref".."$head_ref" -- | cut -f2 -d$'\t')
31+
# Flag to check whether we do the rest of checks
32+
exception=true
33+
34+
for file in $changed_files; do
35+
# If changes were to a markdown file we don't mind
36+
if [[ $file == *.md ]]; then
37+
echo "$file: is markdown, so it doesn't matter (trivial change)"
38+
continue
39+
fi
40+
41+
# If changes were to a .cabal file, we ensure only the version changed
42+
if [[ $file == *.cabal ]]; then
43+
# If file doesn't exist it means it was moved or removed
44+
if [ ! -f "$file" ]; then
45+
echo "$file: was moved or removed and is a cabal file (non-trivial change)"
46+
exception=false
47+
break
48+
fi
49+
50+
# We ensure the only change was to the version field
51+
diff_version=$(git diff "$base_ref".."$head_ref" -- "$file" | perl -ne 'print if /^-(?!version:)/' | wc -l)
52+
diff_no_version=$(git diff "$base_ref".."$head_ref" -- "$file" | perl -ne 'print if /^\+(?!version:)/' | wc -l)
53+
54+
if [ "$diff_version" -gt 1 ] || [ "$diff_no_version" -gt 1 ]; then
55+
echo "$file: was modified beyond the version tag (non-trivial change)"
56+
exception=false
57+
break
58+
fi
59+
echo "In $file, at most the version field was modified"
60+
else
61+
# If other types of files were changed, do not skip the checks
62+
echo "$file: was changed and is not a markdown nor a cabal file (non-trivial change)"
63+
exception=false
64+
break
65+
fi
66+
done
67+
68+
if $exception; then
69+
echo "CHECK_HLS_WORKS=0" >> "$GITHUB_OUTPUT"
70+
echo "All changes are trival, skipping rest of checks..."
71+
else
72+
echo "CHECK_HLS_WORKS=1" >> "$GITHUB_OUTPUT"
73+
echo "Some changes are non-trivial. We need to do the checks!"
74+
fi
2475
- uses: cachix/install-nix-action@v30
76+
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
2577
with:
2678
nix_path: nixpkgs=channel:nixos-unstable
2779
extra_nix_config: |
2880
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
2981
substituters = https://cache.iog.io/ https://cache.nixos.org/
3082
3183
- uses: rrbutani/use-nix-shell-action@v1
84+
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
3285

3386
- name: Update dependencies
87+
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
3488
run: cabal update; cabal freeze
3589

3690
- name: Obtain GHC version
91+
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
3792
run: |
3893
echo "VERSION=$(ghc --numeric-version)" >> "$GITHUB_OUTPUT"
3994
id: ghc
4095

4196
- name: HLS caching
97+
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
4298
uses: actions/cache@v4
4399
with:
44100
path: |
@@ -52,4 +108,5 @@ jobs:
52108
hls-cache-${{ env.HLS_CACHE_VERSION }}-${{ runner.os }}-${{ steps.ghc.outputs.VERSION }}-${{ hashFiles('**/cabal.project.freeze') }}-
53109
54110
- name: Test HLS works
111+
if: steps.check_trivial_changes.outputs.CHECK_HLS_WORKS > 0
55112
run: haskell-language-server

0 commit comments

Comments
 (0)