Skip to content

🧹 Code Cleanup

🧹 Code Cleanup #6

Workflow file for this run

name: 🧹 Code Cleanup
on:
schedule:
- cron: '0 2 * * 1' # Weekly on Monday at 2 AM
workflow_dispatch: # Manual trigger
jobs:
cleanup:
name: 🧹 Automated Cleanup
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: 🐍 Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: 📦 Install cleanup tools
run: |
pip install ruff black isort bandit safety
- name: 🧹 Format code with Black
run: |
black src/ --check --diff || black src/
- name: 📋 Sort imports with isort
run: |
isort src/ --check --diff || isort src/
- name: 🔍 Lint and fix with Ruff
run: |
ruff check src/ --fix --output-format=github
- name: 🔒 Update requirements for security
run: |
pip-compile requirements.in --upgrade || echo "No requirements.in found"
safety check || echo "Safety check completed with warnings"
- name: 📝 Clean up agent profiles
run: |
# Validate and format JSON files
for file in AGENT_Profiles/*.json; do
if [ -f "$file" ]; then
echo "Formatting $file..."
python -m json.tool "$file" > temp.json && mv temp.json "$file"
fi
done
- name: 🧪 Remove unused test files
run: |
# Remove empty test files
find tests/ -name "*.py" -size 0 -delete 2>/dev/null || true
# Remove __pycache__ directories
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
# Remove .pyc files
find . -name "*.pyc" -delete 2>/dev/null || true
- name: 📊 Update documentation
run: |
# Generate requirements list for README if needed
if [ -f "requirements.txt" ]; then
echo "## 📋 Dependencies" > DEPENDENCIES.md
echo "" >> DEPENDENCIES.md
while IFS= read -r line; do
if [[ $line =~ ^[a-zA-Z] ]]; then
package=$(echo $line | cut -d'=' -f1)
echo "- **$package**: $(echo $line | cut -d'=' -f2-)" >> DEPENDENCIES.md
fi
done < requirements.txt
fi
- name: ✅ Create cleanup PR if changes exist
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitTalker Cleanup Bot"
if ! git diff --quiet; then
git add .
git commit -m "🧹 Automated code cleanup
- Format code with Black and isort
- Fix linting issues with Ruff
- Update security dependencies
- Clean agent profile JSON formatting
- Remove unused files and cache
- Update documentation"
# Create a new branch for the cleanup
branch="automated-cleanup-$(date +%Y%m%d)"
git checkout -b $branch
git push origin $branch
# Create PR using GitHub CLI
gh pr create \
--title "🧹 Automated Weekly Cleanup" \
--body "This PR contains automated code cleanup:
## 🔧 Changes Made
- Code formatting (Black, isort)
- Linting fixes (Ruff)
- Security dependency updates
- JSON formatting for agent profiles
- Cleanup of temporary files
- Documentation updates
## 🤖 Automated Process
This PR was created by the weekly cleanup workflow to maintain code quality.
**Safe to merge**: All changes are formatting and cleanup only." \
--head $branch \
--base main
else
echo "No changes detected - repository is already clean! ✨"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}