[bitnami/*] Fix CI-CD pipelines (#367)
* Fix issue getting tag for new releases Signed-off-by: Fran Mulero <fmulero@vmware.com> * Ignore bitnami subfolders Signed-off-by: Fran Mulero <fmulero@vmware.com> * Avoid duplicates in CD pipeline Signed-off-by: Fran Mulero <fmulero@vmware.com> * Avoid duplicates in CD pipeline and fix issue with labeled event Signed-off-by: Fran Mulero <fmulero@vmware.com> * Fix typo Signed-off-by: Fran Mulero <fmulero@vmware.com>
This commit is contained in:
parent
de964fc93b
commit
0682c62899
|
|
@ -27,23 +27,30 @@ jobs:
|
|||
commits=($(echo "${GITHUB_COMMITS}" | jq -r '.[] | .id'))
|
||||
containers=()
|
||||
for commit in "${commits[@]}"; do
|
||||
containers_in_commit=()
|
||||
# Using the Github API to detect the files changed as git merge-base stops working when the branch is behind
|
||||
URL="https://api.github.com/repos/${{ github.repository }}/commits/${commit}"
|
||||
files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL")
|
||||
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))
|
||||
containers_in_commit+=($(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')"
|
||||
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")"
|
||||
branch="$(echo ${readme_object} | jq -r '.patch' | grep -o "([^/]*/[^/]*/Dockerfile)" | sort -u | head -n 1 | 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}")
|
||||
containers_in_commit+=("bitnami/${container_name}/${branch}")
|
||||
fi
|
||||
fi
|
||||
for container in "${containers_in_commit[@]}"; do
|
||||
if [[ ! $containers =~ (^|[[:space:]])$container($|[[:space:]]) ]]; then
|
||||
# Avoid duplicates
|
||||
containers+=("${container}")
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if [[ "${#containers[@]}" -le "0" ]]; then
|
||||
|
|
@ -76,10 +83,17 @@ jobs:
|
|||
- id: get-container-metadata
|
||||
name: Get image tag and container name
|
||||
run: |
|
||||
tag="$(git log --pretty=tformat:"%s" -n 1 --grep=" release$" --author bitnami-bot@vmware.com --author containers@bitnami.com --author containers-bot@bitnami.com -- ${{ matrix.container }} | awk '{print $1}')"
|
||||
name="$(echo "${{ matrix.container }}" | awk -F '/' '{print $2}')"
|
||||
echo "::set-output name=tag::${tag}"
|
||||
echo "::set-output name=name::${name}"
|
||||
# Now EAM commits has the following format "[bitnami/<container>] Release <tag>"
|
||||
tag="$(git log --pretty=tformat:"%s" -n 1 --grep="[R|r]elease" --author bitnami-bot@vmware.com --author containers@bitnami.com --author containers-bot@bitnami.com -- ${{ matrix.container }} | sed "s|\[.*\]||" | sed "s|[R|r]elease||" | sed "s|[[:space:]]*||")"
|
||||
if [[ -z "${tag}" ]]; then
|
||||
echo "No tag found for: ${{ needs.get-container.outputs.path }}"
|
||||
exit 1
|
||||
else
|
||||
name="$(echo "${{ matrix.container }}" | awk -F '/' '{print $2}')"
|
||||
echo "::set-output name=tag::${tag}"
|
||||
echo "::set-output name=name::${name}"
|
||||
echo "::set-output name=tag::${tag}"
|
||||
fi
|
||||
- uses: vmware-labs/vmware-image-builder-action@main
|
||||
name: "Publish ${{ steps.get-container-metadata.outputs.name }}: ${{ steps.get-container-metadata.outputs.tag }}"
|
||||
with:
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ jobs:
|
|||
files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL")
|
||||
files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')"
|
||||
# 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))
|
||||
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
|
||||
|
|
@ -48,13 +48,13 @@ jobs:
|
|||
echo "::set-output name=path::${flavors[0]}"
|
||||
elif [[ "${#flavors[@]}" -le "0" ]]; then
|
||||
# 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')"
|
||||
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")"
|
||||
branch="$(echo ${readme_object} | jq -r '.patch' | grep -o "([^/]*/[^/]*/Dockerfile)" | sort -u | head -n 1 | sed -nr "s|\((.+)/Dockerfile\)|\1|p")"
|
||||
if [[ ! -z "${branch}" ]]; then
|
||||
echo "::set-output name=result::ok"
|
||||
echo "::set-output name=container::${container_name}"
|
||||
|
|
@ -86,14 +86,23 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
name: Checkout Repository
|
||||
# Required to search the latest commit with the tag
|
||||
with:
|
||||
# Required to search the latest commit with the tag
|
||||
fetch-depth: 0
|
||||
# labeled events trigger the event with the latest commit in main
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
- id: get-tag
|
||||
name: Get latest image tag
|
||||
run: |
|
||||
tag="$(git log --pretty=tformat:"%s" -n 1 --grep=" release$" --author bitnami-bot@vmware.com --author containers@bitnami.com --author containers-bot@bitnami.com -- ${{ needs.get-container.outputs.path }} | awk '{print $1}')"
|
||||
echo "::set-output name=tag::${tag}"
|
||||
# Now EAM commits has the following format "[bitnami/<container>] Release <tag>"
|
||||
tag="$(git log --pretty=tformat:"%s" -n 1 --grep="[R|r]elease" --author bitnami-bot@vmware.com --author containers@bitnami.com --author containers-bot@bitnami.com -- ${{ needs.get-container.outputs.path }} | sed "s|\[.*\]||" | sed "s|[R|r]elease||" | sed "s|[[:space:]]*||")"
|
||||
if [[ -z "${tag}" ]]; then
|
||||
echo "No tag found for: ${{ needs.get-container.outputs.path }}"
|
||||
exit 1
|
||||
else
|
||||
echo "::set-output name=tag::${tag}"
|
||||
fi
|
||||
- uses: vmware-labs/vmware-image-builder-action@main
|
||||
name: Verify
|
||||
with:
|
||||
|
|
|
|||
Loading…
Reference in New Issue