[bitnami/*] Change pipelines to get to build branch from readme (#191)

* Change pipelines to try to get modified branch from readme file

Signed-off-by: Fran Mulero <fmulero@vmware.com>

* Amend jspath to get README changes

Signed-off-by: Fran Mulero <fmulero@vmware.com>

* Apply suggestions

Signed-off-by: Fran Mulero <fmulero@vmware.com>
This commit is contained in:
Fran Mulero
2022-07-20 19:43:59 +02:00
committed by GitHub
parent 78f99c83e7
commit fc376afd55
2 changed files with 29 additions and 4 deletions
+11
View File
@@ -33,6 +33,17 @@ jobs:
files_changed="$(echo $files_changed_data | jq -r '.files[] | .filename')"
# Adding || true to avoid "Process exited with code 1" errors
containers+=($(echo "$files_changed" | xargs dirname | grep -o "bitnami/[^/]*/[^/]*/[^/]*" | sort | uniq || true))
# Changes done in readme files?
readme_object="$(echo $files_changed_data | jq -r '[ .files[] | select(.filename | test("bitnami/[^/]+/README.md"))] | first')"
if [[ "${readme_object}" != "null" ]]; then
# Look for modified branch in Readme content
container_name="$(echo ${readme_object} | jq -r '.filename' | sed -nr "s|bitnami/([^/]+)/README.md|\1|p")"
branch="$(echo ${readme_object} | jq -r '.patch' | grep -o "([^/]*/[^/]*/Dockerfile)" | sort -u | sed -nr "s|\((.+)/Dockerfile\)|\1|p")"
if [[ ! -z "${branch}" ]] && [[ ! -z "${container_name}" ]]; then
# readme file changed and the diff contains a change about the latest version generated by EAM
containers+=("bitnami/${container_name}/${branch}")
fi
fi
done
if [[ "${#containers[@]}" -le "0" ]]; then
+18 -4
View File
@@ -33,17 +33,31 @@ jobs:
# Adding || true to avoid "Process exited with code 1" errors
containers_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "bitnami/[^/]*" | sort | uniq || true)"
flavors=($(echo "$files_changed" | xargs dirname | grep -o "bitnami/[^/]*/[^/]*/[^/]*" | sort | uniq || true))
container_name=$(echo "$containers_dirs_changed" | sed "s|bitnami/||g")
if [[ "${#flavors[@]}" -eq "1" ]]; then
# Changes done in only one container -> OK
container_name=$(echo "$containers_dirs_changed" | sed "s|bitnami/||g")
echo "::set-output name=result::ok"
echo "::set-output name=container::${container_name}"
echo "::set-output name=path::${flavors[0]}"
elif [[ "${#flavors[@]}" -le "0" ]]; then
# Changes done in the containers/ folder but not inside a container subfolder -> SKIP
echo "::set-output name=error::No changes detected in containers. The rest of the tests will be skipped."
echo "::set-output name=result::skip"
# Changes done in the containers/ folder but not inside a container subfolder -> Look for readme changes
readme_object="$(echo $files_changed_data | jq -r '[ .[] | select(.filename | test("bitnami/[^/]+/README.md"))] | first')"
if [[ "${readme_object}" == "null" ]]; then
echo "::set-output name=error::No changes detected in containers. The rest of the tests will be skipped."
echo "::set-output name=result::skip"
else
# Look for the modified branch in Readme content
branch="$(echo ${readme_object} | jq -r '.patch' | grep -o "([^/]*/[^/]*/Dockerfile)" | sort -u | sed -nr "s|\((.+)/Dockerfile\)|\1|p")"
if [[ ! -z "${branch}" ]]; then
echo "::set-output name=result::ok"
echo "::set-output name=container::${container_name}"
echo "::set-output name=path::bitnami/${container_name}/${branch}"
else
echo "::set-output name=error::No changes detected in containers. The rest of the tests will be skipped."
echo "::set-output name=result::skip"
fi
fi
else
# Changes done in more than container -> SKIP
echo -e "::set-output name=error::Changes detected in more than one container directory:\n${containers_dirs_changed}\nIt is strongly advised to change only one container in a PR. The rest of the tests will be skipped."