blob: f0db5ceb17c5fea1ecd3357929033ed335a75f89 [file] [log] [blame]
Tomás González6fdcce62025-01-28 10:02:09 +00001- job:
2 name: tf-a-cleanup-tfa-next
3 description: Cleanup https://downloads.trustedfirmware.org/tf-a/next/artifacts/
4 node: build-amd64-private
5 concurrent: false
6 disabled: false
7 project-type: freestyle
8 sandbox: true
9 properties:
Chris Kay675db4f2025-06-24 14:14:34 +010010 - build-discarder:
11 days-to-keep: 90
12 num-to-keep: 15
Tomás González6fdcce62025-01-28 10:02:09 +000013 triggers:
Chris Kay675db4f2025-06-24 14:14:34 +010014 - timed: 0 11 * * 5 # Triggered every Friday at 11 am (GMT)
Tomás González6fdcce62025-01-28 10:02:09 +000015 builders:
Chris Kay675db4f2025-06-24 14:14:34 +010016 - shell: |
17 #!/bin/bash
18 set -ex
19 if ! type aws
20 then
21 sudo apt-get -y -qq update
22 sudo apt-get -y -qq install --no-install-recommends unzip
23 curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
24 unzip -q awscliv2.zip
25 sudo ./aws/install
26 fi
Tomás González6fdcce62025-01-28 10:02:09 +000027
Chris Kay675db4f2025-06-24 14:14:34 +010028 # All tfa-next related files should be under "artifacts" on the S3 bucket.
29 ROOT=s3://${TUXPUB_S3_BUCKET}/
30 for OBJECT in $(aws s3 ls $ROOT --recursive | grep artifacts | awk '{print $4}');
31 do
32 echo "Current object: ${ROOT}${OBJECT}"
33 # Expected URL format: tf-a/next/artifacts/YYYY-MM-DD-HHMMSS/<bin_mode>/<file_name>
34 # Take the YYYY-MM-DD information from the URL for each object
35 dir_date=$(echo $OBJECT | sed 's+tf-a/next/artifacts/++' | sed 's+/.*++' | grep -E "(([0-9]+-){3,}[0-9]+)" | sed -E 's/-[0-9]+$//')
36 if [ $dir_date ]; then
37 # Calculate how old the file is (in days)
38 diff_in_days=$(( ( $(date +%s) - $(date -d "$dir_date" +%s) ) / $((60*60*24)) ))
39 # Remove the file if it's older than 3 days.
40 if (( diff_in_days > 3 )); then
41 echo "Removing object: ${ROOT}${OBJECT}"
42 aws s3 rm ${ROOT}${OBJECT}
43 fi
44 fi
45 done