blob: f0db5ceb17c5fea1ecd3357929033ed335a75f89 [file] [log] [blame]
- job:
name: tf-a-cleanup-tfa-next
description: Cleanup https://downloads.trustedfirmware.org/tf-a/next/artifacts/
node: build-amd64-private
concurrent: false
disabled: false
project-type: freestyle
sandbox: true
properties:
- build-discarder:
days-to-keep: 90
num-to-keep: 15
triggers:
- timed: 0 11 * * 5 # Triggered every Friday at 11 am (GMT)
builders:
- shell: |
#!/bin/bash
set -ex
if ! type aws
then
sudo apt-get -y -qq update
sudo apt-get -y -qq install --no-install-recommends unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install
fi
# All tfa-next related files should be under "artifacts" on the S3 bucket.
ROOT=s3://${TUXPUB_S3_BUCKET}/
for OBJECT in $(aws s3 ls $ROOT --recursive | grep artifacts | awk '{print $4}');
do
echo "Current object: ${ROOT}${OBJECT}"
# Expected URL format: tf-a/next/artifacts/YYYY-MM-DD-HHMMSS/<bin_mode>/<file_name>
# Take the YYYY-MM-DD information from the URL for each object
dir_date=$(echo $OBJECT | sed 's+tf-a/next/artifacts/++' | sed 's+/.*++' | grep -E "(([0-9]+-){3,}[0-9]+)" | sed -E 's/-[0-9]+$//')
if [ $dir_date ]; then
# Calculate how old the file is (in days)
diff_in_days=$(( ( $(date +%s) - $(date -d "$dir_date" +%s) ) / $((60*60*24)) ))
# Remove the file if it's older than 3 days.
if (( diff_in_days > 3 )); then
echo "Removing object: ${ROOT}${OBJECT}"
aws s3 rm ${ROOT}${OBJECT}
fi
fi
done