-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest-lint.sh
More file actions
executable file
·74 lines (58 loc) · 1.76 KB
/
test-lint.sh
File metadata and controls
executable file
·74 lines (58 loc) · 1.76 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
#!/usr/bin/env bash
# shellcheck disable=SC1091
set -e
set -u
ROOT_DIR=$(git rev-parse --show-toplevel)
. "$ROOT_DIR/tests/general.sh"
cd "$ROOT_DIR"
# shellcheck disable=SC2317
function clean_up() {
run_docker rmi "githooks:test-rules" &>/dev/null || true
run_docker volume rm gh-test-tmp &>/dev/null || true
}
trap clean_up EXIT
clean_up
# Build container to only copy to volumes.
cat <<EOF | run_docker build \
--force-rm -t "githooks:volumecopy" -f - . || exit 1
FROM scratch
CMD you-should-not-run-this-container
EOF
# Build test container.
cat <<EOF | run_docker build --force-rm -t githooks:test-rules -f - .
FROM alpine:3.23.0
RUN apk update && apk add curl git
RUN git config --global safe.directory /data
# Install Nix
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux \
--extra-conf "sandbox = false" \
--init none \
--no-confirm
ENV PATH="/nix/var/nix/profiles/default/bin:\$PATH"
RUN nix --version
ADD flake.nix flake.lock /
RUN nix --accept-flake-config develop ".#default" --command true
ENV DOCKER_RUNNING=true
EOF
# Create a volume where all test setup and repositories go in.
# Is mounted to `/tmp`
run_docker volume create gh-test-tmp
# Always show diffs.
export GH_SHOW_DIFFS=true
mountArg=":ro"
if [ "${GH_FIX:-}" = "true" ]; then
mountArg=""
fi
run_docker run --rm -it \
-v "$ROOT_DIR:/data$mountArg" \
-v "gh-test-tmp:/tmp" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-e "GH_SHOW_DIFFS=${GH_SHOW_DIFFS:-false}" \
-e "GH_FIX=${GH_FIX:-false}" \
-w /data \
githooks:test-rules \
nix --accept-flake-config develop ".#default" --command tests/exec-rules.sh ||
{
echo "! Check rules had failures: exit code: $?"
exit 1
}