mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* ci: add Datadog metrics to clean-src-cache job Report free space (before/after cleanup), space freed, and total space for both cross-instance-cache and win-cache volumes to Datadog, matching the pattern used in the macOS disk cleanup workflow. https://claude.ai/code/session_013bpDsZLrFDpWMiARNFH4z9 * ci: use awk instead of bc, add workflow_dispatch trigger - Replace bc with awk for KB-to-GB conversion since bc may not be available in the container image - Add workflow_dispatch trigger for manual testing https://claude.ai/code/session_013bpDsZLrFDpWMiARNFH4z9 * ci: remove workflow_dispatch, handled in another PR https://claude.ai/code/session_013bpDsZLrFDpWMiARNFH4z9 * ci: move DD_API_KEY to job-level env for if-condition The step-level env is not available when GitHub evaluates the step's if expression, so env.DD_API_KEY was always empty. Move it to job-level env so the conditional works correctly. https://claude.ai/code/session_013bpDsZLrFDpWMiARNFH4z9 --------- Co-authored-by: Claude <noreply@anthropic.com>
156 lines
6.5 KiB
YAML
156 lines
6.5 KiB
YAML
name: Clean Source Cache
|
|
|
|
# Description:
|
|
# This workflow cleans up the source cache on the cross-instance cache volume
|
|
# to free up space. It runs daily at midnight and clears files older than 15 days.
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 0 * * *"
|
|
workflow_dispatch:
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
clean-src-cache:
|
|
if: github.repository == 'electron/electron'
|
|
runs-on: electron-arc-centralus-linux-amd64-32core
|
|
permissions:
|
|
contents: read
|
|
env:
|
|
DD_API_KEY: ${{ secrets.DD_API_KEY }}
|
|
container:
|
|
image: ghcr.io/electron/build:bc2f48b2415a670de18d13605b1cf0eb5fdbaae1
|
|
options: --user root
|
|
volumes:
|
|
- /mnt/cross-instance-cache:/mnt/cross-instance-cache
|
|
- /mnt/win-cache:/mnt/win-cache
|
|
steps:
|
|
- name: Get Disk Space Before Cleanup
|
|
id: disk-before
|
|
shell: bash
|
|
run: |
|
|
echo "Disk space before cleanup:"
|
|
df -h /mnt/cross-instance-cache
|
|
df -h /mnt/win-cache
|
|
CROSS_FREE_BEFORE=$(df -k /mnt/cross-instance-cache | tail -1 | awk '{print $4}')
|
|
CROSS_TOTAL=$(df -k /mnt/cross-instance-cache | tail -1 | awk '{print $2}')
|
|
WIN_FREE_BEFORE=$(df -k /mnt/win-cache | tail -1 | awk '{print $4}')
|
|
WIN_TOTAL=$(df -k /mnt/win-cache | tail -1 | awk '{print $2}')
|
|
echo "cross_free_kb=$CROSS_FREE_BEFORE" >> $GITHUB_OUTPUT
|
|
echo "cross_total_kb=$CROSS_TOTAL" >> $GITHUB_OUTPUT
|
|
echo "win_free_kb=$WIN_FREE_BEFORE" >> $GITHUB_OUTPUT
|
|
echo "win_total_kb=$WIN_TOTAL" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cleanup Source Cache
|
|
shell: bash
|
|
run: |
|
|
find /mnt/cross-instance-cache -type f -mtime +15 -delete
|
|
find /mnt/win-cache -type f -mtime +15 -delete
|
|
|
|
- name: Get Disk Space After Cleanup
|
|
id: disk-after
|
|
shell: bash
|
|
run: |
|
|
echo "Disk space after cleanup:"
|
|
df -h /mnt/cross-instance-cache
|
|
df -h /mnt/win-cache
|
|
CROSS_FREE_AFTER=$(df -k /mnt/cross-instance-cache | tail -1 | awk '{print $4}')
|
|
WIN_FREE_AFTER=$(df -k /mnt/win-cache | tail -1 | awk '{print $4}')
|
|
echo "cross_free_kb=$CROSS_FREE_AFTER" >> $GITHUB_OUTPUT
|
|
echo "win_free_kb=$WIN_FREE_AFTER" >> $GITHUB_OUTPUT
|
|
|
|
- name: Log Disk Space to Datadog
|
|
if: ${{ env.DD_API_KEY != '' }}
|
|
shell: bash
|
|
env:
|
|
CROSS_FREE_BEFORE: ${{ steps.disk-before.outputs.cross_free_kb }}
|
|
CROSS_FREE_AFTER: ${{ steps.disk-after.outputs.cross_free_kb }}
|
|
CROSS_TOTAL: ${{ steps.disk-before.outputs.cross_total_kb }}
|
|
WIN_FREE_BEFORE: ${{ steps.disk-before.outputs.win_free_kb }}
|
|
WIN_FREE_AFTER: ${{ steps.disk-after.outputs.win_free_kb }}
|
|
WIN_TOTAL: ${{ steps.disk-before.outputs.win_total_kb }}
|
|
run: |
|
|
TIMESTAMP=$(date +%s)
|
|
|
|
CROSS_FREE_BEFORE_GB=$(awk "BEGIN {printf \"%.2f\", $CROSS_FREE_BEFORE / 1024 / 1024}")
|
|
CROSS_FREE_AFTER_GB=$(awk "BEGIN {printf \"%.2f\", $CROSS_FREE_AFTER / 1024 / 1024}")
|
|
CROSS_FREED_GB=$(awk "BEGIN {printf \"%.2f\", ($CROSS_FREE_AFTER - $CROSS_FREE_BEFORE) / 1024 / 1024}")
|
|
CROSS_TOTAL_GB=$(awk "BEGIN {printf \"%.2f\", $CROSS_TOTAL / 1024 / 1024}")
|
|
|
|
WIN_FREE_BEFORE_GB=$(awk "BEGIN {printf \"%.2f\", $WIN_FREE_BEFORE / 1024 / 1024}")
|
|
WIN_FREE_AFTER_GB=$(awk "BEGIN {printf \"%.2f\", $WIN_FREE_AFTER / 1024 / 1024}")
|
|
WIN_FREED_GB=$(awk "BEGIN {printf \"%.2f\", ($WIN_FREE_AFTER - $WIN_FREE_BEFORE) / 1024 / 1024}")
|
|
WIN_TOTAL_GB=$(awk "BEGIN {printf \"%.2f\", $WIN_TOTAL / 1024 / 1024}")
|
|
|
|
echo "cross-instance-cache: free before=${CROSS_FREE_BEFORE_GB}GB, after=${CROSS_FREE_AFTER_GB}GB, freed=${CROSS_FREED_GB}GB, total=${CROSS_TOTAL_GB}GB"
|
|
echo "win-cache: free before=${WIN_FREE_BEFORE_GB}GB, after=${WIN_FREE_AFTER_GB}GB, freed=${WIN_FREED_GB}GB, total=${WIN_TOTAL_GB}GB"
|
|
|
|
curl -s -X POST "https://api.datadoghq.com/api/v2/series" \
|
|
-H "Content-Type: application/json" \
|
|
-H "DD-API-KEY: ${DD_API_KEY}" \
|
|
-d @- << EOF
|
|
{
|
|
"series": [
|
|
{
|
|
"metric": "electron.src_cache.disk.free_space_before_cleanup_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${CROSS_FREE_BEFORE_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:cross-instance-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.free_space_after_cleanup_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${CROSS_FREE_AFTER_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:cross-instance-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.space_freed_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${CROSS_FREED_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:cross-instance-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.total_space_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${CROSS_TOTAL_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:cross-instance-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.free_space_before_cleanup_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${WIN_FREE_BEFORE_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:win-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.free_space_after_cleanup_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${WIN_FREE_AFTER_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:win-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.space_freed_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${WIN_FREED_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:win-cache", "platform:linux"]
|
|
},
|
|
{
|
|
"metric": "electron.src_cache.disk.total_space_gb",
|
|
"points": [{"timestamp": ${TIMESTAMP}, "value": ${WIN_TOTAL_GB}}],
|
|
"type": 3,
|
|
"unit": "gigabyte",
|
|
"tags": ["volume:win-cache", "platform:linux"]
|
|
}
|
|
]
|
|
}
|
|
EOF
|
|
|
|
echo "Disk space metrics logged to Datadog"
|