build-release #19
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: "Cache Monitor" | |
| permissions: | |
| issues: write | |
| on: | |
| repository_dispatch: | |
| workflow_dispatch: | |
| jobs: | |
| monitor-cache: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Install bc for calculations | |
| run: sudo apt-get update && sudo apt-get install -y bc | |
| - name: Monitor cache usage | |
| run: | | |
| # 获取缓存使用情况 | |
| response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/cache/usage") | |
| echo "Cache usage response: $response" | |
| # 解析缓存大小 (单位: bytes) | |
| cache_size_bytes=$(echo "$response" | jq -r '.active_caches_size_in_bytes // 0') | |
| # 转换为 GB | |
| cache_size_gb=$(echo "scale=2; $cache_size_bytes / 1024 / 1024 / 1024" | bc) | |
| echo "Current cache size: ${cache_size_gb} GB" | |
| # 检查是否超过 7GB | |
| threshold_exceeded=$(echo "$cache_size_gb > 7" | bc) | |
| echo "Threshold exceeded: $threshold_exceeded" | |
| if [ "$threshold_exceeded" -eq 1 ]; then | |
| echo "Cache size exceeds 7GB threshold" | |
| # 检查 issue #6 是否已打开 | |
| issue_state=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/6" | jq -r '.state') | |
| echo "Current issue #6 state: $issue_state" | |
| if [ "$issue_state" = "closed" ]; then | |
| # 重新打开 issue | |
| echo "Reopening issue #6" | |
| curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/6" \ | |
| -d '{"state": "open"}' | |
| fi | |
| # 添加评论到 issue #6 | |
| echo "Adding comment to issue #6" | |
| current_time=$(date -u +"%Y-%m-%d %H:%M:%S UTC") | |
| curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/6/comments" \ | |
| -d "{\"body\": \"⚠️ **Cache Usage Alert** - $current_time\\n\\n📊 Current cache usage: **${cache_size_gb} GB**\\n🚨 This exceeds the 7GB threshold.\\n\\n**Recommended actions:**\\n- Review and clean up unused cache entries\\n- Consider optimizing build workflows to reduce cache usage\\n- Monitor cache usage more frequently\\n\\n---\\n*This alert was automatically generated by the cache monitoring workflow.*\"}" | |
| else | |
| echo "Cache size is within acceptable limits" | |
| # 检查 issue #6 是否打开,如果是则关闭它 | |
| issue_state=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/6" | jq -r '.state') | |
| echo "Current issue #6 state: $issue_state" | |
| if [ "$issue_state" = "open" ]; then | |
| echo "Closing issue #6 as cache usage is now acceptable" | |
| # 添加关闭评论 | |
| current_time=$(date -u +"%Y-%m-%d %H:%M:%S UTC") | |
| curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/6/comments" \ | |
| -d "{\"body\": \"✅ **Cache Usage Normal** - $current_time\\n\\n📊 Current cache usage: **${cache_size_gb} GB**\\n✅ Cache usage is now within acceptable limits (< 7GB).\\n\\nClosing this issue automatically.\\n\\n---\\n*This update was automatically generated by the cache monitoring workflow.*\"}" | |
| # 关闭 issue | |
| curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/6" \ | |
| -d '{"state": "closed"}' | |
| fi | |
| fi |