From a7f7002cbde9ed02b413e62f90cdc42e420c3691 Mon Sep 17 00:00:00 2001 From: Reidar Johansen Date: Wed, 30 Oct 2024 16:03:14 +0100 Subject: [PATCH] Fix psrule config to use repo root relative path (#19) When template and parameters file is in a subfolder, psrule fail with "Unable to find template referenced within parameter file". This update will fix that. Additional fixes: - If the parameters file was updated with metadata, then the updated file will be included in job artifacts. - Add more output to the workflow log to show what is going on. --- scripts/psrule-config.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/psrule-config.sh b/scripts/psrule-config.sh index b139b60..178e2ec 100755 --- a/scripts/psrule-config.sh +++ b/scripts/psrule-config.sh @@ -15,21 +15,28 @@ else echo "Use PSRule config at ${OPTION}" if test -n "${TEMPLATE_FILE}" && [[ "${TEMPLATE_PARAMS_FILE}" == *'.parameters.json' ]]; then file=$TEMPLATE_PARAMS_FILE - t=$(basename "${TEMPLATE_FILE}") - p=$(basename "${file}") + t=$(realpath --relative-to="$(pwd)" "${TEMPLATE_FILE}") + p=$(realpath --relative-to="$(pwd)" "${file}") if [ "${t/.json/}" != "${p/.parameters.json/}" ]; then + echo "Template name '${t/.json/}' differ from parameters '${p/.parameters.json/}'" meta=$(jq -r '.metadata | select (.!=null)' "${file}") if test -z "${meta}"; then json=$(jq --arg t "${t}" '. += {metadata:{template:$t}}' "${file}") if test -n "${json}"; then printf '%s\n' "${json}" >"${file}" + echo "Added metadata to ${file}" + cp "${file}" "${LOG_PATH}/" fi else json=$(jq --arg t "${t}" '.metadata += {template:$t}' "${file}") if test -n "${json}"; then printf '%s\n' "${json}" >"${file}" + echo "Updated metadata in ${file}" + cp "${file}" "${LOG_PATH}/" fi fi + else + echo "No need to set metadata in ${file}" fi fi fi