2025-06-28 02:05:53 +02:00
|
|
|
|
name: Generate M3U Playlist with Auto-Cleanup
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
|
|
jobs:
|
2025-06-28 02:05:53 +02:00
|
|
|
|
build-and-cleanup:
|
2025-06-27 16:30:39 +02:00
|
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
|
steps:
|
2025-06-27 23:41:32 +02:00
|
|
|
|
- name: Checkout Repository
|
2025-06-27 16:30:39 +02:00
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
2025-06-27 23:41:32 +02:00
|
|
|
|
- name: Set up Python
|
2025-06-27 16:30:39 +02:00
|
|
|
|
uses: actions/setup-python@v5
|
|
|
|
|
with:
|
2025-06-27 17:36:55 +02:00
|
|
|
|
python-version: '3.11'
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
2025-06-27 23:41:32 +02:00
|
|
|
|
- name: Configure Git
|
2025-06-27 16:30:39 +02:00
|
|
|
|
run: |
|
|
|
|
|
git config --local user.email "actions@forgejo.plainrock127.xyz"
|
2025-06-27 17:36:55 +02:00
|
|
|
|
git config --local user.name "IPTV Playlist Bot"
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
- name: Pre-Cleanup Health Check
|
2025-06-27 17:36:55 +02:00
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Repository Health Check ==="
|
|
|
|
|
python -c "
|
|
|
|
|
import sys, os
|
|
|
|
|
sys.path.insert(0, 'scripts')
|
|
|
|
|
from repo_health import RepoHealthMonitor
|
|
|
|
|
monitor = RepoHealthMonitor()
|
|
|
|
|
health = monitor.run_health_check()
|
|
|
|
|
print(f'Organization Score: {health[\"organization_score\"]}/100')
|
|
|
|
|
print(f'Total Size: {health[\"repository_size\"][\"total_mb\"]:.1f} MB')
|
|
|
|
|
print(f'Files: {health[\"file_counts\"][\"total_files\"]}')
|
|
|
|
|
if health['cleanup_suggestions']:
|
|
|
|
|
print('Cleanup needed:')
|
|
|
|
|
for suggestion in health['cleanup_suggestions'][:3]:
|
|
|
|
|
print(f' - {suggestion}')
|
|
|
|
|
" 2>/dev/null || echo "Health check skipped (first run)"
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
- name: Auto-Cleanup Repository
|
|
|
|
|
run: |
|
|
|
|
|
echo "=== Auto-Cleanup Phase ==="
|
|
|
|
|
|
|
|
|
|
# Remove Python cache thoroughly
|
|
|
|
|
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
|
|
|
find . -name "*.pyc" -delete 2>/dev/null || true
|
|
|
|
|
find . -name "*.pyo" -delete 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Remove temporary files
|
|
|
|
|
find . -name "*_temp*" -type f -delete 2>/dev/null || true
|
|
|
|
|
find . -name "*.tmp" -delete 2>/dev/null || true
|
|
|
|
|
find . -name "*~" -delete 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Clean backup files older than 30 days
|
|
|
|
|
find backups -name "*.txt" -type f -mtime +30 -delete 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Organize log files
|
|
|
|
|
mkdir -p reports/logs reports/archive
|
|
|
|
|
find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Compress old backups (older than 7 days)
|
|
|
|
|
find backups -name "*.txt" -type f -mtime +7 -exec gzip {} \; 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
echo "✅ Cleanup completed"
|
|
|
|
|
|
2025-06-28 00:11:35 +02:00
|
|
|
|
- name: Setup Directories
|
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Directory Setup ==="
|
|
|
|
|
mkdir -p config backups reports/logs reports/archive templates
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
|
|
|
|
# Create scripts/__init__.py if missing
|
|
|
|
|
if [ ! -f scripts/__init__.py ]; then
|
|
|
|
|
echo '# Scripts package' > scripts/__init__.py
|
|
|
|
|
fi
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
|
|
|
|
# Ensure proper directory structure
|
|
|
|
|
ls -la scripts/ || echo "Scripts directory missing"
|
|
|
|
|
|
|
|
|
|
- name: Debug File Structure
|
|
|
|
|
run: |
|
|
|
|
|
echo "=== File Structure Debug ==="
|
|
|
|
|
echo "Root files:"
|
|
|
|
|
ls -la | head -20
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Scripts directory:"
|
|
|
|
|
ls -la scripts/ 2>/dev/null || echo "Scripts directory not found"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Import file status:"
|
|
|
|
|
if [ -f bulk_import.m3u ]; then
|
|
|
|
|
echo "✅ bulk_import.m3u found ($(wc -l < bulk_import.m3u) lines, $(du -h bulk_import.m3u | cut -f1))"
|
|
|
|
|
echo "First few lines:"
|
|
|
|
|
head -5 bulk_import.m3u
|
|
|
|
|
else
|
|
|
|
|
echo "❌ bulk_import.m3u not found"
|
|
|
|
|
fi
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
|
|
|
|
- name: Run Playlist Generation
|
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Playlist Generation ==="
|
2025-06-28 00:11:35 +02:00
|
|
|
|
python scripts/generate_playlist.py
|
2025-06-27 17:36:55 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
- name: Post-Generation Health Check
|
2025-06-27 17:36:55 +02:00
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Post-Generation Analysis ==="
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
2025-06-27 17:36:55 +02:00
|
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0")
|
|
|
|
|
FILE_SIZE=$(du -h playlist.m3u | cut -f1)
|
|
|
|
|
echo "✅ playlist.m3u generated:"
|
|
|
|
|
echo " - Channels: $CHANNEL_COUNT"
|
|
|
|
|
echo " - Size: $FILE_SIZE"
|
|
|
|
|
|
|
|
|
|
# Show top countries
|
|
|
|
|
echo " - Top countries:"
|
|
|
|
|
grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -5 || echo " No country data"
|
2025-06-28 00:11:35 +02:00
|
|
|
|
else
|
|
|
|
|
echo "❌ playlist.m3u not generated"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -f channels.txt ]; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
CHANNELS_SIZE=$(du -h channels.txt | cut -f1)
|
|
|
|
|
CHANNELS_LINES=$(wc -l < channels.txt)
|
|
|
|
|
echo "📁 channels.txt: $CHANNELS_SIZE ($CHANNELS_LINES lines)"
|
2025-06-27 17:36:55 +02:00
|
|
|
|
fi
|
2025-06-27 17:51:10 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# Check for any error logs
|
|
|
|
|
if [ -f reports/logs/playlist_update.log ]; then
|
|
|
|
|
echo "📋 Recent log entries:"
|
|
|
|
|
tail -10 reports/logs/playlist_update.log || tail -10 playlist_update.log 2>/dev/null || echo "No logs found"
|
2025-06-28 00:57:29 +02:00
|
|
|
|
fi
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
|
|
|
|
- name: Repository Cleanup & Organization
|
2025-06-27 16:30:39 +02:00
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Final Repository Organization ==="
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# Remove any remaining cache files
|
|
|
|
|
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Move any stray log files
|
|
|
|
|
find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Clean up any editor backup files
|
|
|
|
|
find . -name "*~" -delete 2>/dev/null || true
|
|
|
|
|
find . -name "*.swp" -delete 2>/dev/null || true
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# Ensure bulk_import.m3u is clean for next use
|
|
|
|
|
if [ -f bulk_import.m3u ]; then
|
|
|
|
|
# If it has more than just the header, it means it wasn't cleaned by the script
|
|
|
|
|
LINE_COUNT=$(wc -l < bulk_import.m3u)
|
|
|
|
|
if [ "$LINE_COUNT" -gt 2 ]; then
|
|
|
|
|
echo "⚠️ Manually cleaning bulk_import.m3u (had $LINE_COUNT lines)"
|
|
|
|
|
echo '#EXTM3U' > bulk_import.m3u
|
|
|
|
|
echo '' >> bulk_import.m3u
|
|
|
|
|
fi
|
2025-06-28 00:57:29 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "✅ Repository organized"
|
|
|
|
|
|
|
|
|
|
- name: Commit Changes
|
|
|
|
|
run: |
|
|
|
|
|
echo "=== Committing Changes ==="
|
|
|
|
|
|
|
|
|
|
# Add specific files/directories (exclude unnecessary items)
|
2025-06-28 00:57:29 +02:00
|
|
|
|
git add bulk_import.m3u || true
|
|
|
|
|
git add channels.txt || true
|
|
|
|
|
git add playlist.m3u || true
|
|
|
|
|
git add scripts/ || true
|
|
|
|
|
git add config/ || true
|
|
|
|
|
git add reports/ || true
|
2025-06-28 02:05:53 +02:00
|
|
|
|
git add backups/*.gz || true # Only compressed backups
|
2025-06-28 00:57:29 +02:00
|
|
|
|
git add templates/ || true
|
|
|
|
|
git add .forgejo/ || true
|
|
|
|
|
git add README.md || true
|
2025-06-28 02:05:53 +02:00
|
|
|
|
git add .gitignore || true
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# Remove any files that shouldn't be tracked
|
|
|
|
|
git rm --cached *.log 2>/dev/null || true
|
|
|
|
|
git rm --cached **/__pycache__/** 2>/dev/null || true
|
|
|
|
|
git rm --cached **/*.pyc 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# Check what we're about to commit
|
|
|
|
|
echo "Files to be committed:"
|
|
|
|
|
git diff --staged --name-only || echo "No staged changes"
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-27 23:42:36 +02:00
|
|
|
|
if ! git diff --staged --quiet; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# Calculate channel count for commit message
|
2025-06-27 17:36:55 +02:00
|
|
|
|
CHANNEL_COUNT="0"
|
|
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0")
|
2025-06-27 17:36:55 +02:00
|
|
|
|
fi
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# Calculate repository size
|
|
|
|
|
REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown")
|
|
|
|
|
|
|
|
|
|
# Create informative commit message
|
|
|
|
|
COMMIT_MSG="📺 Updated playlist: $CHANNEL_COUNT channels ($(date '+%Y-%m-%d %H:%M'))
|
|
|
|
|
|
|
|
|
|
Repository Status:
|
|
|
|
|
- Size: $REPO_SIZE
|
|
|
|
|
- Channels: $CHANNEL_COUNT
|
|
|
|
|
- Auto-cleaned and organized
|
|
|
|
|
- $(date '+%Y-%m-%d %H:%M:%S UTC')"
|
|
|
|
|
|
|
|
|
|
git commit -m "$COMMIT_MSG"
|
2025-06-27 23:42:36 +02:00
|
|
|
|
git push
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "✅ Repository updated successfully"
|
|
|
|
|
echo " 📺 Channels: $CHANNEL_COUNT"
|
|
|
|
|
echo " 📁 Size: $REPO_SIZE"
|
2025-06-28 00:57:29 +02:00
|
|
|
|
else
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "ℹ️ No changes to commit"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
- name: Final Status Report
|
|
|
|
|
run: |
|
|
|
|
|
echo "=== Final Status Report ==="
|
|
|
|
|
echo "🎯 Workflow completed successfully!"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "📊 Repository Statistics:"
|
|
|
|
|
echo " - Total files: $(find . -type f | wc -l)"
|
|
|
|
|
echo " - Directory size: $(du -sh . | cut -f1)"
|
|
|
|
|
echo " - Git status: $(git status --porcelain | wc -l) pending changes"
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
if [ -f playlist.m3u ]; then
|
|
|
|
|
CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0")
|
|
|
|
|
echo "✅ Playlist Status:"
|
|
|
|
|
echo " - Channels: $CHANNEL_COUNT"
|
|
|
|
|
echo " - File size: $(du -h playlist.m3u | cut -f1)"
|
|
|
|
|
echo " - Last updated: $(date)"
|
|
|
|
|
else
|
|
|
|
|
echo "❌ No playlist generated"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "🧹 Cleanup Summary:"
|
|
|
|
|
echo " - Python cache: Removed"
|
|
|
|
|
echo " - Log files: Organized in reports/logs/"
|
|
|
|
|
echo " - Backup files: Compressed if older than 7 days"
|
|
|
|
|
echo " - Temporary files: Cleaned"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "🚀 Ready for next import!"
|