-
Notifications
You must be signed in to change notification settings - Fork 28
/
docker-ci
executable file
·188 lines (167 loc) · 4.26 KB
/
docker-ci
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/sh -ef
. ./config
TESTS_DIR="$(pwd)"
print_usage()
{
cat <<EOF
$0 [--shell] [--download] [--no-compare] --target {TARGET} --implementation {IMPLEMENTATION} [--os {OS}] [--arch {ARCH}]"
Runs Kaitai Struct CI for a specific target and implementation in a
Docker container using image that guarantees to have all necessary
prerequisites installed.
Options:
-t|--target NAME select target programming language
-u|--subtarget NAME select variant of target programming language
-i|--implementation NAME select implementation of programming language
--os NAME select operating system
--arch NAME select architecture
-s|--shell launches interactive shell instead of CI script
-d|--download attempt to download image from ghcr.io if missing
-r|--rebuild clean up everything and rebuild
--no-compare don't compare with previous master build from CI
Available images:
EOF
docker images --filter='label=io.kaitai.ci=true'
}
# Cleans up leftover binary artifacts from previous builds to make sure we're starting from scratch
cleanup_bin()
{
echo "Cleaning up binary artifacts..."
case "$TARGET" in
cpp_stl|java)
sudo rm -rf "compiled/$TARGET$SUBTARGET/bin"
;;
esac
}
is_image_available()
{
docker images --no-trunc -q "$1" 2> /dev/null | grep -q '^sha256:[0-9a-f]\+$'
}
# Define default values for parameters
TARGET=""
SUBTARGET=""
IMPLEMENTATION=""
OS=linux
ARCH=x86_64
SHELL_FLAG=0
DOWNLOAD_FLAG=0
REBUILD_FLAG=0
DO_COMPARE_FLAG=1
# Parse command-line options
while [ $# -gt 0 ]; do
key="$1"
case "$key" in
--shell|-s)
SHELL_FLAG=1
DO_COMPARE_FLAG=0
shift
;;
--download|-d)
DOWNLOAD_FLAG=1
shift
;;
--rebuild|-r)
REBUILD_FLAG=1
shift
;;
--target|-t)
TARGET="$2"
shift 2
;;
--subtarget|-u)
SUBTARGET="$2"
shift 2
;;
--implementation|-i)
IMPLEMENTATION="$2"
shift 2
;;
--os)
OS="$2"
shift 2
;;
--arch)
ARCH="$2"
shift 2
;;
--no-compare)
DO_COMPARE_FLAG=0
shift
;;
--help|-h)
print_usage
exit 0
;;
*)
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
if [ -z "$TARGET" ] || [ -z "$IMPLEMENTATION" ] || [ -z "$OS" ] || [ -z "$ARCH" ]; then
echo "Missing required parameters."
exit 1
fi
EXTRA_OPTS=
IMG_NAME="kaitai-$TARGET-$IMPLEMENTATION-$OS-$ARCH"
# Check image availability
if is_image_available "$IMG_NAME"; then
# If locally-built image exists, prioritize that
IMG_COORD="$IMG_NAME"
elif is_image_available "ghcr.io/kaitai-io/$IMG_NAME"; then
# If ghcr.io image exists, use it
IMG_COORD="ghcr.io/kaitai-io/$IMG_NAME"
elif [ "$DOWNLOAD_FLAG" = 1 ]; then
# No image, but we'll try to download
IMG_COORD="ghcr.io/kaitai-io/$IMG_NAME"
docker pull "$IMG_COORD"
else
echo 'Neither locally-built nor remotely-built image is present. Try using `--download` to try downloading prebuilt image from ghcr.io.'
exit 2
fi
# If --shell used, invoke /bin/sh
if [ "$SHELL_FLAG" = 1 ]; then
COMMAND=/bin/sh
EXTRA_OPTS=-it
else
COMMAND="./ci-$TARGET$SUBTARGET"
fi
if [ -n "$GITHUB_ACTIONS" ]; then
echo "GITHUB_ACTIONS=$GITHUB_ACTIONS"
echo "GITHUB_RUN_ID=$GITHUB_RUN_ID"
echo "GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER"
echo "GH_JOB_ID=$GH_JOB_ID"
echo "GH_HTML_URL=$GH_HTML_URL"
fi
if [ "$DO_COMPARE_FLAG" = 1 ]; then
./report-download-github "$TARGET" "$SUBTARGET" "$IMPLEMENTATION" "$OS" "$ARCH" || :
fi
if [ "$REBUILD_FLAG" = 1 ]; then
cleanup_bin
fi
# If we run in Mingw/MSYS environment on Windows, it will invoke `docker.exe` here,
# but it will attempt to do Linux-to-Windows paths conversion with `cygpath.exe`.
# We disable it with MSYS2_ARG_CONV_EXCL argument: looks like `docker.exe` is
# intelligent enough to understand Mingw-style Windows paths by itself.
#
# See https://www.msys2.org/docs/filesystem-paths/
MSYS2_ARG_CONV_EXCL='*' docker run $EXTRA_OPTS \
--rm \
-e GITHUB_ACTIONS \
-e GITHUB_RUN_ID \
-e GITHUB_RUN_NUMBER \
-e GH_JOB_ID \
-e GH_HTML_URL \
-v "$TESTS_DIR":/tests \
-v "$TESTS_DIR/../runtime":/runtime \
-w /tests \
--network none \
"$IMG_COORD" \
"$COMMAND"
if [ "$DO_COMPARE_FLAG" = 1 ]; then
echo "# Comparison with previous"
echo
aggregate/compare_with_prev \
"ci_results/$TARGET$SUBTARGET/$IMPLEMENTATION-$OS-$ARCH/ci.json" \
"test_out/$TARGET$SUBTARGET/ci.json"
fi