Repository navigation
Expand file tree
/
Copy pathimage-test.sh
More file actions
executable file
Β·135 lines (121 loc) Β· 3.27 KB
/
Copy pathimage-test.sh
File metadata and controls
executable file
Β·135 lines (121 loc) Β· 3.27 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
check_user_not_root() {
if [ "$(id -u)" -eq 0 ]; then
echo "User must not be root! π£" >&2
exit 1
else
echo "User is unprivileged $(whoami) π"
fi
}
check_command_missing() {
local command=$1
if command -v "$command" &> /dev/null; then
echo "$command exists but should not π£" >&2
exit 1
else
echo "$command is missing π"
fi
}
check_command_exists() {
local command=$1
local default_version_option="--version"
local version_option="${2:-$default_version_option}"
if "$command" "$version_option" >/dev/null; then
echo "$command β
"
else
echo "$command β" >&2
exit 1
fi
}
check_git_foreign_owned_repo() {
local repo
repo=$(mktemp -d)
git init -q "$repo"
# GIT_TEST_ASSUME_DIFFERENT_OWNER makes git treat the repo as owned by another user, the same
# situation as a project bind-mounted from the host or checked out by CI under a different UID.
# Without safe.directory=* in the system gitconfig, git refuses to work in such repos with
# "detected dubious ownership" (exit 128), breaking e.g. Gradle plugins that read git state.
if GIT_TEST_ASSUME_DIFFERENT_OWNER=1 git -C "$repo" rev-parse --git-dir > /dev/null; then
echo "git works in repos owned by another user β
"
else
echo "git fails in repos owned by another user (safe.directory not set?) β" >&2
exit 1
fi
rm -rf "$repo"
}
check_dir() {
local dir=$1
if [[ -d "$dir" ]]; then
echo "$dir exists β
"
else
echo "Error: directory not found: $dir" >&2
exit 1
fi
}
check_dir_writable() {
local dir=$1
if test -w "$dir"; then
echo "$dir writable β
"
else
echo "$dir not writable but must be β" >&2
exit 1
fi
}
check_env() {
local var=$1
if [[ -n ${!var} ]]; then
echo "$var present β
"
else
echo "Error: env var missing or empty: $var" >&2
exit 1
fi
}
# Security
echo
echo "Security check"
check_user_not_root
check_command_missing "apt"
check_command_missing "apt-get"
check_command_missing "dpkg"
check_command_missing "npm"
check_command_missing "su"
check_command_missing "sudo"
# Required custom SW
echo
echo "Required custom SW check"
check_command_exists "git"
check_git_foreign_owned_repo
check_command_exists "git-lfs"
check_command_exists "java"
check_command_exists "sdkmanager"
check_dir_writable "$ANDROID_HOME"
check_dir "$ANDROID_HOME/cmdline-tools"
check_dir "$ANDROID_HOME/licenses"
check_dir "$ANDROID_HOME/platform-tools"
check_command_exists "danger"
check_command_exists "danger-kotlin"
check_command_exists "kotlinc" "-version" # Needed for danger-kotlin
check_command_exists "nodejs" # Needed for danger (JS)
check_dir "/usr/local/lib/danger" # Check that danger-kotlin lib exists
check_dir "/usr/local/lib/node_modules/danger" # Check that danger node_modules exists
# Commonly used Linux SW on CI
echo
echo "Commonly used Linux SW on CI check"
check_command_exists "awk"
check_command_exists "cat"
check_command_exists "cp"
check_command_exists "grep"
check_command_exists "ln"
check_command_exists "mkdir"
check_command_exists "rm"
# Env vars
echo
echo "Env vars check"
check_env "ANDROID_HOME"
check_env "JAVA_HOME"
# Build image-test-app
echo
echo "Build image-test-app check"
cd /image-test-app
./gradlew assembleDebug --no-daemon
echo "image-test-app build successful β
"