Skip to content

Commit 336f38e

Browse files
authored
Merge pull request #439 from IntersectMBO/wenkokke/simplify-scripts
Simplify pre-commit scripts.
2 parents d0d2f7a + fecc54d commit 336f38e

File tree

9 files changed

+90
-107
lines changed

9 files changed

+90
-107
lines changed

.github/workflows/haskell.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ jobs:
169169
- name: Checkout repository
170170
uses: actions/checkout@v4
171171

172-
- name: Install system dependencies (apt-get)
173-
run: |
174-
sudo apt-get update || true
175-
sudo apt-get -y install fd-find
176-
177172
- name: Setup Haskell
178173
id: setup-haskell
179174
uses: haskell-actions/setup@v2
@@ -210,7 +205,7 @@ jobs:
210205
211206
- name: Run stylish-haskell
212207
run: |
213-
./scripts/format-stylish-fd.sh
208+
./scripts/format-stylish.sh
214209
git diff --exit-code
215210
216211
# Check formatting for cabal files
@@ -227,17 +222,12 @@ jobs:
227222
# See the comment on the hackage-index-state environment variable for the
228223
# stylish-haskell job.
229224
env:
230-
hackage-index-state: "2024-04-10T14:36:07Z"
225+
hackage-index-state: "2024-04-27T12:31:04Z"
231226

232227
steps:
233228
- name: Checkout repository
234229
uses: actions/checkout@v4
235230

236-
- name: Install system dependencies (apt-get)
237-
run: |
238-
sudo apt-get update || true
239-
sudo apt-get -y install fd-find
240-
241231
- name: Setup Haskell
242232
id: setup-haskell
243233
uses: haskell-actions/setup@v2
@@ -265,7 +255,7 @@ jobs:
265255
266256
- name: Install cabal-fmt
267257
run: |
268-
cabal install --ignore-project cabal-fmt --index-state="${{ env.hackage-index-state }}" --constraint 'cabal-fmt == 0.1.11'
258+
cabal install --ignore-project cabal-fmt --index-state="${{ env.hackage-index-state }}" --constraint 'cabal-fmt == 0.1.12'
269259
270260
- name: Record cabal-fmt version
271261
run: |
@@ -274,7 +264,7 @@ jobs:
274264
275265
- name: Run cabal-fmt
276266
run: |
277-
./scripts/format-cabal-fd.sh
267+
./scripts/format-cabal.sh
278268
git diff --exit-code
279269
280270
# Check cabal files

scripts/check-cabal.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
set -euo pipefail
3+
# Check for cabal
4+
cabal="$(which cabal)"
5+
if [ "${cabal}" = "" ]; then
6+
echo "Requires cabal; no version found"
7+
exit 1
8+
fi
49

5-
for x in $(find . -name '*.cabal' | grep -v dist-newstyle | cut -c 3-); do
6-
(
7-
d=$(dirname $x)
8-
if [ $(basename $d) != "bloomfilter" ]; then
9-
echo "== $d =="
10-
cd $d
11-
cabal check
12-
fi
13-
)
14-
done
10+
# Check Cabal files with cabal
11+
echo "Checking Cabal source files with cabal"
12+
# shellcheck disable=SC2016
13+
if ! git ls-files --exclude-standard --no-deleted --deduplicate '*.cabal' | xargs -L 1 sh -c 'echo "$0" && cd "$(dirname "$0")" && cabal check'; then
14+
exit 1
15+
fi

scripts/format-cabal-fd.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/format-cabal-find.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/format-cabal.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
export LC_ALL=C.UTF-8
4+
5+
# Check for cabal-fmt
6+
cabal_fmt_required_version="0.1.12"
7+
cabal_fmt="$(which cabal-fmt)"
8+
if [ "${cabal_fmt}" = "" ]; then
9+
echo "Requires cabal-fmt version ${cabal_fmt_required_version}; no version found"
10+
exit 1
11+
fi
12+
cabal_fmt_installed_version="$($cabal_fmt --version | head -n 1 | cut -d' ' -f2)"
13+
if [ ! "${cabal_fmt_installed_version}" = "${cabal_fmt_required_version}" ]; then
14+
echo "Requires cabal-fmt version ${cabal_fmt_required_version}; found version ${cabal_fmt_installed_version}"
15+
exit 1
16+
fi
17+
18+
# Check Cabal files with cabal-fmt
19+
echo "Formatting Cabal source files with cabal-fmt version ${cabal_fmt_required_version}"
20+
# shellcheck disable=SC2016
21+
if ! git ls-files --exclude-standard --no-deleted --deduplicate '*.cabal' | xargs -L 1 sh -c 'echo "$0" && cabal-fmt -i "$0"'; then
22+
exit 1
23+
fi

scripts/format-stylish-fd.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

scripts/format-stylish-find.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

scripts/format-stylish.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
export LC_ALL=C.UTF-8
4+
5+
# Check for stylish-haskell
6+
stylish_haskell_required_version="0.14.6.0"
7+
stylish_haskell="$(which stylish-haskell)"
8+
if [ "${stylish_haskell}" = "" ]; then
9+
echo "Requires stylish-haskell version ${stylish_haskell_required_version}; no version found"
10+
exit 1
11+
fi
12+
stylish_haskell_installed_version="$($stylish_haskell --version | head -n 1 | cut -d' ' -f2)"
13+
if [ ! "${stylish_haskell_installed_version}" = "${stylish_haskell_required_version}" ]; then
14+
echo "Requires stylish-haskell version ${stylish_haskell_required_version}; found version ${stylish_haskell_installed_version}"
15+
exit 1
16+
fi
17+
18+
# Check Haskell files with stylish-haskell
19+
echo "Formatting Haskell source files with stylish-haskell version ${stylish_haskell_required_version}"
20+
# shellcheck disable=SC2016
21+
if ! git ls-files --exclude-standard --no-deleted --deduplicate '*.hs' | xargs -L 1 sh -c 'echo "$0" && stylish-haskell -i -c .stylish-haskell.yaml "$0"'; then
22+
exit 1
23+
fi

scripts/pre-commit.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
# To install as a Git pre-commit hook, run:
4+
#
5+
# > ln scripts/pre-commit.sh .git/hooks/pre-commit.sh
6+
#
7+
8+
# Check for unstaged changes in Haskell files
9+
unstaged_haskell_files="$(git ls-files --exclude-standard --no-deleted --deduplicate --modified '*.hs')"
10+
if [ ! "${unstaged_haskell_files}" = "" ]; then
11+
echo "Found unstaged Haskell files"
12+
echo "${unstaged_haskell_files}"
13+
exit 1
14+
fi
15+
16+
# Check for unstaged changes in Cabal files
17+
unstaged_cabal_files="$(git ls-files --exclude-standard --no-deleted --deduplicate --modified '*.cabal')"
18+
if [ ! "${unstaged_cabal_files}" = "" ]; then
19+
echo "Found unstaged Cabal files"
20+
echo "${unstaged_cabal_files}"
21+
exit 1
22+
fi
23+
24+
# Run various checks and formatters
25+
./scripts/check-cabal.sh
26+
./scripts/format-cabal.sh
27+
./scripts/format-stylish.sh

0 commit comments

Comments
 (0)