forked from Chachigo/FamilyBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
447 lines (369 loc) · 16 KB
/
justfile
File metadata and controls
447 lines (369 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# FamilyBot Justfile - Cross-platform task runner
# Run `just --list` to see all available commands
# Default recipe - shows help
default:
@just --list
# === SETUP AND INSTALLATION ===
# Complete setup: create venv, install dependencies, and verify installation
setup:
@echo "🚀 Setting up FamilyBot development environment..."
just create-venv
just install-deps
just node-deps
just update-camoufox
just verify-setup
@echo "✅ Setup complete! Run 'just run' to start the bot."
# Install Node.js dependencies for linting and formatting
node-deps:
@echo "📥 Installing Node.js development dependencies..."
mise exec -- npm install -g markdownlint-cli2 prettier
# Create virtual environment using uv
create-venv:
@echo "📦 Creating virtual environment with uv..."
mise exec -- uv venv --clear
@echo "✅ Virtual environment created at .venv/"
# Install all dependencies in editable mode
install-deps:
@echo "📥 Installing dependencies from lockfile and project in editable mode..."
mise exec -- uv pip install -r requirements.txt -e .
@echo "✅ Dependencies installed."
# Clean reinstall: remove everything and start fresh
reinstall:
@echo "🧹 Performing clean reinstall..."
just clean-all
just setup
@echo "✅ Clean reinstall complete!"
# Generate a new lockfile from pyproject.toml
lock:
@echo "🔒 Generating lockfile from pyproject.toml..."
mise exec -- uv pip compile pyproject.toml --extra dev -o requirements.txt
@echo "✅ requirements.txt lockfile updated."
# Generate a hash-pinned lockfile (recommended for supply chain security)
lock-hashes:
@echo "🔒 Generating hash-pinned lockfile from pyproject.toml..."
mise exec -- uv pip compile pyproject.toml --extra dev --generate-hashes -o requirements-hashes.txt
@echo "✅ requirements-hashes.txt hash-pinned lockfile created."
@echo "💡 This lockfile verifies every package by SHA256 hash at install time."
@echo "📖 See: https://bernat.tech/posts/securing-python-supply-chain/"
# Upgrade all dependencies in the lockfile to the latest safe versions
update-deps:
@echo "⬆️ Upgrading dependencies to their latest compatible versions (respecting ~=)..."
mise exec -- uv pip compile pyproject.toml --extra dev --upgrade -o requirements.txt
@echo "✅ Lockfile updated. Run 'just install-deps' to apply the changes."
# Verify installation is working
verify-setup:
@echo "🔍 Verifying installation..."
@echo "Python version:"
mise exec -- uv run python --version
@echo "FamilyBot version:"
mise exec -- uv run python -c "import familybot; print('FamilyBot package loaded successfully')" || echo "⚠️ FamilyBot package not found"
@echo "✅ Verification complete"
# === RUNNING THE BOT ===
# Run the main bot (recommended method)
run: verify-setup
@echo "🤖 Starting FamilyBot..."
@echo "Press Ctrl+C to stop the bot gracefully"
mise exec -- uv run familybot
@echo "🛑 FamilyBot stopped"
# Set up browser profile for token sender (first-time setup)
setup-browser:
@echo "🌐 Setting up browser profile for Steam login..."
mise exec -- uv run python scripts/setup_browser.py
# Test token extraction functionality
test-token:
@echo "🔑 Testing token extraction..."
mise exec -- uv run python scripts/test_token_plugin.py
# Run token diagnostic tool (detailed debugging)
diagnose-token:
@echo "🔍 Running token diagnostics..."
mise exec -- uv run python scripts/diagnose_token.py
# Force immediate token update
force-token:
@echo "🔄 Forcing token update..."
mise exec -- uv run python scripts/force_token_update.py
# Update Camoufox and browser binaries
update-camoufox:
@echo "🦊 Updating Camoufox..."
mise exec -- uv pip install --upgrade camoufox
mise exec -- uv run camoufox fetch
@echo "✅ Camoufox updated"
# Test free games plugin
test-free-games:
@echo "🎮 Testing free games plugin..."
mise exec -- uv run python scripts/test_free_games.py
# Run bot with legacy script (backward compatibility)
run-legacy:
@echo "🤖 Starting FamilyBot using legacy script..."
@if [ -f "run_bots.ps1" ]; then powershell -ExecutionPolicy Bypass -File run_bots.ps1; elif [ -f "run_bots.sh" ]; then chmod +x run_bots.sh && ./run_bots.sh; else echo "❌ No legacy run script found"; fi
# === CACHE MANAGEMENT ===
# Purge game details cache
purge-cache:
@echo "🧹 Purging game details cache..."
mise exec -- uv run python src/familybot/FamilyBot.py --purge-cache
@echo "✅ Game details cache purged"
# Purge wishlist cache
purge-wishlist:
@echo "🧹 Purging wishlist cache..."
mise exec -- uv run python src/familybot/FamilyBot.py --purge-wishlist
@echo "✅ Wishlist cache purged"
# Purge family library cache
purge-family-library:
@echo "🧹 Purging family library cache..."
mise exec -- uv run python src/familybot/FamilyBot.py --purge-family-library
@echo "✅ Family library cache purged"
# Purge all cache data
purge-all-cache:
@echo "🧹 Purging ALL cache data..."
mise exec -- uv run python src/familybot/FamilyBot.py --purge-all
@echo "✅ All cache data purged"
# Purge price cache (ITAD prices and mappings)
purge-prices:
@echo "🧹 Purging price cache..."
mise exec -- uv run python src/familybot/FamilyBot.py --purge-prices
@echo "✅ Price cache purged"
# Check price cache status (permanent vs TTL-based entries)
check-price-cache:
@echo "🔍 Checking price cache status..."
mise exec -- uv run python scripts/check_price_cache.py
# === DATABASE OPERATIONS ===
# Populate database with game data and family information
populate-db:
@echo "📊 Populating database..."
mise exec -- uv run python scripts/populate_database.py
@echo "✅ Database populated"
# Import data from JSON file
import-json *args:
@echo "📥 Importing JSON data..."
mise exec -- uv run python scripts/json_database_importer.py {{args}}
# Convert Steamworks JSON to FamilyBot format
convert-json *args:
@echo "🔄 Converting Steamworks JSON..."
mise exec -- uv run python scripts/steamworks_json_converter.py {{args}}
# Populate price data (consolidated)
populate-prices *args:
@echo "💰 Populating price data (consolidated)..."
mise exec -- uv run python scripts/populate_prices.py {{args}}
@echo "✅ Price data populated"
# Inspect database structure and contents
inspect-db:
@echo "🔍 Inspecting database..."
mise exec -- uv run familybot-inspect-db
# Backup database
backup-db:
@echo "💾 Backing up database..."
mise exec -- uv run python scripts/backup_database.py
@echo "✅ Database backed up"
# Check database integrity
check-db:
@echo "🩺 Checking database integrity..."
mise exec -- uv run python scripts/check_db_integrity.py
# Fix missing or 'Unknown' game names in price cache
fix-missing-info:
@echo "🔧 Fixing missing game names in price cache..."
mise exec -- uv run python scripts/fix_missing_info.py
# Debug deals detection logic
debug-deals:
@echo "🔍 Debugging deals detection..."
mise exec -- uv run python scripts/debug_deals.py
# Restore database from a backup (interactive)
restore-db:
@echo "🔄 Restoring database from backup..."
mise exec -- uv run python scripts/restore_database.py
# === LINTING AND FORMATTING ===
# Run ruff linter
lint:
@echo "🔍 Running ruff linter..."
mise exec -- uv run ruff check src/ scripts/
# Run ruff linter with auto-fix
lint-fix:
@echo "🔧 Running ruff linter with auto-fix..."
mise exec -- uv run ruff check --fix src/ scripts/
# Format code with ruff
format:
@echo "✨ Formatting code with ruff..."
mise exec -- uv run ruff format src/ scripts/
# Format markdown files with prettier
format-md:
@echo "📝 Formatting markdown files..."
mise exec -- npx prettier --write "**/*.md"
# Check code formatting without making changes
format-check:
@echo "🔍 Checking code formatting..."
mise exec -- uv run ruff format --check src/ scripts/
# Check markdown formatting without making changes
format-md-check:
@echo "🔍 Checking markdown formatting..."
mise exec -- npx prettier --check "**/*.md"
# Run markdown linter
lint-md:
@echo "🔍 Linting markdown files..."
mise exec -- npx markdownlint-cli2 "**/*.md"
# Run mypy type checker
type-check:
@echo "🧐 Running mypy type checker..."
mise exec -- uv run mypy src/ scripts/
# Run pip-audit for security vulnerabilities (against standard lockfile)
audit:
@echo "🛡️ Running pip-audit for security vulnerabilities..."
mise exec -- uv run pip-audit -r requirements.txt -s osv
# Run pip-audit for security vulnerabilities (against hash-pinned lockfile)
audit-hashes:
@echo "🛡️ Running pip-audit against hash-pinned lockfile..."
mise exec -- uv run pip-audit -r requirements-hashes.txt -s osv
# Install dependencies with time-based constraints (supply chain security)
install-safe older_than_days='7':
@echo "🔒 Installing with --exclude-newer (supply chain security)..."
@echo "This installs packages published at least {{ older_than_days }} days ago"
@mise exec -- uv run python -c "from datetime import datetime, timedelta; days = int('{{ older_than_days }}'); date = (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d'); print(f'Excluding packages newer than: {date}')"
@mise exec -- uv run python -c "from datetime import datetime, timedelta; days = int('{{ older_than_days }}'); date = (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d'); import subprocess; subprocess.run(['mise', 'exec', '--', 'uv', 'pip', 'install', '--exclude-newer', date, '-r', 'requirements-hashes.txt'], check=True)"
# Show supply chain security status
security-status:
@echo "🔒 FamilyBot Supply Chain Security Status"
@echo "========================================="
@echo ""
@echo "✅ Hash-pinned lockfile:"
@if [ -f "requirements-hashes.txt" ]; then echo " ✓ requirements-hashes.txt exists"; else echo " ✗ Missing (run: just lock-hashes)"; fi
@echo ""
@echo "✅ Ruff security linting:"
@echo " Rules: S105 (hardcoded secrets), S301 (pickle), S608 (SQL injection)"
@echo " Run: ruff check --select S src/ scripts/"
@echo ""
@echo "✅ Pip-audit integration:"
@echo " Run: just audit-hashes (checks against OSV database)"
@echo ""
@echo "✅ GitHub Actions:"
@if [ -f ".github/workflows/security.yml" ]; then echo " ✓ Security workflow configured"; else echo " ✗ Missing"; fi
@echo ""
@echo "✅ Time-based constraints:"
@echo " Run: just install-safe <days>"
@echo " Example: just install-safe 7 (packages from 7+ days ago)"
@echo ""
@echo "📖 Learn more: https://bernat.tech/posts/securing-python-supply-chain/"
# Lint TOML files
check-toml:
@echo "🔍 Checking TOML files..."
mise exec -- uv run tombi lint pyproject.toml
# Format TOML files
format-toml:
@echo "✨ Formatting TOML files..."
mise exec -- uv run tombi format pyproject.toml
# Run all code quality checks
check: lint format-check type-check audit-hashes check-toml
@echo "✅ All code quality checks passed!"
# Fix and format all code issues
fix: lint-fix format format-toml
@echo "✅ Code fixed and formatted!"
# Legacy lint command (for backward compatibility)
lint-legacy:
@echo "🔍 Running legacy lint script..."
mise exec -- uv run familybot-lint
# === DEVELOPMENT TASKS ===
# Set up pre-commit hooks
setup-precommit:
@echo "🪝 Setting up pre-commit hooks..."
mise exec -- uv run familybot-setup-precommit
@echo "✅ Pre-commit hooks installed"
# Run pre-commit style checks
pre-commit: check
@echo "✅ Pre-commit checks completed"
# Create a new release (used by bump-* commands)
release version_type='patch':
@echo "🚀 Creating a '{{ version_type }}' release..."
mise exec -- uv run python scripts/release.py '{{ version_type }}'
# Bumps and creates a new patch release (e.g., 1.0.0 -> 1.0.1)
bump-patch:
@just release 'patch'
# Bumps and creates a new minor release (e.g., 1.0.0 -> 1.1.0)
bump-minor:
@just release 'minor'
# Bumps and creates a new major release (e.g., 1.0.0 -> 2.0.0)
bump-major:
@just release 'major'
# Check for outdated Python dependencies
check-updates:
@echo "🔍 Running smart update checker..."
mise exec -- uv run python scripts/check_updates.py
# === UTILITY TASKS ===
# View real-time logs
logs:
@echo "📋 Viewing FamilyBot logs (Ctrl+C to exit)..."
@if [ -f "logs/familybot.log" ]; then tail -f logs/familybot.log; else echo "❌ Log file not found. Run the bot first."; fi
# View error logs
logs-errors:
@echo "📋 Viewing error logs (Ctrl+C to exit)..."
@if [ -f "logs/familybot_errors.log" ]; then tail -f logs/familybot_errors.log; else echo "❌ Error log file not found."; fi
# Check bot status and configuration
status:
@echo "📊 FamilyBot Status:"
@echo "==================="
@echo "Virtual environment: $(if [ -d '.venv' ]; then echo '✅ Present'; else echo '❌ Missing'; fi)"
@echo "Config file: $(if [ -f 'config.yml' ]; then echo '✅ Present'; else echo '❌ Missing (use config-template.yml)'; fi)"
@echo "Browser profile: $(if [ -d 'FamilyBotBrowserProfile' ]; then echo '✅ Present'; else echo '❌ Missing (run just setup-browser)'; fi)"
@echo "Database: $(if [ -f 'bot_data.db' ]; then echo '✅ Present'; else echo '❌ Missing (run just populate-db)'; fi)"
# === CLEANUP TASKS ===
# Clean Python cache files
clean-cache:
@echo "🧹 Cleaning Python cache files..."
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
@echo "✅ Python cache cleaned"
# Clean virtual environment
clean-venv:
@echo "🧹 Removing virtual environment..."
rm -rf .venv
@echo "✅ Virtual environment removed"
# Clean logs
clean-logs:
@echo "🧹 Cleaning log files..."
rm -rf logs/*.log logs/scripts/*.log 2>/dev/null || true
@echo "✅ Log files cleaned"
# Clean all generated files
clean-all: clean-cache clean-venv clean-logs
@echo "🧹 Cleaning all generated files..."
rm -rf *.egg-info build/ dist/ 2>/dev/null || true
@echo "✅ All generated files cleaned"
# === MIGRATION HELPERS ===
# Migrate from legacy scripts to just
migrate-from-legacy:
@echo "🔄 Migration guide from legacy scripts:"
@echo "======================================"
@echo "Old command → New command"
@echo ".\reinstall_bot.ps1 → just reinstall"
@echo ".\run_bots.ps1 → just run"
@echo ".\purge_cache.ps1 → just purge-cache"
@echo ".\purge_all_cache.ps1 → just purge-all-cache"
@echo "uv run familybot-lint → just lint"
@echo ""
@echo "💡 Run 'just --list' to see all available commands"
# Show installation instructions for just
install-just-help:
@echo "📦 Installing 'just' command runner:"
@echo "==================================="
@echo "Windows (Scoop): scoop install just"
@echo "Windows (Chocolatey): choco install just"
@echo "Windows (Cargo): cargo install just"
@echo "macOS (Homebrew): brew install just"
@echo "Linux (Cargo): cargo install just"
@echo "Linux (Package manager): Check your distro's package manager"
@echo ""
@echo "💡 After installation, run 'just setup' to get started"
# === HELP AND INFORMATION ===
# Show detailed help
help:
@echo "🤖 FamilyBot Task Runner Help"
@echo "============================"
@echo ""
@echo "Quick Start:"
@echo " just setup # Complete setup"
@echo " just run # Start the bot"
@echo ""
@echo "Common Tasks:"
@echo " just lint # Check code quality"
@echo " just format # Format code"
@echo " just populate-db # Set up database"
@echo " just purge-cache # Clear cache"
@echo ""
@echo "For full command list: just --list"
@echo "For migration help: just migrate-from-legacy"
@echo "For just installation: just install-just-help"