diff --git a/.github/scripts/utils.sh b/.github/scripts/utils.sh index ec29124..d4f61dc 100755 --- a/.github/scripts/utils.sh +++ b/.github/scripts/utils.sh @@ -49,7 +49,7 @@ function exit_with_error { function export_db_json { local db_file=$1 - local objects=() + local json_dump="{}" local rows tables=$( @@ -60,16 +60,20 @@ function export_db_json { ORDER BY name" ) + echo "${json_dump}" > bomctl-export.json + for table in $tables; do rows=$(sqlite3 "${db_file}" -json "SELECT * FROM ${table}") [[ -z $rows ]] && rows="[]" - objects+=("$(printf '{"%s": %s}' "$table" "$rows")") - done + echo "${rows}" | jq --arg table "${table}" '{($table): .}' > "tmp-${table}.json" - output=$(echo "${objects[*]}" | jq --slurp 'reduce .[] as $obj ({}; . += $obj)') - echo "$output" > bomctl-export.json + json_dump=$(jq --slurpfile data "tmp-${table}.json" '. += $data[]' bomctl-export.json) + echo "${json_dump}" > bomctl-export.json + + rm "tmp-${table}.json" + done } function export_db_sql {