Skip to content

Commit

Permalink
ci: temp files for table data
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Howard <[email protected]>
  • Loading branch information
jhoward-lm committed Nov 18, 2024
1 parent b4eed1c commit 3d5f39c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions .github/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function exit_with_error {

function export_db_json {
local db_file=$1
local objects=()
local json_dump="{}"
local rows

tables=$(
Expand All @@ -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 {
Expand Down

0 comments on commit 3d5f39c

Please sign in to comment.