From c15361a1d9bb6598785ca5fddce86788a43462fc Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Thu, 2 Jan 2025 12:05:31 +0100 Subject: [PATCH] jsoninfo: add `inventory-artifacts` cli, which stops after artifacts-reduced and adds kernels.ndjson and uboots.njdson via jq - if one runs `./compile.sh inventory-artifacts` we shall get: - `output/info/kernels.ndjson`: one line for each kernel build - `output/info/uboots.ndjson`: one line for each u-boot build - this is meant as base for other tooling that acts "for each kernel" or "for each u-boot" such as patch/config rewrites, etc --- lib/functions/cli/cli-jsoninfo.sh | 15 +++++++++++++++ lib/functions/cli/commands.sh | 19 ++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/functions/cli/cli-jsoninfo.sh b/lib/functions/cli/cli-jsoninfo.sh index 22ee241e6c13..08361358bb34 100644 --- a/lib/functions/cli/cli-jsoninfo.sh +++ b/lib/functions/cli/cli-jsoninfo.sh @@ -17,10 +17,12 @@ function cli_json_info_run() { prep_conf_main_minimal_ni + # shellcheck disable=SC2317 function json_info_logged() { # logging wrapper LOG_SECTION="json_info" do_with_logging json_info_only } + # shellcheck disable=SC2317 function json_info_only() { prepare_python_and_pip # requires HOSTRELEASE @@ -113,6 +115,8 @@ function cli_json_info_run() { declare IMAGE_INFO_CSV_FILE="${BASE_INFO_OUTPUT_DIR}/image-info.csv" declare INVENTORY_BOARDS_CSV_FILE="${BASE_INFO_OUTPUT_DIR}/boards-inventory.csv" declare REDUCED_ARTIFACTS_FILE="${BASE_INFO_OUTPUT_DIR}/artifacts-reduced.json" + declare REDUCED_KERNELS_FILE="${BASE_INFO_OUTPUT_DIR}/kernels.ndjson" + declare REDUCED_UBOOTS_FILE="${BASE_INFO_OUTPUT_DIR}/uboots.ndjson" declare ARTIFACTS_INFO_FILE="${BASE_INFO_OUTPUT_DIR}/artifacts-info.json" declare ARTIFACTS_INFO_UPTODATE_FILE="${BASE_INFO_OUTPUT_DIR}/artifacts-info-uptodate.json" declare OUTDATED_ARTIFACTS_IMAGES_FILE="${BASE_INFO_OUTPUT_DIR}/outdated-artifacts-images.json" @@ -199,6 +203,17 @@ function cli_json_info_run() { if [[ ! -f "${REDUCED_ARTIFACTS_FILE}" ]]; then display_alert "Reducing info into artifacts" "artifact-reducer" "info" run_host_command_logged "${PYTHON3_VARS[@]}" "${PYTHON3_INFO[BIN]}" "${INFO_TOOLS_DIR}"/artifact-reducer.py "${IMAGE_INFO_FILE}" ">" "${REDUCED_ARTIFACTS_FILE}" + + # Simple jq to get reduced kernels, with board and branch coordinates and number of images for each; NDJSON (newline-delimited JSON) format. + jq -c '.[] | select(.artifact_name == "kernel") | {"vars": .original_inputs.vars,"kernel":.inputs.LINUXFAMILY,"needed_by":.needed_by} | {"BOARD":.vars.BOARD,"BRANCH":.vars.BRANCH,"kernel":.kernel,"needed_by":.needed_by}' < "${REDUCED_ARTIFACTS_FILE}" > "${REDUCED_KERNELS_FILE}" + + # Similar, but for u-boot's. + jq -c '.[] | select(.artifact_name == "uboot") | {"vars": .original_inputs.vars,"needed_by":.needed_by} | {"BOARD":.vars.BOARD,"BRANCH":.vars.BRANCH,"needed_by":.needed_by}' < "${REDUCED_ARTIFACTS_FILE}" > "${REDUCED_UBOOTS_FILE}" + fi + + if [[ "${ARMBIAN_COMMAND}" == "inventory-artifacts" ]]; then + display_alert "Done with" "inventory-artifacts" "info" + return 0 fi # The artifact info extractor. diff --git a/lib/functions/cli/commands.sh b/lib/functions/cli/commands.sh index 2c544601a26c..d7051f156144 100644 --- a/lib/functions/cli/commands.sh +++ b/lib/functions/cli/commands.sh @@ -27,15 +27,16 @@ function armbian_register_commands() { ["config-dump-json"]="config_dump_json" # implemented in cli_config_dump_json_pre_run and cli_config_dump_json_run ["config-dump-no-json"]="config_dump_json" # implemented in cli_config_dump_json_pre_run and cli_config_dump_json_run - ["inventory"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["targets"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["targets-dashboard"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["inventory-boards"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["targets-composed"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["debs-to-repo-json"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["gha-matrix"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["gha-workflow"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run - ["gha-template"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["inventory"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["targets"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["targets-dashboard"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["inventory-boards"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["inventory-artifacts"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["targets-composed"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["debs-to-repo-json"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["gha-matrix"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["gha-workflow"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run + ["gha-template"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run # These probably should be in their own separate CLI commands file, but for now they're together in jsoninfo. ["debs-to-repo-download"]="json_info" # implemented in cli_json_info_pre_run and cli_json_info_run