|
1 | | -# github-rate-limit-check |
2 | | -GitHub Action to get current GitHub rate limit summary. |
| 1 | +# 📊 GitHub API Rate Limit Check |
| 2 | + |
| 3 | +## **Description** |
| 4 | + |
| 5 | +This GitHub Action provides an **automated, real-time check** of your repository’s GitHub API rate limits, giving you **instant visibility** into your API consumption. With detailed reporting and proactive alerts, you can **prevent unexpected disruptions** and **optimize API usage** in your workflows. |
| 6 | + |
| 7 | +Designed for **reliability and clarity**, this composite action: |
| 8 | + |
| 9 | +- Calls the **GitHub Rate Limit API** and extracts real-time usage metrics. |
| 10 | +- Formats and logs the results professionally in both **workflow logs** and **GitHub Step Summary**. |
| 11 | +- **Warns** when remaining API requests fall below a threshold (default: `100`). |
| 12 | +- **Fails fast** when limits are exhausted to avoid unexpected workflow failures. |
| 13 | +- **Handles missing data gracefully**, preventing false alarms from disabled or unavailable API endpoints. |
| 14 | + |
| 15 | +Whether you're running frequent automation, managing API-driven integrations, or monitoring GitHub resources, this action ensures you **stay informed and in control** of your API quota. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 🚀 **Why Use This Action?** |
| 20 | + |
| 21 | +✔️ **Prevents Workflow Failures** – Stops workflows from running when API limits are exceeded. |
| 22 | +✔️ **Proactive Warnings** – Get alerts when remaining requests drop below a safe threshold. |
| 23 | +✔️ **Clear, Professional Reporting** – View a **clean summary table** in GitHub Actions for quick insights. |
| 24 | +✔️ **Safe and Robust Handling** – Avoids errors due to missing or unavailable API data. |
| 25 | +✔️ **Simple Integration** – Plug it into any workflow with minimal setup. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## 📦 **Usage** |
| 30 | + |
| 31 | +### **Workflow Example** |
| 32 | + |
| 33 | +Add the following to your **GitHub Actions workflow** to monitor API usage before running rate-limited tasks. |
| 34 | + |
| 35 | +```yaml |
| 36 | +jobs: |
| 37 | + check-rate-limit: |
| 38 | + name: Check GitHub API Rate Limit |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - name: Checkout Repository |
| 42 | + id: checkout-repo |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Run GitHub API Rate Limit Check |
| 46 | + id: check-rate-limit |
| 47 | + uses: coderrob/github-api-rate-limit-check@v1 |
| 48 | + with: |
| 49 | + github-token: ${{ github.token }} |
| 50 | +``` |
| 51 | +
|
| 52 | +--- |
| 53 | +
|
| 54 | +## 📜 **How It Works** |
| 55 | +
|
| 56 | +1. **Fetches Rate Limit Data** → Calls the `https://api.github.com/rate_limit` endpoint. |
| 57 | +2. **Parses and Processes Data** → Extracts core, GraphQL, and search API quotas. |
| 58 | +3. **Logs Results** → Displays a structured **table** in `GITHUB_STEP_SUMMARY` and console logs. |
| 59 | +4. **Triggers Alerts**: |
| 60 | + - **Warning** (`⚠️`) if remaining API requests **drop below 100**. |
| 61 | + - **Error** (`❌`) if limits are **fully exhausted** (only if that API type is enabled). |
| 62 | +5. **Fails the Workflow (if needed)** → Prevents unintended execution when API access is unavailable. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## 📊 **Example Output** |
| 67 | + |
| 68 | +### **Console Logs** |
| 69 | + |
| 70 | +```bash |
| 71 | +GitHub API Rate Limit Status: |
| 72 | +-------------------------------------------- |
| 73 | + Core API: 85 / 5000 (Resets at 2025-02-20 15:00:00 UTC) |
| 74 | + GraphQL: 4500 / 5000 (Resets at 2025-02-20 15:00:00 UTC) |
| 75 | + Search: 0 / 30 (Resets at 2025-02-20 15:00:00 UTC) |
| 76 | +-------------------------------------------- |
| 77 | +⚠️ GitHub API Rate Limit is low (85 remaining)! |
| 78 | +❌ GitHub Search API Rate Limit has been fully exhausted! |
| 79 | +``` |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +### 📊 **GitHub API Rate Limit Summary** |
| 84 | + |
| 85 | +| API Type | Remaining | Limit | Reset Time (UTC) | |
| 86 | +| ------------ | --------- | ----- | ------------------- | |
| 87 | +| **Core API** | **85** | 5000 | 2025-02-20 15:00:00 | |
| 88 | +| **GraphQL** | **4500** | 5000 | 2025-02-20 15:00:00 | |
| 89 | +| **Search** | **0** | 30 | 2025-02-20 15:00:00 | |
| 90 | + |
| 91 | +⚠️ **Warning:** GitHub API rate limit is low (85 remaining). |
| 92 | +❌ **Error:** GitHub Search API rate limit has been fully exhausted. |
| 93 | + |
| 94 | +⏳ API limits reset periodically. Plan requests accordingly. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## 🛠 **Inputs** |
| 99 | + |
| 100 | +| Name | Required | Description | |
| 101 | +| -------------- | -------- | ------------------------------------------------------------ | |
| 102 | +| `github-token` | ✅ Yes | GitHub token used for authentication (`${{ github.token }}`) | |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## 🎯 **Best Use Cases** |
| 107 | + |
| 108 | +- **Before running API-heavy workflows** (e.g., fetching issue data, triggering GitHub Actions via API). |
| 109 | +- **Monitoring CI/CD jobs that rely on GitHub API calls** to avoid failures mid-run. |
| 110 | +- **Logging and auditing API usage** across your organization’s GitHub actions. |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## 🏆 **Take Control of Your GitHub API Usage** |
| 115 | + |
| 116 | +This action gives you the **power to monitor, manage, and prevent API failures before they happen**. Whether you're a solo developer or running large-scale automation, **stay ahead of rate limits and keep your workflows running smoothly**. 🚀 |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +### **🔗 Related Resources** |
| 121 | + |
| 122 | +- [GitHub API Rate Limits Docs](https://docs.github.com/en/rest/rate-limit) |
| 123 | +- [GitHub Actions Documentation](https://docs.github.com/en/actions) |
0 commit comments