-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathjustfile
More file actions
executable file
·186 lines (163 loc) · 6.69 KB
/
Copy pathjustfile
File metadata and controls
executable file
·186 lines (163 loc) · 6.69 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
#!/usr/bin/env just --justfile
mod cpp
mod java
mod rust
mod ts
just := quote(just_executable())
ci_mode := if env('CI', '') != '' {'1'} else {''}
# By default, show the list of all available commands
@_default:
{{just}} --list --list-submodules
bench:
{{just}} rust::bench
{{just}} java::bench
{{just}} ts::bench
# Run integration tests, and override what we expect the output to be with the actual output
bless: _clean-int-test _test-run-int
{{just}} rust::bless
rm -rf test/expected && mv test/output test/expected
# Delete all build files for multiple languages
clean:
{{just}} rust::clean
{{just}} java::clean
{{just}} ts::clean
{{just}} cpp::clean
# Run all formatting in every language
fmt:
{{just}} rust::fmt
{{just}} java::fmt
{{just}} ts::fmt
{{just}} cpp::fmt
# Run linting in every language. Run `just fmt` to fix formatting issues.
lint:
{{just}} rust::lint
{{just}} java::lint
{{just}} ts::lint
{{just}} cpp::lint
# Run all tests in every language, including integration tests
test: test-int
{{just}} rust::test
{{just}} java::test
{{just}} ts::test
{{just}} cpp::test
# Run integration tests, ensuring that the output matches the expected output
test-int: _clean-int-test _test-run-int (_diff-dirs "test/output" "test/expected")
docs:
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs zensical/zensical:latest
docs-build:
docker run --rm -v ${PWD}:/docs zensical/zensical:latest build
# Extract version from a tag by removing language prefix and 'v' prefix
ci-extract-version language tag:
@echo "{{replace(replace(tag, language + '-', ''), 'v', '')}}"
# Run the mlt CLI tool with the given arguments from current dir.
[no-cd]
[positional-arguments] # avoids shell expansions
mlt *args:
cargo run --manifest-path {{join(justfile_directory(), 'rust', 'Cargo.toml')}} --package mlt -- "$@"
# Run the mlt CLI tool with the given arguments from current dir.
[no-cd]
[positional-arguments] # avoids shell expansions
mlt-rel *args:
cargo run --release --manifest-path {{join(justfile_directory(), 'rust', 'Cargo.toml')}} --package mlt -- "$@"
# Ensure a command is available
assert-cmd command:
#!/usr/bin/env bash
set -euo pipefail
if ! type {{command}} > /dev/null; then
echo "Command '{{command}}' could not be found. Please make sure it has been installed on your computer."
exit 1
fi
# Install a Cargo tool if missing (uses cargo-binstall when available)
cargo-install $COMMAND $INSTALL_CMD='' *args='':
#!/usr/bin/env bash
set -euo pipefail
unset CARGO_BUILD_WARNINGS
binstall_args="{{ if env('CI', '') != '' {'--no-confirm --no-track --disable-telemetry'} else {''} }}"
if ! command -v $COMMAND > /dev/null; then
if ! command -v cargo-binstall > /dev/null; then
echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}"
cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}
else
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} $binstall_args --locked"
cargo binstall ${INSTALL_CMD:-$COMMAND} $binstall_args --locked
fi
fi
# Install the pmtiles CLI and Python pmtiles library (needed by download-benchmark-tiles)
install-pmtiles:
#!/usr/bin/env bash
set -euo pipefail
if ! command -v pmtiles > /dev/null; then
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS-$ARCH" in
linux-x86_64) SUFFIX="Linux_x86_64" ;;
linux-aarch64) SUFFIX="Linux_arm64" ;;
darwin-x86_64) SUFFIX="Darwin_x86_64" ;;
darwin-arm64) SUFFIX="Darwin_arm64" ;;
*) echo "Unsupported platform: $OS-$ARCH"; exit 1 ;;
esac
AUTH=()
if [ -n "${GITHUB_TOKEN:-}" ]; then
AUTH=(-H "Authorization: Bearer ${GITHUB_TOKEN}")
fi
ASSET_URL=$(curl -sSf "${AUTH[@]}" https://api.github.com/repos/protomaps/go-pmtiles/releases/latest | \
jq -r ".assets[] | select(.name | test(\"${SUFFIX}\")) | .browser_download_url")
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
echo "Could not find pmtiles release for $SUFFIX"; exit 1
fi
curl -sSfL "$ASSET_URL" | sudo tar -xz -C /usr/local/bin pmtiles
fi
echo "pmtiles: $(pmtiles version)"
pip install --break-system-packages pmtiles 2>/dev/null \
|| pip install pmtiles
# Make sure the git repo has no uncommitted changes. Fails only if CI envvar is set.
assert-git-is-clean:
#!/usr/bin/env bash
set -euo pipefail
if [ -n "$(git status --porcelain --untracked-files=all)" ]; then
>&2 echo "::error::git repo is not clean. Make sure compilation and tests artifacts are in the .gitignore, and no repo files are modified."
if [[ "{{ci_mode}}" == "1" ]]; then
>&2 echo "::group::git status"
git status
>&2 echo "::endgroup::"
>&2 echo "::group::git diff (tracked changes)"
git add . --intent-to-add
git --no-pager diff
>&2 echo "::endgroup::"
exit 1
else
>&2 echo "git repo is not clean, but not failing because CI mode is not enabled."
fi
fi
_clean-int-test:
rm -rf test/output && mkdir -p test/output
_diff-dirs OUTPUT_DIR EXPECTED_DIR:
#!/usr/bin/env bash
set -euo pipefail
echo "** Comparing {{OUTPUT_DIR}} with {{EXPECTED_DIR}}..."
if ! diff --brief --recursive --new-file {{OUTPUT_DIR}} {{EXPECTED_DIR}}; then
echo "** Expected output does not match actual output"
echo "** You may want to run 'just bless' to update expected output"
exit 1
else
echo "** Expected output matches actual output"
fi
_test-run-int:
echo "TODO: Add integration test command, outputting to test/output"
echo "fake output by copying expected into output so that the rest of the script works"
# TODO: REMOVE THIS, and replace it with a real integration test run
cp -r test/expected/* test/output
# Ensure there are no duplicate synthetic MLT files by comparing their hashes.
_assert-all-mlt-files-different dir='test/synthetic':
#!/usr/bin/env bash
set -euo pipefail
all_hashes=$(find {{quote(dir)}} -name '*.mlt' -exec sha256sum {} \; | sort)
duplicates=$(echo "$all_hashes" | awk '{print $1}' | uniq -d)
if [ -n "$duplicates" ]; then
echo "::error::Duplicate synthetic MLT files found"
while IFS= read -r hash; do
echo ""
echo "$all_hashes" | grep "^$hash " | awk '{print " - " $2}'
done <<< "$duplicates"
exit 1
fi