Check available disk space #269
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check available disk space | |
| on: | |
| schedule: | |
| - cron: "0 17 * * *" # noon EST | |
| workflow_dispatch: | |
| permissions: {} | |
| env: | |
| threshold: 80 | |
| jobs: | |
| CheckDiskSpace: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Load JSON data | |
| run: | | |
| JSON_URL="https://raw.githubusercontent.com/dandi/backup-status/main/data/disk.json" | |
| JSON_CONTENT=$(curl -s $JSON_URL) | |
| echo $JSON_CONTENT | |
| echo "JSON_CONTENT=$JSON_CONTENT" >> $GITHUB_ENV | |
| - name: Check partition 001 | |
| run: | | |
| VALUE=$(echo "$JSON_CONTENT" | jq -r '.data["Size (Used / Total)"][0]' | sed -n 's/.*(\([0-9.]*\)%)$/\1/p') | |
| echo "Value: $VALUE" | |
| if (( $(echo "$VALUE > $threshold" | bc -l) )); then | |
| echo "Disk usage on partition 001 exceeds $threshold%" | |
| exit 1 | |
| fi | |
| - name: Check partition 002 | |
| id: check-002 | |
| run: | | |
| VALUE=$(echo "$JSON_CONTENT" | jq -r '.data["Size (Used / Total)"][1]' | sed -n 's/.*(\([0-9.]*\)%)$/\1/p') | |
| echo "Value: $VALUE" | |
| if (( $(echo "$VALUE > $threshold" | bc -l) )); then | |
| echo "Disk usage on partition 002 exceeds $threshold%" | |
| exit 1 | |
| fi | |
| - name: Success message | |
| if: success() | |
| run: echo "Disk space on Engaging partitions is within acceptable range." | |
| NotifyOnFailure: | |
| runs-on: ubuntu-latest | |
| needs: [ CheckDiskSpace ] | |
| if: ${{ always() && needs.CheckDiskSpace.result == 'failure' }} | |
| steps: | |
| - uses: dawidd6/action-send-mail@v17 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 465 | |
| username: ${{ secrets.MAIL_USERNAME }} | |
| password: ${{ secrets.MAIL_PASSWORD }} | |
| subject: Engaging partition disk space is above $threshold% | |
| to: cody.c.baker.phd@gmail.com # Add more with comma separation (no spaces) | |
| from: Backup Status <backup-status@users.noreply.github.com> | |
| body: "Please check the available disk space and backup protocols for DANDI on Engaging." |