Skip to content

Commit d76aecb

Browse files
authored
Merge pull request #4951 from IntersectMBO/nm/shellcheck
Add a shellcheck workflow to GitHub CI
2 parents d65e5ab + 421da83 commit d76aecb

File tree

8 files changed

+70
-34
lines changed

8 files changed

+70
-34
lines changed

.github/workflows/shellcheck.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Shellcheck
2+
3+
# This pipeline runs shellcheck on all shell scripts in the repo.
4+
#
5+
# It uses Nix, so that the shellcheck version used is the same as the one used
6+
# by developers in Nix shells. This ensures the CI's behavior is consistent
7+
# with the one of developers.
8+
9+
on:
10+
push:
11+
branches: [ "master", "release/**" ]
12+
pull_request:
13+
# For running the workflow manually - useful for branches without PRs, for which CI isn't run automatically
14+
workflow_dispatch:
15+
16+
jobs:
17+
shellcheck:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out source
21+
uses: actions/checkout@v4
22+
23+
- name: Install Nix
24+
uses: cachix/install-nix-action@v31
25+
with:
26+
nix_path: nixpkgs=channel:nixos-unstable
27+
28+
- name: Use nix
29+
uses: rrbutani/use-nix-shell-action@v1
30+
with:
31+
extraNixOptions: --accept-flake-config
32+
33+
- name: Shellcheck
34+
run: |
35+
git ls-files scripts | xargs -rd\\n file | egrep 'Bourne|bash' | cut -d: -f1 | xargs -rd\\n shellcheck

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
[
128128
(python3.withPackages (ps: with ps; [sphinx sphinx_rtd_theme recommonmark sphinx-markdown-tables sphinxemoji]))
129129
haskellPackages.implicit-hie
130+
shellcheck
130131
];
131132
# disable Hoogle until someone request it
132133
withHoogle = false;

scripts/cabal-test-with-retries.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for TRY in $(seq "$TRIES"); do
1010
echo ">>>>> Testing $PACKAGE ... attempt $TRY of $TRIES <<<<<"
1111
if cabal test "$PACKAGE"; then
1212
exit 0
13-
elif ! find dist-newstyle -path '*/t/*' -name "$PACKAGE*.log" | xargs grep -h "$CONDITION"; then
13+
elif ! find dist-newstyle -path '*/t/*' -name "$PACKAGE*.log" -print0 | xargs -0 grep -h "$CONDITION"; then
1414
echo "The test failure isn't retryable - aborting"
1515
exit 1
1616
fi

scripts/fourmolize.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ set -euo pipefail
55
if [[ $# -gt 0 ]]; then
66
case "$1" in
77
--changes)
8-
files=$(git diff --diff-filter=MA --name-only origin/master HEAD -- '*.hs')
9-
if [[ -n "$files" ]]; then
10-
# Run fourmolu on changes compared to `master`.
11-
fourmolu -m inplace $(echo "$files" | grep -v Setup.hs)
12-
fi
8+
# Run fourmolu on changes compared to `master`.
9+
git diff --diff-filter=MA --name-only origin/master HEAD -- '*.hs'
1310
;;
1411
*)
1512
echo "Invalid option: $1" >&2
1613
exit 1
1714
;;
1815
esac
1916
else
20-
fourmolu -m inplace $(git ls-files -- '*.hs' | grep -v Setup.hs)
21-
fi
17+
git ls-files -- '*.hs'
18+
fi \
19+
| { grep -v Setup.hs || true; } \
20+
| xargs -r fourmolu -m inplace
2221

2322
git diff --exit-code

scripts/gen-cddl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ set -euo pipefail
44

55
eras=("shelley" "allegra" "mary" "alonzo" "babbage" "conway")
66

7-
for era in ${eras[@]}; do
7+
for era in "${eras[@]}"; do
88

99
echo "Generating cddl for $era..."
10-
cabal run cardano-ledger-$era:exe:huddle-cddl
10+
cabal run "cardano-ledger-$era:exe:huddle-cddl"
1111
echo "Regenerated ${era}.cddl"
1212

1313
done

scripts/ghcid

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

3-
set -euC
3+
set -euCo pipefail
44

55
SNAME=cardano-ledger-ghcid
66

@@ -13,35 +13,36 @@ PACKAGES=(
1313
)
1414

1515
ghcid_for_package () {
16-
local wd="$(pwd)/$1"
17-
PACKAGE_NAME=$(get_package_name $wd | xargs basename | sed -e "s/.cabal//")
18-
echo $PACKAGE_NAME
19-
tmux new-window -d -t "=$SNAME" -n $PACKAGE_NAME -c "$wd"
16+
local WD=$PWD/$1
17+
PACKAGE_NAME=$(get_package_name "$WD" | xargs basename | sed -e "s/.cabal//")
18+
echo "$PACKAGE_NAME"
19+
tmux new-window -d -t "=$SNAME" -n "$PACKAGE_NAME" -c "$WD"
2020
tmux send-keys -t "=$SNAME:=$PACKAGE_NAME" 'ghcid' Enter
2121
}
2222

2323
# Get the package name for a given directory
2424
get_package_name () {
25-
CABAL_FILE=$(find $1 -maxdepth 1 -name "*.cabal")
26-
echo $CABAL_FILE
25+
find "$1" -maxdepth 1 -name "*.cabal"
2726
}
2827

29-
att() {
28+
attach() {
3029
[ -n "${TMUX:-}" ] &&
31-
tmux switch-client -t "=$SNAME" ||
32-
tmux attach-session -t "=$SNAME"
30+
{
31+
tmux switch-client -t "=$SNAME" ||
32+
tmux attach-session -t "=$SNAME"
33+
}
3334
}
3435

3536
if tmux has-session -t "=$SNAME" 2> /dev/null; then
36-
att
37+
attach
3738
exit 0
3839
fi
3940

4041
tmux new-session -d -s $SNAME
4142
tmux rename-window -t "=$SNAME:0" "cls"
4243

43-
for t in ${PACKAGES[@]}; do
44-
ghcid_for_package $t
44+
for P in "${PACKAGES[@]}"; do
45+
ghcid_for_package "$P"
4546
done
4647

47-
att
48+
attach

scripts/haskell-language-server

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#! /usr/bin/env -S nix develop --accept-flake-config -c bash
2+
# shellcheck shell=bash
23

3-
haskell-language-server "$@"
4+
exec haskell-language-server "$@"

scripts/mkprolog.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
set -euo pipefail
44

5-
HADDOCKS_DIR=${1:-"./haddocks"}
6-
PROLOG_FILE=${2:-"./scripts/prolog"}
5+
HADDOCKS_DIR=${1:-haddocks}
6+
PROLOG_FILE=${2:-scripts/prolog}
77

8-
> ${PROLOG_FILE}
8+
exec >"$PROLOG_FILE" # Write all stdout to $PROLOG_FILE from here on
99

10-
cat > ${PROLOG_FILE} << EOF
10+
cd "$HADDOCKS_DIR"
11+
12+
cat << EOF
1113
= Cardano Ledger Repository Hackage Documentation
1214
1315
[skip to module list](#module-list)
@@ -16,9 +18,6 @@ This site contains Haskell documentation of:
1618
1719
EOF
1820

19-
for dir in $(ls ${HADDOCKS_DIR}); do
20-
if [[ -d ${HADDOCKS_DIR}/${dir} ]]; then
21-
link=$(echo "${dir}" | sed "s/:/%3A/g")
22-
echo "* __[${dir}](${link}/index.html)__" >> ${PROLOG_FILE}
23-
fi
21+
find -- * -maxdepth 0 -type d | while read -r dir; do
22+
echo "* __[$dir](${dir//:/%3A}/index.html)__"
2423
done

0 commit comments

Comments
 (0)