Skip to content

Commit

Permalink
Also delete docker artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
loicalbertin committed Apr 26, 2021
1 parent 4bf0d06 commit 91684f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions build/gh-action-cleanup-artifactory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ set -euo pipefail

comp_date=$(date --date="${FROM_DATE:=14 days ago}" +"%Y-%m-%dT%H:%M:%S.000Z")

local_dist_path="yorc-bin-dev-local/ystia/yorc/dist"
local_bin_dist_path="yorc-bin-dev-local/ystia/yorc/dist"
local_docker_path="yorc-docker-dev-local/ystia/yorc"

all_paths=$(jfrog rt s "${local_dist_path}/*/yorc-*.tgz" --limit 0 | jq -r ".[]| [.modified, .path] | @tsv" | sed -e "s@${local_dist_path}/\(.*\)/yorc-.*\.tgz@\1@g" | sort)
bin_paths=$(jfrog rt s "${local_bin_dist_path}/*/yorc-*.tgz" --limit 0 | jq -r ".[]| [.modified, .path] | @tsv" | sed -e "s@\(${local_bin_dist_path}/\(.*\)\)/yorc-.*\.tgz@\2\t\1@g")
docker_paths=$(jfrog rt s "${local_docker_path}/PR-*/manifest.json" --limit 0 | jq -r ".[]| [.modified, .path] | @tsv" | sed -e "s@\(${local_docker_path}/\(PR-.*\)\)/manifest.json@\2\t\1@g")

all_paths=$(echo -e "${bin_paths}\n${docker_paths}" | sort)

function get_pr_state() {
gh pr view "${1}" --json state | jq -r ".state"
Expand All @@ -18,7 +22,7 @@ function does_branch_exit() {
}

function delete_artifactory_path() {
jfrog rt del --quiet "${local_dist_path}/${1}" || echo "failed to delete ${local_dist_path}/${1}"
jfrog rt del --quiet "${1}" || echo "failed to delete ${1}"
}

echo "${all_paths}" | while read line ; do
Expand All @@ -27,13 +31,14 @@ echo "${all_paths}" | while read line ; do
continue
fi
ref=$(echo "${line}" | awk -F '\t' '{print $2}')
artifact_path=$(echo "${line}" | awk -F '\t' '{print $3}')
if [[ "${ref}" == PR-* ]] ; then
if [[ "$(get_pr_state "${ref##*PR-}")" != "OPEN" ]] ; then
delete_artifactory_path "${ref}"
delete_artifactory_path "${artifact_path}"
fi
else
if ! does_branch_exit "${ref}" ; then
delete_artifactory_path "${ref}"
delete_artifactory_path "${artifact_path}"
fi
fi
done

0 comments on commit 91684f0

Please sign in to comment.