Skip to content

Commit 37bd835

Browse files
committed
Use jq to join artificats files in import script
1 parent 1e70791 commit 37bd835

File tree

1 file changed

+3
-7
lines changed
  • mithril-test-lab/mithril-aggregator-fake/scripts

1 file changed

+3
-7
lines changed

mithril-test-lab/mithril-aggregator-fake/scripts/import.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,17 @@ join_artifacts_files() {
162162
local -r name=${1:?"No artifact name given to join_artifacts_files function."};
163163
local -r src="${DATA_DIR:?}/${name}"
164164
local -r dest="$DATA_DIR"/"$name"s.json
165-
local buffer=""
166-
local separator=""
165+
local buffer="{}"
167166

168167
echo "Joining ${name} artifacts into ${dest}"
169168

170169
local key=""
171-
buffer+="{"
172170
for filename in "$src/"*; do
173171
key=$(basename "${filename%.*}")
174-
buffer+=$(echo "$separator\"$key\": " | cat - "$filename")
175-
separator=","
172+
buffer=$(echo $buffer | jq --slurpfile file "$filename" ". += {\"${key}\": \$file[0]}")
176173
done
177-
buffer+="}"
178174

179-
echo ${buffer} | jq > "$dest"
175+
echo "${buffer}" > "$dest"
180176
rm -rf "$src"
181177
}
182178

0 commit comments

Comments
 (0)