Skip to content
Snippets Groups Projects
Commit d6ae748e authored by linsui's avatar linsui
Browse files

tool/keep-latest.sh: only remove exist versions

parent fb255505
No related branches found
No related tags found
No related merge requests found
......@@ -24,13 +24,14 @@ for file in $changed_files; do
keep_num=$(sed -z -E -n 's/.*VercodeOperation:\n(( -[^\n]*\n)+).*/\1/p' "$file" | wc -l)
[[ $keep_num == 0 ]] && keep_num=1
removed_versions=$(grep "\- versionCode: " <<< "$diff" | sed -E -n "s/.*versionCode: ([0-9]+)/\1/p" | jq --slurp '.')
new_versions=$(grep "+ versionCode: " <<< "$diff" | sed -E -n "s/.*versionCode: ([0-9]+)/\1/p" | jq --slurp '.')
missing_versions=$(jq -r ".\"$appid\" // []" <<< "$missing_builds")
failed_versions=$(jq -r "map(select(.[0] == \"$appid\") | .[1])" <<< "$failed_builds")
success_versions=$(jq -r "map(select(.[0] == \"$appid\") | .[1])" <<< "$success_builds")
all_versions=$(sed -E -n "s/.*versionCode: ([0-9]+)/\1/p" $file | jq --slurp '.')
remove_versions=$(jq --slurp -r ".[0] + .[2] + .[3] - .[1] - .[4] | sort | unique | .[:-$keep_num][]" <(printf "$new_versions") <(printf "$removed_versions") <(printf "$missing_versions") <(printf "$failed_versions") <(printf "$success_versions"))
remove_versions=$(jq --slurp -r ".[4] - (.[4] - (.[0] + .[1] + .[2] - .[3])) | sort | unique | .[:-$keep_num][]" \
<(printf "$new_versions") <(printf "$missing_versions") <(printf "$failed_versions") <(printf "$success_versions") <(printf "$all_versions"))
if [[ -n $remove_versions ]]; then
echo "Cleaning $appid: ${remove_versions//$'\n'/ }"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment