Skip to content

Instantly share code, notes, and snippets.

@jeffaburt
Created June 5, 2020 21:10
Show Gist options
  • Save jeffaburt/8b7d260c7650d1cc7afe54da12824788 to your computer and use it in GitHub Desktop.
Save jeffaburt/8b7d260c7650d1cc7afe54da12824788 to your computer and use it in GitHub Desktop.
Remove stale AppCenter builds from the past (currently set to builds older than 15 days old)
#!/usr/bin/env sh
npm list -g appcenter-cli > /dev/null 2>&1
if [[ $? -ne 0 ]]
then
echo "Installing appcenter-cli..."
npm install -g appcenter-cli
fi
set -e
if [[ -z "${APPCENTER_ACCESS_TOKEN}" ]]; then
echo "ERROR: APPCENTER_ACCESS_TOKEN was not found. Run appcenter login and add the token to your bash profile."
exit 1
fi
app=StockX/StockX-iOS
IFS=$'\n'
lines=(`appcenter distribute releases list --app $app`)
now=`date +%s`
seconds_in_one_day=86400
days_to_keep=15
appcenter_date_format="%a %b %d %Y %T %Z%z"
echo "Searching for $app releases to prune..."
i=0
for (( i=0; i<${#lines[@]}; i+= 5 )) ; do
id=`echo "${lines[$i]}" | cut -d ':' -f2 | xargs`
extracted_date=`echo "${lines[$i + 3]}" | cut -d ':' -f2- | cut -d '(' -f1 | xargs`
upload_date_seconds=`date -j -f "$appcenter_date_format" $extracted_date +%s`
upload_date_pretty=`date -j -f "$appcenter_date_format" $extracted_date +%D`
if (( ($now - $upload_date_seconds) > ($days_to_keep * $seconds_in_one_day) ))
then
echo "Pruning $id from $upload_date_pretty"
appcenter distribute releases delete -r $id --app $app --quiet
else
echo "Skipping $id since it was uploaded within the past $days_to_keep days ($upload_date_pretty)"
fi
done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment