-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
126 lines (100 loc) · 4.55 KB
/
Copy pathJustfile
File metadata and controls
126 lines (100 loc) · 4.55 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
set dotenv-load := true
# Local development runs in Django debug mode by default. The app now fails closed
# (DEBUG=False) when DJANGO_DEBUG is unset, so opt in here for the SQLite/dev-secret
# local workflow. An explicit DJANGO_DEBUG in the environment or .env still wins.
export DJANGO_DEBUG := env_var_or_default("DJANGO_DEBUG", "1")
dev_db := env_var_or_default("GOGGLES_DEV_DB", "var/goggles-dev.sqlite3")
database_url := "sqlite:///" + justfile_directory() + "/" + dev_db
port := env_var_or_default("GOGGLES_DEV_PORT", "8000")
test_db_port := env_var_or_default("GOGGLES_TEST_DB_PORT", "55432")
test_database_url := env_var_or_default("GOGGLES_TEST_DATABASE_URL", "postgres://goggles:goggles@127.0.0.1:" + test_db_port + "/goggles_test")
python := "uv run python"
alias run := dev
alias reset := reset-db
# Show available commands.
default:
@just --list
# Install or update local Python dependencies.
sync:
uv sync
# Install locked dependencies exactly as GitHub Actions does.
sync-frozen:
uv sync --frozen
# Apply migrations to the durable local development database.
migrate: _dev-db-dir
DATABASE_URL='{{database_url}}' {{python}} manage.py migrate
# Create Django migrations from model changes.
makemigrations:
{{python}} manage.py makemigrations
# Fail if model changes need migrations.
check-migrations:
{{python}} manage.py makemigrations --check --dry-run
# Run Django's system checks.
django-check:
{{python}} manage.py check
# Seed admin/pass123 and sample audit-log data into the dev database.
seed: migrate
DATABASE_URL='{{database_url}}' {{python}} manage.py seed_dev
# Delete, recreate, migrate, and seed the durable local development database.
reset-db: _dev-db-dir
rm -f '{{justfile_directory()}}/{{dev_db}}' '{{justfile_directory()}}/{{dev_db}}-shm' '{{justfile_directory()}}/{{dev_db}}-wal'
DATABASE_URL='{{database_url}}' {{python}} manage.py migrate
DATABASE_URL='{{database_url}}' {{python}} manage.py seed_dev
# Run the Django dev server against the durable local development database.
dev: migrate
@echo 'Goggles dev: http://127.0.0.1:{{port}}'
@echo 'Seeded login: admin / pass123'
DATABASE_URL='{{database_url}}' {{python}} manage.py runserver 127.0.0.1:{{port}}
# Create a reusable upload bearer token in the durable local development
# database. Pass extra flags through, e.g. `just token "ios qa" --expires-in-days 30`.
token name *args: migrate
DATABASE_URL='{{database_url}}' {{python}} manage.py create_upload_token "{{name}}" {{args}}
# Delete audit uploads, events, groups, projections, and saved reports while
# preserving users and upload tokens. Pass `--dry-run` first, then
# `--confirm-delete-audit-data` when performing the deployment cutover.
purge-audit-data *args: migrate
DATABASE_URL='{{database_url}}' {{python}} manage.py purge_audit_data {{args}}
# Open a Django shell against the durable local development database.
shell: migrate
DATABASE_URL='{{database_url}}' {{python}} manage.py shell
# Validate JSONL audit events against the committed V2 schema.
validate-schema *paths:
{{python}} manage.py validate_audit_schema {{paths}}
# Run the Django test suite.
test:
{{python}} manage.py test
# Run the Django test suite against a disposable Postgres service.
test-postgres:
#!/usr/bin/env bash
set -euo pipefail
GOGGLES_ENV_FILE='.env.example' GOGGLES_TEST_DB_PORT='{{test_db_port}}' docker compose up -d --wait db-test
trap "GOGGLES_ENV_FILE='.env.example' GOGGLES_TEST_DB_PORT='{{test_db_port}}' docker compose rm -sf db-test >/dev/null" EXIT
DATABASE_URL='{{test_database_url}}' {{python}} manage.py test
# Run Ruff checks.
lint:
uv run ruff check .
# Audit the locked dependency set.
audit-dependencies:
#!/usr/bin/env bash
set -euo pipefail
requirements_file="$(mktemp)"
trap 'rm -f "$requirements_file"' EXIT
uv export --locked --all-groups --format requirements-txt -o "$requirements_file"
uv run --with pip-audit==2.10.0 pip-audit \
-r "$requirements_file" \
--strict \
--require-hashes \
--disable-pip \
--progress-spinner off
# Format Python code with Ruff.
format:
uv run ruff format .
# Fail if Python code is not formatted with Ruff.
format-check:
uv run ruff format --check .
# Run the normal local verification suite.
check: test django-check lint format-check check-migrations
# Run the same push/PR checks as GitHub Actions.
ci: sync-frozen test test-postgres django-check lint format-check check-migrations audit-dependencies
_dev-db-dir:
@mkdir -p "$(dirname '{{justfile_directory()}}/{{dev_db}}')"