forked from cncf/gitjobs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
143 lines (112 loc) · 4.97 KB
/
Copy pathjustfile
File metadata and controls
143 lines (112 loc) · 4.97 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
# GitJobs - Development Tasks
#
# Configuration: Set these environment variables.
#
# Optional (with defaults):
# GITJOBS_CONFIG - Path to config directory (default: $HOME/.config/gitjobs)
# GITJOBS_DB_HOST - Database host or unix socket path (default: localhost)
# GITJOBS_DB_NAME - Main database name (default: gitjobs)
# GITJOBS_DB_NAME_TESTS - Test database name (default: gitjobs_tests)
# GITJOBS_DB_PORT - Database port (default: 5432)
# GITJOBS_DB_USER - Database user (default: postgres)
# GITJOBS_PG_BIN - Path to PostgreSQL binaries
# (default: /opt/homebrew/opt/postgresql@17/bin)
#
# Please set up tern config files (`tern.conf` and `tern-tests.conf`) in
# `GITJOBS_CONFIG` with connection settings matching these variables.
# Configuration
config_dir := env("GITJOBS_CONFIG", env_var("HOME") / ".config/gitjobs")
db_host := env("GITJOBS_DB_HOST", "localhost")
db_name := env("GITJOBS_DB_NAME", "gitjobs")
db_name_tests := env("GITJOBS_DB_NAME_TESTS", "gitjobs_tests")
db_port := env("GITJOBS_DB_PORT", "5432")
db_server_host_opt := if db_host =~ '^/' { "-k " + db_host } else { "-h " + db_host }
db_user := env("GITJOBS_DB_USER", "postgres")
pg_bin := env("GITJOBS_PG_BIN", "/opt/homebrew/opt/postgresql@17/bin")
pg_conn := "-h " + db_host + " -p " + db_port + " -U " + db_user
source_dir := justfile_directory()
# Helper to run PostgreSQL commands with the configured binary path.
[private]
pg command *args:
PATH="{{ pg_bin }}:$PATH" {{ command }} {{ args }}
# Database
# Connect to main database.
db-client:
just pg psql {{ pg_conn }} {{ db_name }}
# Connect to test database.
db-client-tests:
just pg psql {{ pg_conn }} {{ db_name_tests }}
# Create main database.
db-create:
just pg createdb {{ pg_conn }} {{ db_name }}
# Create test database with pgtap extension.
db-create-tests:
just pg createdb {{ pg_conn }} {{ db_name_tests }}
PATH="{{ pg_bin }}:$PATH" psql {{ pg_conn }} {{ db_name_tests }} -c "CREATE EXTENSION IF NOT EXISTS pgtap"
# Drop main database.
db-drop:
just pg dropdb {{ pg_conn }} --if-exists --force {{ db_name }}
# Drop test database.
db-drop-tests:
just pg dropdb {{ pg_conn }} --if-exists --force {{ db_name_tests }}
# Initialize PostgreSQL data directory.
db-init data_dir:
mkdir -p "{{ data_dir }}"
just pg initdb -U {{ db_user }} "{{ data_dir }}"
# Load e2e seed data into main database.
db-load-e2e-data:
just pg psql {{ pg_conn }} {{ db_name }} -f "{{ source_dir }}/database/tests/data/e2e.sql"
# Run migrations on main database.
db-migrate:
cd "{{ source_dir }}/database/migrations" && TERN_CONF="{{ config_dir }}/tern.conf" ./migrate.sh
# Run migrations on test database.
db-migrate-tests:
cd "{{ source_dir }}/database/migrations" && TERN_CONF="{{ config_dir }}/tern-tests.conf" ./migrate.sh
# Drop, create, and migrate main database.
db-recreate: db-drop db-create db-migrate
# Drop, create, and migrate test database.
db-recreate-tests: db-drop-tests db-create-tests db-migrate-tests
# Run database tests (recreates test db and runs pgTAP tests).
db-tests: db-recreate-tests
pg_prove -h {{ db_host }} -p {{ db_port }} -d {{ db_name_tests }} -U {{ db_user }} --psql-bin {{ pg_bin }}/psql -v $(find "{{ source_dir }}/database/tests/schema" "{{ source_dir }}/database/tests/functions" -type f -name '*.sql' | sort)
# Run database tests on a specific file.
db-tests-file file: db-migrate-tests
pg_prove -h {{ db_host }} -p {{ db_port }} -d {{ db_name_tests }} -U {{ db_user }} --psql-bin {{ pg_bin }}/psql -v {{ file }}
# Start PostgreSQL server.
db-server data_dir:
just pg postgres -D "{{ data_dir }}" -p {{ db_port }} {{ db_server_host_opt }}
# Server
# Run the server using cargo run (builds if needed).
server:
cargo run -p gitjobs-server -- --config-file "{{ config_dir }}/server.yml"
# Build the server binary.
server-build:
cargo build -p gitjobs-server
# Format and lint server code.
server-fmt-and-lint:
cargo fmt
cargo check
cargo clippy --all-targets --all-features -- --deny warnings
# Run server tests.
server-tests:
cargo test
# Run the server with cargo watch for auto-reload.
server-watch:
cargo watch -x "run -p gitjobs-server -- --config-file {{ config_dir }}/server.yml"
# Syncer
# Run the syncer using cargo run (builds if needed).
syncer:
cargo run -p gitjobs-syncer -- --config-file "{{ config_dir }}/syncer.yml"
# Build the syncer binary.
syncer-build:
cargo build -p gitjobs-syncer
# Run the syncer with cargo watch for auto-reload.
syncer-watch:
cargo watch -x "run -p gitjobs-syncer -- --config-file {{ config_dir }}/syncer.yml"
# Frontend
e2e-tests *args:
npx playwright test --config tests/e2e/playwright.config.ts {{ args }}
# Format and lint frontend code.
frontend-fmt-and-lint:
prettier --config gitjobs-server/static/js/.prettierrc.yaml --write "gitjobs-server/static/js/**/*.js"
djlint --check --configuration gitjobs-server/templates/.djlintrc gitjobs-server/templates