-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest.sh
executable file
·112 lines (94 loc) · 2.99 KB
/
test.sh
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
#!/bin/bash
set -e
PWD=$(pwd)
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
PROJECT_ROOT=$(realpath "$SCRIPT_PATH/..")
if [ "$GITHUB_BASE_REF" != "" ]; then
TARGET_BRANCH="origin/$GITHUB_BASE_REF"
echo "PR event: running against base branch $TARGET_BRANCH"
elif [ "$GITHUB_EVENT_NAME" = "push" ]; then
TARGET_BRANCH=$(git rev-parse HEAD~1)
echo "Push event: running against previous commit $TARGET_BRANCH"
else
TARGET_BRANCH="origin/main"
echo "Local run: running against default branch $TARGET_BRANCH"
fi
SERVER=1
CLIENT=1
E2E=1
INFRASTRUCTURE=1
# shellcheck source=SCRIPTDIR/helpers.sh
source "$SCRIPT_PATH/helpers.sh"
while [[ "$#" -gt 0 ]]; do
case $1 in
--server)
SERVER=1
CLIENT=0
E2E=0
INFRASTRUCTURE=0
shift
;;
--client)
SERVER=0
CLIENT=1
E2E=0
INFRASTRUCTURE=0
shift
;;
--e2e)
SERVER=0
CLIENT=0
E2E=1
INFRASTRUCTURE=0
shift
;;
--infrastructure)
SERVER=0
CLIENT=0
E2E=0
INFRASTRUCTURE=1
shift
;;
*) usage ;;
esac
done
AT_LEAST_ONE_ERROR=0
cd "$PROJECT_ROOT"
if [[ $SERVER -eq 1 ]]; then
OLD_PATH="$PATH"
# Fixes playwright.
# See: https://github.com/microsoft/playwright/issues/5501
PATH="$VIRTUAL_ENV/bin:/bin:/sbin/:$PATH"
capture_stdout_and_stderr_if_successful pytest
capture_stdout_and_stderr_if_successful flake8 .
capture_stdout_and_stderr_if_successful isort -c .
capture_stdout_and_stderr_if_successful black . --check
capture_stdout_and_stderr_if_successful mypy --no-incremental .
PATH="$OLD_PATH"
fi
if [[ $CLIENT -eq 1 ]]; then
# capture_stdout_and_stderr_if_successful node_modules/.bin/tslint -p packages/reactivated
# capture_stdout_and_stderr_if_successful node_modules/.bin/tslint -p sample
capture_stdout_and_stderr_if_successful npm exec -- prettier --ignore-path .gitignore --check '**/*.{ts,tsx,yaml,json}'
fi
if [[ $E2E -eq 1 ]]; then
capture_stdout_and_stderr_if_successful echo "No E2E tests yet"
fi
if [[ $INFRASTRUCTURE -eq 1 ]]; then
target_ref=$(git merge-base "$TARGET_BRANCH" HEAD)
CHANGED_NIX_FILES=$(git diff --name-only --diff-filter d --relative "$target_ref" | grep -e '.nix$' || true)
CHANGED_SH_FILES=$(git diff --name-only --diff-filter d --relative "$target_ref" | grep -e '.sh$' || true)
if [[ -n "${CHANGED_SH_FILES// /}" ]]; then
# shellcheck disable=SC2086
capture_stdout_and_stderr_if_successful shellcheck $CHANGED_SH_FILES -x
# shellcheck disable=SC2086
capture_stdout_and_stderr_if_successful shfmt -d $CHANGED_SH_FILES
fi
if [[ -n "${CHANGED_NIX_FILES// /}" ]]; then
# shellcheck disable=SC2086
capture_stdout_and_stderr_if_successful nixfmt -c $CHANGED_NIX_FILES
fi
# capture_stdout_and_stderr_if_successful terraform fmt -recursive -check
fi
cd "$PWD"
exit $AT_LEAST_ONE_ERROR