Consider adding a TTL to autoclose gates
Our CI pipeline builds feature branches using autoclose gates. It is expected that builds on feature branches fail from time to time and may be corrected by developers. This leaves autoclose gates open and "stranded".
When processing autoclose items, the gate resource should probably perform a cleanup of gates after a configurable TTL. Thinking of it, there might be value to having a TTL for gates in general (i.e. reduced git checkout size and less load on the filesystem). This might be best delegated to a "sidecar" task that runs on the gate-repo
I've experimented with a script like this to clean up gate files older than 7 days
#!/bin/bash
set -o errexit
set -o errtrace
set -o pipefail
set -o nounset
function cleanup()
{
stamp=$(date +%s)
day=$((60*60*24))
old=$(($stamp - 7*$day))
echo "cleaning any file commited older than $old"
while read FILE; do
modified=$(git log --pretty="%ad" --date=unix -1 -- "$FILE")
if [ $modified -lt $old ]; then
echo "$FILE $modified is old, cleaning"
rm "$FILE"
else
echo "$FILE $modified is not old"
fi;
done < <( git ls-files )
}
cleanup
When commiting to the gate repository, use something like git commit -am "[ci skip] cleanup old gates" so that the commit is not picked up accidentally as a valid gate-modifying commit. Otherwise you'll see errors like could not determine passed file in version ... in your gate resources.