0
0
mirror of https://github.com/sp-tarkov/build.git synced 2025-02-12 14:50:44 -05:00

Refactors 'Clean Old Mega Releases' Step

Updates the mega clean-up step to use the mega-find command to do the brunt of the work.
This commit is contained in:
Refringe 2024-11-22 09:44:52 -05:00
parent 3e29c137af
commit 816415a8e4
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k

View File

@ -584,6 +584,7 @@ jobs:
id: upload-mega
run: |
mega-https on
mega-exec psa --discard
mega-login "${{ secrets.MEGA_EMAIL }}" "${{ secrets.MEGA_PASSWORD }}"
mega-put -c "/workspace/SPT/Build/${{ steps.generate-filename.outputs.build_name }}" "/spt-release/${{ steps.generate-filename.outputs.build_name }}"
@ -600,48 +601,29 @@ jobs:
run: |
mega-https on
mega-login "${{ secrets.MEGA_EMAIL }}" "${{ secrets.MEGA_PASSWORD }}"
mega-exec psa --discard
echo "Finding files matching the pattern:"
mega-find /spt-release --pattern 'SPT-*.7z' > matching_files.txt
cat matching_files.txt
echo "Finding old, non-release type files..."
echo "Filter files matching specific build types:"
grep -E 'SPT-(NIGHTLY|DEBUG|BLEEDING|BLEEDINGMODS).*\.7z$' matching_files.txt > filtered_files.txt
cat filtered_files.txt
mega-find /spt-release \
--type=f \
--pattern=SPT-(NIGHTLY|DEBUG|BLEEDING|BLEEDINGMODS).*\.7z \
--use-pcre \
--mtime=+14d > old_files.txt
# Process each filepath
while read -r filepath; do
filename=$(basename "$filepath")
echo "Processing filename: $filename"
# Check if any old files were found
if [ -s old_files.txt ]; then
echo "Old files found:"
cat old_files.txt
# Extract date from filename
if [[ "$filename" =~ ([0-9]{8})\.7z$ ]]; then
file_date="${BASH_REMATCH[1]}"
echo "Extracted date: $file_date"
file_date_fmt=$(date -d "${file_date:0:4}-${file_date:4:2}-${file_date:6:2}" +%s)
echo "File date timestamp: $file_date_fmt"
# Get current date minus 14 days
current_date=$(date +%s)
limit_date=$(date -d "@$((current_date - 14 * 24 * 3600))" +%s)
echo "Current date timestamp: $current_date"
echo "Limit date timestamp: $limit_date"
# Compare dates and delete old files
if [[ "$file_date_fmt" -lt "$limit_date" ]]; then
echo "Deleting old file: $filepath"
mega-rm "$filepath"
else
echo "File is not older than 14 days, keeping: $filepath"
fi
else
echo "Filename does not match date pattern: $filename"
fi
done < filtered_files.txt
# Delete each file listed in old_files.txt
while read -r filepath; do
echo "Deleting old file: $filepath"
mega-rm "$filepath"
done < old_files.txt
else
echo "No old files found."
fi
# Remove old file versions to save space.
mega-deleteversions -f /spt-release/*