Skip to content

Commit

Permalink
ci: clean up old runs on the server (#357)
Browse files Browse the repository at this point in the history
* ci: clean up old logs on the server

* ci: start the interop run after the cleanup job
  • Loading branch information
marten-seemann authored Feb 29, 2024
1 parent 149e197 commit cc58623
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: cleanup
on:
schedule:
- cron: "0 */8 * * *" # every 8h

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete old logs on the server
uses: appleboy/ssh-action@8f949198563a347a01c65ffc60399aef2b59d4ab # v1.0.1
with:
host: interop.seemann.io
username: ${{ secrets.INTEROP_SEEMANN_IO_USER }}
key: ${{ secrets.INTEROP_SEEMANN_IO_SSH_KEY }}
script: |
delete_oldest_folder() {
OLDEST_DIR=$(find "${{ vars.LOG_DIR }}" -mindepth 1 -maxdepth 1 -type d -printf '%T+ %p\n' | sort | head -n 1 | cut -d" " -f2-)
if [[ -n "$OLDEST_DIR" ]]; then
echo "Deleting oldest directory: $OLDEST_DIR"
rm -rf "$OLDEST_DIR"
fi
}
# Loop until enough space is available or no directories left to delete
while true; do
AVAILABLE_SPACE_GB=$(df -BG "${{ vars.LOG_DIR }}" | tail -n 1 | awk '{print $4}' | sed 's/G//')
echo "Available Space: $AVAILABLE_SPACE_GB GB"
if [[ "$AVAILABLE_SPACE_GB" -lt 50 ]]; then
echo "Less than 50 GB available. Trying to clean up..."
delete_oldest_folder
else
echo "Enough space available."
break
fi
done
TEMP_FILE=$(mktemp)
find "${{ vars.LOG_DIR }}" -mindepth 1 -maxdepth 1 -type d -not -name 'lost+found' -exec basename {} \; | sort > "$TEMP_FILE"
jq -R -s 'split("\n") | map(select(. != ""))' "$TEMP_FILE" > "${{ vars.LOG_DIR }}/logs.json"
rm -f "$TEMP_FILE"
10 changes: 6 additions & 4 deletions .github/workflows/interop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: interop
on:
schedule:
- cron: "0 */8 * * *" # every 8h
# Every 8h, at 15 minutes past the hour
# This makes sure that the cleanup cron job can run first.
- cron: "15 */8 * * *"

# Cache key for caching the Wireshark build.
# To trigger a rebuild of Wireshark increment this value.
Expand Down Expand Up @@ -229,7 +231,7 @@ jobs:
with:
switches: -avzr --relative
path: logs/./${{ matrix.server }}_${{ matrix.client }}/
remote_path: /mnt/logs/${{ needs.config.outputs.logname }}
remote_path: ${{ vars.LOG_DIR }}/${{ needs.config.outputs.logname }}
remote_host: interop.seemann.io
remote_user: ${{ secrets.INTEROP_SEEMANN_IO_USER }}
remote_key: ${{ secrets.INTEROP_SEEMANN_IO_SSH_KEY }}
Expand Down Expand Up @@ -276,7 +278,7 @@ jobs:
with:
switches: -avzr
path: result.json
remote_path: /mnt/logs/${{ needs.config.outputs.logname }}/
remote_path: ${{ vars.LOG_DIR }}/${{ needs.config.outputs.logname }}/
remote_host: interop.seemann.io
remote_user: ${{ secrets.INTEROP_SEEMANN_IO_USER }}
remote_key: ${{ secrets.INTEROP_SEEMANN_IO_SSH_KEY }}
Expand All @@ -289,7 +291,7 @@ jobs:
key: ${{ secrets.INTEROP_SEEMANN_IO_SSH_KEY }}
envs: LOGNAME
script: |
cd /mnt/logs
cd ${{ vars.LOG_DIR }}
jq '. += [ "${{ needs.config.outputs.logname }}" ]' logs.json | sponge logs.json
rm latest || true
ln -s $LOGNAME latest

0 comments on commit cc58623

Please sign in to comment.