Skip to content
Permalink
Browse files

Add script to delete old wmf builds

  • Loading branch information
FlorianSW committed Dec 23, 2019
1 parent 787cf01 commit 871440d849428d909e569f7911d3a2a8fa2d9e53
@@ -1,3 +1,4 @@
/vendor/
.idea
ci/credentials.yml
operations-update-tools.iml
ci/credentials.yml
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

while [[ $(ls $1 | wc -l) -gt 4 ]]
do
oldestFile=$(find $1 -type f -printf '%T+ %p\n' | sort | head -n 1 | awk '{print $NF}')
rm $oldestFile
done
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

./tests/less_than_four_files.sh
./tests/delete_oldest_file.sh
./tests/delete_until_four_left.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

. ./tests/helpers.sh

trap "rm -rf data" EXIT

function setupTestdata() {
mkdir data
touch -t 201805121200 data/file1
touch data/file2
touch data/file3
touch data/file4
touch data/file5
}

printf "Should delete latest file if more than 4 builds..."
setupTestdata

./delete_obsolete_wmf_builds.sh "data/"

expectFourRemainingFiles
expectFileDeleted "data/file1"
printf "PASS\n"
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

. ./tests/helpers.sh

trap "rm -rf data" EXIT

printf "Should delete latest files until only 4 remains..."
mkdir data
touch -t 201805121200 data/file1
touch -t 201805121200 data/file2
touch -t 201805121200 data/file3
touch data/file4
touch data/file5
touch data/file6
touch data/file7

./delete_obsolete_wmf_builds.sh "data/"

expectFourRemainingFiles
expectFileDeleted "data/file1"
expectFileDeleted "data/file2"
expectFileDeleted "data/file3"
printf "PASS\n"
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

function expectFileDeleted() {
if [ -f "$1" ]; then
printf "FAIL\nExpected file $1 to be deleted"
exit 1
fi
}

function expectFourRemainingFiles() {
if [ $(ls data/ | wc -l) != 4 ]; then
printf "FAIL\nExpected one file to be deleted"
exit 1
fi
}
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

trap "rm -rf data" EXIT

printf "Should not delete any file if less then 4 builds..."
mkdir data
touch data/file1
touch data/file2

./delete_obsolete_wmf_builds.sh "data/"

if [ $(ls data/ | wc -l) != 2 ]; then
printf "FAIL\nFiles in data should not be deleted"
exit 1
else
printf "PASS\n"
fi

0 comments on commit 871440d

Please sign in to comment.
You can’t perform that action at this time.