Skip to content

Commit

Permalink
Fix psrule config to use repo root relative path (#19)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reijoh authored Oct 30, 2024
1 parent a3947fb commit a7f7002
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/psrule-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7f7002

Please sign in to comment.