Agent skill

ops-utils

Operations and infrastructure utilities for vm0 project

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/ops-utils

SKILL.md

You are an operations utilities specialist for the vm0 project. Your role is to handle infrastructure and operational tasks efficiently.

Operations

Parse the args parameter to determine which operation to perform:

  • cleanup-previews: Clean up old GitHub preview deployment environments

When invoked, check the args to determine the operation and execute accordingly.


Operation: cleanup-previews

Clean up GitHub preview deployment environments that haven't had deployments in the last 3 days.

What It Does

  • Lists all preview environments
  • Identifies environments older than 3 days
  • Deletes old preview environments
  • Preserves production and recent preview environments

Workflow

Step 1: List All Preview Environments

bash
gh api repos/:owner/:repo/environments --paginate -q '.environments[] | .name' 2>/dev/null | grep -i preview > /tmp/preview_envs.txt

Count total:

bash
total_count=$(wc -l < /tmp/preview_envs.txt)
echo "Found $total_count preview environments"

Step 2: Get Latest Deployment Dates

bash
gh api repos/:owner/:repo/deployments --paginate -q '.[] | select(.environment | test("preview")) | "\(.environment)|\(.created_at)"' 2>/dev/null | sort -t'|' -k1,1 -k2,2r | sort -t'|' -k1,1 -u > /tmp/latest_preview_deployments.txt

Step 3: Show Environments to be Deleted

Calculate cutoff date (3 days ago) and preview deletions:

bash
cutoff=$(date -d "3 days ago" -Iseconds)
echo "Cutoff date: $cutoff"
echo ""
echo "Preview environments status:"

while IFS='|' read -r env date; do
  if [[ "$date" < "$cutoff" ]]; then
    echo "DELETE: $env (last: $date)"
  else
    echo "KEEP:   $env (last: $date)"
  fi
done < /tmp/latest_preview_deployments.txt

Step 4: Delete Old Preview Environments

bash
cutoff=$(date -d "3 days ago" -Iseconds)
count=0
failed=0

while read env; do
  # URL encode environment name
  encoded_env=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$env', safe=''))")

  # Attempt deletion
  if gh api -X DELETE "repos/:owner/:repo/environments/$encoded_env" --silent 2>/dev/null; then
    ((count++))
    # Progress indicator every 50 deletions
    if [ $((count % 50)) -eq 0 ]; then
      echo "Deleted $count environments..."
    fi
  else
    ((failed++))
  fi
done < /tmp/preview_envs.txt

echo ""
echo "=== Deletion Summary ==="
echo "Deleted: $count"
echo "Failed:  $failed"

Step 5: Verify Cleanup

Check remaining preview environments:

bash
remaining=$(gh api repos/:owner/:repo/environments --paginate -q '.environments[] | .name' 2>/dev/null | grep -i preview | wc -l)
echo "Remaining preview environments: $remaining"

Step 6: Display Final Summary

## Cleanup Complete

| Item | Count |
|------|-------|
| Total preview environments before | [count] |
| Deleted (>3 days old) | [count] |
| Failed deletions | [count] |
| Remaining preview environments | [count] |

## Remaining Environments

[List all remaining environments]

Important Notes

  • Only deletes GitHub Environments, not deployment records
  • Production environments (production, web/production, docs/production, npm) are NOT affected
  • Preview environments with recent activity (within 3 days) are preserved
  • Deletion process may take several minutes for large numbers of environments
  • Uses GitHub API with proper URL encoding for environment names

Error Handling

If API calls fail:

  • Verify GitHub CLI authentication: gh auth status
  • Check repository permissions (need write access to environments)
  • Verify rate limits: gh api rate_limit

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results