0
0
mirror of https://github.com/sp-tarkov/build.git synced 2025-02-13 01:50:46 -05:00

Well, that didn't work. Let's try a batch file.

This commit is contained in:
Refringe 2024-03-09 14:38:14 -05:00
parent 25777ec7e4
commit df7d6f6c4d
Signed by: Refringe
GPG Key ID: 7715B85B4A6306ED

View File

@ -339,25 +339,34 @@ jobs:
run: | run: |
cd /workspace/refringe/Build/ cd /workspace/refringe/Build/
echo "${{ secrets.SFTP_HOST_KEY }}" > known_hosts echo "${{ secrets.SFTP_HOST_KEY }}" > known_hosts
lftp -u ${{ secrets.SFTP_USERNAME }},${{ secrets.SFTP_PASSWORD }} sftp://${{ secrets.SFTP_HOST }}:${{ secrets.SFTP_PORT }} << EOF
set net:timeout 20 # Generate a batch file for sftp commands
set net:connect-timeout 20 echo "cd /public" > sftp_batch.txt
set sftp:connect-program "ssh -a -x -o ConnectTimeout=20 -o UserKnownHostsFile=$(pwd)/known_hosts -o StrictHostKeyChecking=yes"
cd /public # List files in the directory using sftp
cls -1 | grep -E 'SPT-(DEBUG|BLEEDING).*\.7z$' | awk '{ FILE_LIST=$(sshpass -p "${{ secrets.SFTP_PASSWORD }}" sftp -oBatchMode=no -oPort=${{ secrets.SFTP_PORT }} -oUserKnownHostsFile=known_hosts -oStrictHostKeyChecking=yes ${{ secrets.SFTP_USERNAME }}@${{ secrets.SFTP_HOST }}:/public <<< "ls")
match(\$0, /([0-9]{8})\.7z$/, arr);
"date +%s" | getline current_date; # Process each file to determine if it's older than 30 days
file_date=substr(arr[1],1,4) "-" substr(arr[1],5,2) "-" substr(arr[1],7,2); echo "$FILE_LIST" | grep -E 'SPT-(DEBUG|BLEEDING).*\.7z$' | while read -r filename; do
"date -d" file_date " +%s" | getline file_date_sec; # Extract date from filename
limit_date=current_date - (30 * 24 * 3600); if [[ "$filename" =~ ([0-9]{8})\.7z$ ]]; then
if (file_date_sec < limit_date) { file_date="${BASH_REMATCH[1]}"
print \$0; file_date_fmt=$(date -d "${file_date:0:4}-${file_date:4:2}-${file_date:6:2}" +%s)
}
}' | while read filename; do # Get current date minus 30 days
echo "Deleting old file: \$filename" current_date=$(date +%s)
rm "\$filename" limit_date=$(date -d "@$((current_date - 30 * 24 * 3600))" +%s)
done
EOF # Compare dates and write the delete command to the batch file
if [[ "$file_date_fmt" -lt "$limit_date" ]]; then
echo "Deleting old file: $filename"
echo "rm \"/public/$filename\"" >> sftp_batch.txt
fi
fi
done
# Execute batch file with sftp
sshpass -p "${{ secrets.SFTP_PASSWORD }}" sftp -oBatchMode=no -b sftp_batch.txt -oPort=${{ secrets.SFTP_PORT }} -oUserKnownHostsFile=known_hosts -oStrictHostKeyChecking=yes ${{ secrets.SFTP_USERNAME }}@${{ secrets.SFTP_HOST }}
shell: bash shell: bash
- name: Upload Release to Mega - name: Upload Release to Mega