Skip to content

Commit 9944956

Browse files
committed
ci: use shell for SerDe snapshot setup
1 parent c778535 commit 9944956

3 files changed

Lines changed: 139 additions & 150 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
distribution: 'temurin'
3636

3737
- name: Download ${{ matrix.name }} snapshots
38-
run: python3 tools/download_serialization_test_data.py ${{ matrix.language }}
38+
run: ./tools/download_serialization_test_data.sh ${{ matrix.language }}
3939

4040
- name: Run Java tests against ${{ matrix.name }} snapshots
4141
run: mvn test -P ${{ matrix.profile }}

tools/download_serialization_test_data.py

Lines changed: 0 additions & 149 deletions
This file was deleted.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -euo pipefail
21+
22+
# Pin the archive so compatibility tests always use an immutable snapshot set.
23+
readonly TCK_REVISION="d363b12d293b395d90abb42677f9ea63178dbc0d"
24+
readonly TCK_ARCHIVE_URL="https://api.github.com/repos/apache/datasketches-tck/tarball/${TCK_REVISION}"
25+
readonly SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26+
readonly REPOSITORY_ROOT="$(cd "${SCRIPT_DIRECTORY}/.." && pwd)"
27+
readonly SERIALIZATION_DATA="${REPOSITORY_ROOT}/serialization_test_data"
28+
29+
usage() {
30+
echo "Usage: $0 [cpp] [go]"
31+
echo "Download C++ and/or Go serialization snapshots (both by default)."
32+
}
33+
34+
if [[ $# -eq 0 ]]; then
35+
set -- cpp go
36+
fi
37+
38+
languages=()
39+
for language in "$@"; do
40+
case "${language}" in
41+
cpp | go)
42+
;;
43+
-h | --help)
44+
usage
45+
exit 0
46+
;;
47+
*)
48+
echo "Unsupported language: ${language}" >&2
49+
usage >&2
50+
exit 2
51+
;;
52+
esac
53+
54+
case " ${languages[*]-} " in
55+
*" ${language} "*)
56+
;;
57+
*)
58+
languages+=("${language}")
59+
;;
60+
esac
61+
done
62+
63+
for command in curl tar mktemp; do
64+
if ! command -v "${command}" >/dev/null 2>&1; then
65+
echo "Required command not found: ${command}" >&2
66+
exit 1
67+
fi
68+
done
69+
70+
mkdir -p "${SERIALIZATION_DATA}"
71+
temporary_directory="$(mktemp -d "${TMPDIR:-/tmp}/datasketches-tck.XXXXXX")"
72+
staging_directory=""
73+
74+
cleanup() {
75+
rm -rf "${temporary_directory}"
76+
if [[ -n "${staging_directory}" && -d "${staging_directory}" ]]; then
77+
rm -rf "${staging_directory}"
78+
fi
79+
}
80+
trap cleanup EXIT
81+
82+
archive_path="${temporary_directory}/datasketches-tck.tar.gz"
83+
echo "Downloading serialization snapshots from ${TCK_ARCHIVE_URL}"
84+
curl \
85+
--fail \
86+
--location \
87+
--silent \
88+
--show-error \
89+
--connect-timeout 60 \
90+
--max-time 120 \
91+
--header "Accept: application/vnd.github+json" \
92+
--header "User-Agent: apache-datasketches-java" \
93+
--header "X-GitHub-Api-Version: 2022-11-28" \
94+
--output "${archive_path}" \
95+
"${TCK_ARCHIVE_URL}"
96+
97+
for language in "${languages[@]}"; do
98+
staging_directory="$(
99+
mktemp -d "${SERIALIZATION_DATA}/.${language}_generated_files.XXXXXX"
100+
)"
101+
count=0
102+
103+
while IFS= read -r member; do
104+
case "${member}" in
105+
*/serialization/"${language}"/snapshots/*.sk)
106+
name="${member##*/}"
107+
output="${staging_directory}/${name}"
108+
if [[ -e "${output}" || -L "${output}" ]]; then
109+
echo "Duplicate snapshot in archive: ${name}" >&2
110+
exit 1
111+
fi
112+
tar -xOzf "${archive_path}" "${member}" > "${output}"
113+
count=$((count + 1))
114+
;;
115+
esac
116+
done < <(tar -tzf "${archive_path}")
117+
118+
if [[ ${count} -eq 0 ]]; then
119+
echo "No ${language} snapshots found in the TCK archive" >&2
120+
exit 1
121+
fi
122+
123+
destination="${SERIALIZATION_DATA}/${language}_generated_files"
124+
if [[ -L "${destination}" ]]; then
125+
echo "Snapshot output path cannot be a symbolic link: ${destination}" >&2
126+
exit 1
127+
fi
128+
if [[ -e "${destination}" && ! -d "${destination}" ]]; then
129+
echo "Snapshot output path is not a directory: ${destination}" >&2
130+
exit 1
131+
fi
132+
if [[ -d "${destination}" ]]; then
133+
rm -rf "${destination}"
134+
fi
135+
mv "${staging_directory}" "${destination}"
136+
staging_directory=""
137+
echo "Extracted ${count} ${language} snapshots into ${destination}"
138+
done

0 commit comments

Comments
 (0)