diff --git a/.github/agents/developer.instructions.md b/.github/agents/developer.instructions.md index 6d7e973eff..7ddfebdef5 100644 --- a/.github/agents/developer.instructions.md +++ b/.github/agents/developer.instructions.md @@ -20,6 +20,7 @@ This document consolidates development guidelines, architectural patterns, and i - [Testing Framework](#testing-framework) - [Repo-Memory System](#repo-memory-system) - [Hierarchical Agent Management](#hierarchical-agent-management) +- [GitHub Actions Cost Estimation](#github-actions-cost-estimation) - [Release Management](#release-management) - [Quick Reference](#quick-reference) @@ -592,6 +593,200 @@ graph TD --- +## GitHub Actions Cost Estimation + +The cost estimation system helps users understand resource consumption before deploying scheduled automation, enabling informed decisions about workflow frequency and tool usage. + +### When to Include Cost Estimation + +Cost estimation tables should be included for: + +- **Scheduled workflows** that run on cron schedules (`on: schedule`) +- **High-frequency workflows** (hourly, daily, multiple times per day) +- **Workflows using expensive tools** (Playwright, extensive file operations) +- **Documentation examples** demonstrating scheduled automation +- **Any workflow** where monthly minutes usage may approach or exceed the free tier + +Cost estimation is optional for: + +- Event-driven workflows (triggered by issues, PRs, pushes) +- Manual workflows (`workflow_dispatch` only) +- One-time or rarely-executed automation + +### Cost Estimation Architecture + +```mermaid +graph TD + A[Workflow Definition] --> B[Base Execution Time] + A --> C[Tool Multipliers] + A --> D[Schedule Frequency] + + B --> E[Simple: 2min] + B --> F[Medium: 3-5min] + B --> G[Complex: 5-10min] + + C --> H[Playwright: +5min] + C --> I[repo-memory: +1min] + C --> J[Network APIs: +2min] + + D --> K[Hourly: 720/month] + D --> L[Daily: 30/month] + D --> M[Weekly: 4/month] + + B --> N[Monthly Cost Calculation] + C --> N + D --> N + + N --> O{Free Tier Check} + O -->|< 1,500 min| P[✅ Acceptable] + O -->|1,500-2,000 min| Q[⚠️ Monitor] + O -->|> 2,000 min| R[❌ Optimization Required] +``` + +### Cost Estimation Formula + +``` +Monthly Minutes = (Base Time + Tool Overhead) × Schedule Frequency +Free Tier Impact = (Monthly Minutes / 2,000) × 100% +``` + +**Base Execution Time**: +- Simple workflows (basic API calls): ~2 minutes +- Medium workflows (data processing): ~3-5 minutes +- Complex workflows (extensive analysis): ~5-10 minutes + +**Tool Multipliers**: +| Tool/Feature | Additional Minutes | Reason | +|--------------|-------------------|--------| +| Playwright | +5 minutes | Browser automation containerization | +| repo-memory | +1 minute | Git branch operations | +| Network API calls | +2 minutes | External HTTP requests | +| cache-memory | +0.5 minutes | Artifact operations | +| Multiple MCP servers (3+) | +1-2 minutes | Tool initialization overhead | +| File processing (large repos) | +2-3 minutes | Checkout and scanning | + +**Schedule Frequencies**: +| Schedule | Runs/Month | Example Cron | +|----------|------------|--------------| +| Hourly | 720 | `"0 * * * *"` | +| Every 6 hours | 120 | `"0 */6 * * *"` | +| Daily | 30 | `"0 2 * * *"` | +| Weekdays only | 22 | `"0 2 * * 1-5"` | +| Weekly | 4 | `"0 2 * * 1"` | + +### Cost Table Template + +Include this table in workflow documentation: + +```markdown +## Estimated Cost + +- **Base execution time**: ~X minutes per run +- **Tool overhead**: +Y minutes (list tools) +- **Total per run**: ~(X+Y) minutes +- **Schedule**: [Frequency] (N runs/month) +- **Monthly total**: ~Z minutes (~H hours) +- **Free tier impact**: P% of free tier + +### Free Tier Comparison + +- **Public repositories**: 2,000 minutes/month (free tier) +- **This workflow**: Z minutes/month +- **Status**: ✅ Within free tier / ⚠️ Exceeds free tier +``` + +### Example: Hourly Monitoring + +```markdown +## Estimated Cost + +- **Base execution time**: ~3 minutes per run +- **Tool overhead**: +2 minutes (network API calls) +- **Total per run**: ~5 minutes +- **Schedule**: Hourly (720 runs/month) +- **Monthly total**: ~3,600 minutes (~60 hours) +- **Free tier impact**: 180% (exceeds free tier by 1,600 minutes) + +### Optimization Suggestions + +⚠️ **This workflow exceeds the free tier.** Consider: + +1. **Reduce frequency**: Hourly → Every 6 hours (saves 2,400 min/month) +2. **Use path filters**: Skip runs when files unchanged +3. **Add pre-activation checks**: Exit early when no work needed +``` + +### Optimization Strategies + +When monthly usage exceeds 1,500 minutes (75% of free tier): + +**1. Reduce Frequency**: +- Hourly → Every 6 hours (saves 80% of runs) +- Daily → Weekdays only (saves 25% of runs) +- Consider business hours only + +**2. Add Conditional Execution**: +```yaml +pre-activation: + - name: Check if work needed + run: | + if [ no_changes_detected ]; then + echo "Skipping workflow" + exit 1 + fi +``` + +**3. Use Path Filters**: +```yaml +on: + schedule: + - cron: "0 * * * *" + push: + paths: + - 'src/**' + - 'config/**' +``` + +**4. Optimize Tool Usage**: +- Parallel jobs instead of sequential +- Cache dependencies +- Set `timeout-minutes` to prevent runaway jobs +- Batch network calls + +**5. Alternative Triggers**: +- Replace schedule with webhook events +- Use `repository_dispatch` for external triggers +- Implement manual review gates + +### Cost Tracking + +Monitor actual usage: + +```bash +gh aw logs --workflow [name] --stats +``` + +Provides: +- Average execution time +- Token usage +- Actual cost per run +- Monthly projection + +### Agent Guidelines + +When creating scheduled workflows: + +1. **Always calculate cost** using the formula above +2. **Include cost table** in workflow documentation +3. **Add optimization suggestions** when monthly usage exceeds 1,500 minutes +4. **Consider weekday-only schedules** for business workflows +5. **Recommend monitoring** for workflows approaching free tier limits +6. **Test with lower frequency** initially before increasing + +**Implementation**: See examples/cost-estimation-table.md for detailed templates and examples + +--- + ## Release Management ### Changesets @@ -708,6 +903,7 @@ For detailed specifications, see individual files in `specs/`: - [Styles Guide](../../specs/styles-guide.md) - [Changesets](../../specs/changesets.md) - [Labels](../../specs/labels.md) +- [GitHub Actions Cost Estimation](examples/cost-estimation-table.md) ### Advanced Topics - [Hierarchical Agents](../../specs/agents/hierarchical-agents.md) @@ -726,4 +922,4 @@ For detailed specifications, see individual files in `specs/`: --- -**Last Updated**: 2026-01-04 +**Last Updated**: 2026-01-16 diff --git a/.github/agents/examples/cost-estimation-table.md b/.github/agents/examples/cost-estimation-table.md new file mode 100644 index 0000000000..3b66ca221b --- /dev/null +++ b/.github/agents/examples/cost-estimation-table.md @@ -0,0 +1,190 @@ +# GitHub Actions Cost Estimation Template + +This template provides a framework for estimating the cost of GitHub Actions workflows, particularly for scheduled automation. + +## Cost Estimation Formula + +The total cost of a workflow depends on several factors: + +``` +Monthly Minutes = (Base Execution Time + Tool Multipliers) × Schedule Frequency +``` + +### Base Execution Time + +- **Simple workflows** (basic API calls, minimal processing): ~2 minutes per run +- **Medium workflows** (data processing, multiple API calls): ~3-5 minutes per run +- **Complex workflows** (extensive analysis, file operations): ~5-10 minutes per run + +### Tool Multipliers + +Add these minutes to the base execution time based on tools used: + +| Tool/Feature | Additional Minutes | Reason | +|--------------|-------------------|--------| +| **Playwright** | +5 minutes | Browser automation with containerization overhead | +| **repo-memory** | +1 minute | Git branch cloning and pushing operations | +| **Network API calls** (external) | +2 minutes | HTTP requests to external services | +| **cache-memory** | +0.5 minutes | Artifact upload/download operations | +| **Multiple MCP servers** (3+) | +1-2 minutes | Additional tool initialization overhead | +| **File processing** (large repos) | +2-3 minutes | Checkout and file scanning operations | + +### Schedule Frequency Calculations + +| Schedule | Runs per Month | Example Cron | +|----------|----------------|--------------| +| **Hourly** | 720 | `"0 * * * *"` | +| **Every 6 hours** | 120 | `"0 */6 * * *"` | +| **Daily** | 30 | `"0 2 * * *"` | +| **Weekdays only** | 22 | `"0 2 * * 1-5"` | +| **Weekly** | 4 | `"0 2 * * 1"` | +| **Bi-weekly** | 2 | `"0 2 1,15 * *"` | + +## Cost Table Template + +When creating scheduled workflows, include this table in the workflow documentation: + +```markdown +## Estimated Cost + +- **Base execution time**: ~[X] minutes per run +- **Tool overhead**: +[Y] minutes ([list tools]) +- **Total per run**: ~[X+Y] minutes +- **Schedule**: [Frequency] ([runs per month] runs/month) +- **Monthly total**: ~[total] minutes (~[hours] hours) +- **Free tier impact**: [percentage]% of free tier + +### Free Tier Comparison + +- **Public repositories**: 2,000 minutes/month (free tier) +- **Private repositories**: 2,000 minutes/month (free tier for Pro accounts) +- **This workflow**: [total] minutes/month +- **Status**: ✅ Within free tier / ⚠️ Exceeds free tier by [X] minutes +``` + +## Example 1: Hourly Monitoring Workflow + +```markdown +## Estimated Cost + +- **Base execution time**: ~3 minutes per run +- **Tool overhead**: +2 minutes (network API calls) +- **Total per run**: ~5 minutes +- **Schedule**: Hourly (720 runs/month) +- **Monthly total**: ~3,600 minutes (~60 hours) +- **Free tier impact**: 180% (exceeds free tier by 1,600 minutes) + +### Optimization Suggestions + +⚠️ **This workflow exceeds the free tier.** Consider these optimizations: + +1. **Reduce frequency**: Change from hourly to every 6 hours (saves 2,400 minutes/month) +2. **Use path filters**: Skip runs when monitored files haven't changed +3. **Conditional execution**: Add pre-activation checks to exit early when no action needed +``` + +## Example 2: Daily Code Scan + +```markdown +## Estimated Cost + +- **Base execution time**: ~4 minutes per run +- **Tool overhead**: +3 minutes (repo-memory + file processing) +- **Total per run**: ~7 minutes +- **Schedule**: Daily on weekdays (22 runs/month) +- **Monthly total**: ~154 minutes (~2.6 hours) +- **Free tier impact**: 7.7% of free tier + +### Status + +✅ **Well within free tier limits.** This workflow is cost-efficient for daily operations. +``` + +## Example 3: Weekly Digest with Playwright + +```markdown +## Estimated Cost + +- **Base execution time**: ~5 minutes per run +- **Tool overhead**: +5 minutes (Playwright browser automation) +- **Total per run**: ~10 minutes +- **Schedule**: Weekly (4 runs/month) +- **Monthly total**: ~40 minutes (~0.67 hours) +- **Free tier impact**: 2% of free tier + +### Status + +✅ **Minimal cost impact.** Ideal for weekly automation without concerns about usage limits. +``` + +## When to Include Cost Estimation + +**Always include** cost estimation tables for: + +- Scheduled workflows (`on: schedule`) +- Workflows that run frequently (hourly, daily) +- Workflows using expensive tools (Playwright, extensive file operations) +- Workflows in documentation examples + +**Optional** for: + +- Event-driven workflows (issues, pull requests) +- Manual workflows (`workflow_dispatch` only) +- One-time or rare automation tasks + +## Optimization Best Practices + +When a workflow exceeds 1,500 minutes/month (75% of free tier): + +1. **Reduce frequency**: + - Hourly → Every 6 hours (saves 80% of runs) + - Daily → Weekdays only (saves 25% of runs) + - Consider business hours only for monitoring + +2. **Add path filters**: + ```yaml + on: + schedule: + - cron: "0 * * * *" + push: + paths: + - 'src/**' + - 'config/**' + ``` + +3. **Use pre-activation checks**: + ```yaml + pre-activation: + - name: Check if work needed + run: | + # Exit early if no changes detected + if [ "$(git diff --name-only HEAD^)" = "" ]; then + echo "No changes detected, skipping workflow" + exit 1 + fi + ``` + +4. **Optimize tool usage**: + - Run jobs in parallel instead of sequential + - Cache dependencies to reduce setup time + - Use `timeout-minutes` to prevent runaway jobs + - Minimize network calls with batching + +5. **Consider alternative triggers**: + - Replace schedule with webhook events + - Use repository_dispatch for external triggers + - Implement manual review gates for expensive operations + +## Cost Tracking + +Monitor your actual usage with: + +```bash +gh aw logs --workflow [workflow-name] --stats +``` + +This provides: +- Average execution time +- Token usage +- Actual cost per run +- Monthly projection based on schedule diff --git a/pkg/parser/schemas/main_workflow_schema.json b/pkg/parser/schemas/main_workflow_schema.json index 682d07a0f5..4a871e467d 100644 --- a/pkg/parser/schemas/main_workflow_schema.json +++ b/pkg/parser/schemas/main_workflow_schema.json @@ -2357,12 +2357,7 @@ "pattern": "^[^:]+:[^:]+:(ro|rw)$", "description": "Mount specification in format 'source:destination:mode'" }, - "examples": [ - [ - "/host/data:/container/data:ro", - "/host/config:/container/config:rw" - ] - ] + "examples": [["/host/data:/container/data:ro", "/host/config:/container/config:rw"]] }, "env": { "type": "object",