-
Notifications
You must be signed in to change notification settings - Fork 0
/
Justfile
70 lines (58 loc) · 3.69 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
set dotenv-load
set positional-arguments
export AWS_PAGER := ""
difftool := env_var_or_default("DIFFTOOL", "diff -u")
schedules_key := "data/schedules.json"
local_schedules_file := "frontend/local/" + schedules_key
upload_data_args := '--output-s3-bucket "$S3_BUCKET" --output-s3-key ' + quote(schedules_key) + ' --invalidate-cloudfront-distribution-id "$CLOUDFRONT_DISTRIBUTION_ID"'
normalize_data_jq := '.
| sort_by(.terminal_pair.from + .terminal_pair.to + .date_range.from + .date_range.to)
| .[].items |= sort_by(.sailing.depart_time + .sailing.arrive_time + (.sailing | tostring))
| (.. | .refreshed_at? | select(. != null)) |= null
| (.. | .Only? | select(. != null)) |= sort
| (.. | .Except? | select(. != null)) |= sort'
help:
@{{ just_executable() }} --list
check:
cargo test
cargo clippy -- -D warnings
cargo fmt -- --check
fix="$(git grep -I -i '@[@]@\|%[%]%\|F[I]XME\|d[b]g!\|p[r]intln!\|u[n]implemented!')"; test "$fix" = "" || (echo "\nFIX COMMENTS:\n$fix\n" >&2; false)
dirty="$(git status . --short)"; test "$dirty" = "" || (echo "\nDIRTY FILES:\n$dirty\n" >&2; false)
@echo "\nChecks passed."
local-frontend:
@if ! test -f {{ quote(local_schedules_file) }}; then echo "\nLocal data not found; run 'just local-data' to scrape it.\n"; false; fi
cd frontend && trunk serve
local-data *args:
mkdir -p {{ quote(parent_directory(local_schedules_file)) }}
cargo run --bin ferrysched_scraper -- \
--output-file {{ quote(local_schedules_file) }} \
"$@"
upload-frontend:
mkdir -p {{ quote(parent_directory(local_schedules_file)) }}
cd frontend && trunk build --release --dist dist-release
@# Work around for the fact that CloudFront does not support auto-compressing wasm files
wasm="$(ls frontend/dist-release/*.wasm)"; gzip "$wasm" && mv "$wasm.gz" "$wasm"
aws s3 sync frontend/dist-release/ "s3://$S3_BUCKET/" --acl public-read --delete --exclude "data/*" --exclude "*.wasm" --exclude "*.html" --cache-control max-age=7776000,public
aws s3 sync frontend/dist-release/ "s3://$S3_BUCKET/" --acl public-read --delete --exclude "*" --include "*.wasm" --cache-control max-age=7776000,public --content-encoding gzip --content-type application/wasm
aws s3 sync frontend/dist-release/ "s3://$S3_BUCKET/" --acl public-read --delete --exclude "*" --include "*.html" --cache-control max-age=43200,public
aws cloudfront create-invalidation --distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" --paths "/*"
upload-data *args:
cargo run --bin ferrysched_scraper -- {{ upload_data_args }} "$@"
upload-data-with-bin bin *args:
shift; {{ quote(bin) }} {{ upload_data_args }} "$@"
compare-data: local-data
mkdir -p tmp
aws s3 cp "s3://$S3_BUCKET/"{{ quote(schedules_key) }} tmp/compare_old_data_unformatted.json
jq --sort-keys {{ quote(normalize_data_jq) }} < tmp/compare_old_data_unformatted.json >tmp/compare_old_data.json
jq --sort-keys {{ quote(normalize_data_jq) }} <{{ quote(local_schedules_file) }} >tmp/compare_new_data.json
{{ difftool }} tmp/compare_old_data.json tmp/compare_new_data.json
scraper-coverage:
# See https://blog.rng0.io/how-to-do-code-coverage-in-rust
mkdir -p tmp
CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='scraper-coverage-%p-%m.profraw' just local-data
mkdir -p target/coverage/html
grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/html
grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/scraper.lcov
clean:
rm -rf frontend/dist/ frontend/dist-release/ frontend/local/ target/ tmp/