From 3b84b379b0a7c94cc5f2a4573eb7ab210ce86d2e Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 7 Oct 2023 12:48:45 +0700 Subject: [PATCH] delete folders --- .github/workflows/interop.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/interop.yml b/.github/workflows/interop.yml index 3b7b3645..57f37336 100644 --- a/.github/workflows/interop.yml +++ b/.github/workflows/interop.yml @@ -11,8 +11,8 @@ jobs: id-token: write contents: read env: - LOGNAME: ${{ needs.config.outputs.logname }} BUCKET: "quic-interop-runner" + RETENTION_DAYS: "3" steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -26,7 +26,17 @@ jobs: B2_APPLICATION_KEY: ${{ secrets.BACKBLAZE_APPLICATION_KEY }} - name: upload a file run: | - b2 ls --long ${{ env.BUCKET }} - b2 ls --long ${{ env.BUCKET}} | awk -v days=3 -v today=$(date +%s) '$1=="upload" && (today - $3) > days*86400 {print $4}' - + threshold_time=$((($(date +%s) * 1000) - (${{ env.RETENTION_DAYS }} * 24 * 60 * 60 * 1000))) + old_files=$(b2 ls --json ${{ env.BUCKET}} | jq -r ".[] | select(.uploadTimestamp > $threshold_time)") + echo "Deleting files:" + echo $old_files | jq ".fileName" + # Now delete them + echo $old_files | jq -r ".fileName" | while read -r filename; do + dir_name="${filename%%/*}" + echo "Deleting $dir_name" + # see https://github.com/Backblaze/B2_Command_Line_Tool/issues/495#issuecomment-413932585 + mkdir empty # create an empty directory + b2 sync --delete --allowEmptySource empty b2://${{ env.BUCKET }}/"$dir_name" + rmdir empty + done