Skip to content

Commit

Permalink
generate logs.json
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 7, 2023
1 parent 3b84b37 commit 63e2bab
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/interop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ jobs:
permissions:
id-token: write
contents: read
env:
BUCKET: "quic-interop-runner"
RETENTION_DAYS: "3"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -24,19 +21,27 @@ jobs:
env:
B2_APPLICATION_KEY_ID: ${{ secrets.BACKBLAZE_KEY_ID }}
B2_APPLICATION_KEY: ${{ secrets.BACKBLAZE_APPLICATION_KEY }}
- name: upload a file
- name: remove old logs
run: |
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)")
threshold_time=$((($(date +%s) * 1000) - (${{ vars.LOG_RETENTION_DAYS }} * 24 * 60 * 60 * 1000)))
old_files=$(b2 ls --json ${{ vars.BACKBLAZE_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
# skip files, we only care about directories
if [[ "$dir_name" != "." ]]; then
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://${{ vars.BACKBLAZE_BUCKET }}/"$dir_name"
rmdir empty
fi
done
- name: generate logs.json and upload it
run: |
b2 ls --json quic-interop-runner | jq '[sort_by(.uploadTimestamp) | .[] | select(.fileName | contains("/")) | .fileName | split("/")[0] | select(. != null)]' > logs.json
b2 upload-file ${{ vars.BACKBLAZE_BUCKET }} logs.json logs.json

0 comments on commit 63e2bab

Please sign in to comment.