-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
justfile
198 lines (155 loc) · 7.1 KB
/
justfile
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
# List available recipes
list:
@just --list --justfile {{ source_file() }}
fmt_flags := '--all'
# Run formatter
fmt *FLAGS:
cargo +nightly fmt {{ fmt_flags }} {{ FLAGS }}
check_flags := '--all-targets'
v2_lints:= '-D warnings -Aunused -Aclippy::todo -Aclippy::diverging_sub_expression'
alias c := check
# Check compilation of Rust code and catch common mistakes
# We cannot run --all-features because v1 and v2 are mutually exclusive features
# Create a list of features by excluding certain features
clippy *FLAGS:
#! /usr/bin/env bash
set -euo pipefail
FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \
jq -r '
[ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
| .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
| del( .[] | select( any( . ; test("(([a-z_]+)_)?v2") ) ) ) # Exclude some features from features list
| join(",") # Construct a comma-separated string of features for passing to `cargo`
')"
set -x
cargo clippy {{ check_flags }} --features "${FEATURES}" {{ FLAGS }}
set +x
clippy_v2 *FLAGS:
#! /usr/bin/env bash
set -euo pipefail
FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \
jq -r '
[ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
| .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
| del( .[] | select( . == ("default", "v1") ) ) # Exclude some features from features list
| join(",") # Construct a comma-separated string of features for passing to `cargo`
')"
set -x
cargo clippy {{ check_flags }} --no-default-features --features "${FEATURES}" -- {{ v2_lints }} {{ FLAGS }}
set +x
check_v2 *FLAGS:
#! /usr/bin/env bash
set -euo pipefail
FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \
jq -r '
[ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
| .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
| del( .[] | select( . == ("default", "v1") ) ) # Exclude some features from features list
| join(",") # Construct a comma-separated string of features for passing to `cargo`
')"
set -x
cargo check {{ check_flags }} --no-default-features --features "${FEATURES}" -- {{ FLAGS }}
set +x
run_v2:
#! /usr/bin/env bash
set -euo pipefail
FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \
jq -r '
[ .packages[] | select(.name == "router") | .features | keys[] # Obtain features of `router` package
| select( any( . ; test("(([a-z_]+)_)?v2") ) ) ] # Select v2 features
| join(",") # Construct a comma-separated string of features for passing to `cargo`
')"
set -x
cargo run --package router --no-default-features --features "${FEATURES}"
set +x
check *FLAGS:
#! /usr/bin/env bash
set -euo pipefail
FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \
jq -r '
[ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array
| .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates
| del( .[] | select( any( . ; test("(([a-z_]+)_)?v2") ) ) ) # Exclude some features from features list
| join(",") # Construct a comma-separated string of features for passing to `cargo`
')"
set -x
cargo check {{ check_flags }} --features "${FEATURES}" {{ FLAGS }}
set +x
alias cl := clippy
# Build binaries
build *FLAGS:
cargo build {{ FLAGS }}
alias b := build
# Build release (optimized) binaries
build-release *FLAGS:
cargo build --release --features release {{ FLAGS }}
alias br := build-release
# Run server
run *FLAGS:
cargo run {{ FLAGS }}
alias r := run
doc_flags := '--all-features --all-targets --exclude-features "v2"'
# Generate documentation
doc *FLAGS:
cargo doc {{ doc_flags }} {{ FLAGS }}
alias d := doc
# Build the `euclid_wasm` crate
euclid-wasm features='dummy_connector':
wasm-pack build \
--target web \
--out-dir {{ source_directory() }}/wasm \
--out-name euclid \
{{ source_directory() }}/crates/euclid_wasm \
--features '{{ features }}'
# Run pre-commit checks
precommit: fmt clippy
# Use the env variables if present, or fallback to default values
db_user := env_var_or_default('DB_USER', 'db_user')
db_password := env_var_or_default('DB_PASSWORD', 'db_pass')
db_host := env_var_or_default('DB_HOST', 'localhost')
db_port := env_var_or_default('DB_PORT', '5432')
db_name := env_var_or_default('DB_NAME', 'hyperswitch_db')
default_db_url := 'postgresql://' + db_user + ':' + db_password + '@' + db_host + ':' + db_port / db_name
database_url := env_var_or_default('DATABASE_URL', default_db_url)
default_migration_params := ''
v2_migration_dir := source_directory() / 'v2_migrations'
v1_migration_dir := source_directory() / 'migrations'
resultant_dir := source_directory() / 'final-migrations'
# Copy v1 and v2 migrations to a single directory
[private]
copy_migrations:
@mkdir -p {{ resultant_dir }}
@cp -r {{ v1_migration_dir }}/. {{ v2_migration_dir }}/. {{ resultant_dir }}/
echo "Created {{ resultant_dir }}"
# Delete the newly created directory
[private]
delete_dir_if_exists dir=resultant_dir:
@rm -rf {{ dir }}
v1_config_file_dir := source_directory() / 'diesel.toml'
default_operation := 'run'
[private]
run_migration operation=default_operation migration_dir=v1_migration_dir config_file_dir=v1_config_file_dir url=database_url *other_params=default_migration_params:
diesel migration \
--database-url '{{ url }}' \
{{ operation }} \
--migration-dir '{{ migration_dir }}' \
--config-file '{{ config_file_dir }}' \
{{ other_params }}
# Run database migrations for v1
migrate operation=default_operation *args='': (run_migration operation v1_migration_dir v1_config_file_dir database_url args)
v2_config_file_dir := source_directory() / 'diesel_v2.toml'
# Run database migrations for v2
migrate_v2 operation=default_operation *args='':
#! /usr/bin/env bash
set -euo pipefail
EXIT_CODE=0
just copy_migrations
just run_migration {{ operation }} {{ resultant_dir }} {{ v2_config_file_dir }} {{ database_url }} {{ args }} || EXIT_CODE=$?
just delete_dir_if_exists
exit $EXIT_CODE
# Drop database if exists and then create a new 'hyperswitch_db' Database
resurrect database_name='hyperswitch_db':
psql -U postgres -c 'DROP DATABASE IF EXISTS {{ database_name }}';
psql -U postgres -c 'CREATE DATABASE {{ database_name }}';
ci_hack:
scripts/ci-checks.sh