-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjustfile
More file actions
202 lines (159 loc) · 7.25 KB
/
justfile
File metadata and controls
202 lines (159 loc) · 7.25 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# OpenApi Client CLI
OPENAPI_GENERATOR_CLI := "npx @openapitools/openapi-generator-cli --openapitools .generation/openapitools.json"
_default:
@just --list
# Clear the terminal before executing a command. Does not fail in a CI.
_clear:
@-clear
# Build all API clients by executing the build steps for each language.
[group('build')]
build: _clear _build-python-preprocess _build-rust-preprocess _build-typescript-preprocess _build_call _build-python-postprocess _build-rust-postprocess _build-typescript-postprocess
_build_call generator="":
{{ OPENAPI_GENERATOR_CLI }} generate {{ if generator == "" { "" } else { "--generator-key " + generator } }}
# Build the API clients for Python by generating code with the OpenAPI Generator and applying post-processing steps.
[group('build')]
build-python: _clear _build-python-preprocess (_build_call "python") _build-python-postprocess
# Remove some directories because they are not be overwritten by the generator.
_build-python-preprocess:
rm -rf \
python/geoengine_openapi_client \
python/.mypy_cache \
python/test \
python/diffs
_build-python-postprocess:
.generation/post-process/python.py
rm -rf \
python/docs \
python/git_push.sh \
python/.travis.yml \
python/.gitlab-ci.yml \
python/.github
# Build the API clients for TypeScript by generating code with the OpenAPI Generator and applying post-processing steps. Also install npm dependencies and set up .gitignore.
[group('build')]
build-typescript: _clear _build-typescript-preprocess (_build_call "typescript") _build-typescript-postprocess
# Remove some directories because they are not be overwritten by the generator.
_build-typescript-preprocess:
rm -rf \
typescript/src \
typescript/docs \
typescript/dist \
typescript/node_modules \
typescript/diffs
_build-typescript-postprocess:
.generation/post-process/typescript.py
echo "wwwroot/*.js" > typescript/.gitignore
echo "node_modules" > typescript/.gitignore
echo "typings" > typescript/.gitignore
cd typescript && npm install
rm \
typescript/.openapi-generator/FILES \
package-lock.json
# Build the API clients for Rust by generating code with the OpenAPI Generator and applying post-processing steps.
[group('build')]
build-rust: _clear _build-rust-preprocess (_build_call "rust") _build-rust-postprocess
_build-rust-preprocess:
rm -rf \
rust/src/apis \
rust/src/models \
rust/docs \
rust/diffs
_build-rust-postprocess:
.generation/post-process/rust.py
rm -rf \
rust/git_push.sh \
rust/.travis.yml
[group('config')]
lint-openapi-spec: _clear
{{ OPENAPI_GENERATOR_CLI }} validate \
-i .generation/input/openapi.json \
--recommend
# Generate the OpenAPI Generator configuration files from the config.ini.
[group('config')]
[script("python3")]
update-generator-configs:
import configparser
import json
config = configparser.ConfigParser()
config.optionxform = str # do not convert keys to lowercase
config.read('.generation/config.ini')
with open('.generation/openapitools.json', 'r', encoding='utf-8') as f:
generator_config = json.load(f)
spaces = generator_config['spaces']
generators = generator_config['generator-cli']['generators']
for generator in ['typescript', 'python', 'rust']:
generators[generator]['gitHost'] = config['git']['host']
generators[generator]['gitUserId'] = config['git']['user']
generators[generator]['gitRepoId'] = config['git']['repo']
repository_url = f"https://{config['git']['host']}/{config['git']['user']}/{config['git']['repo']}"
generators['typescript']['additionalProperties']['npmVersion'] = config['general']['version']
generators['python']['additionalProperties']['packageVersion'] = config['general']['version']
generators['python']['additionalProperties']['packageUrl'] = repository_url
generators['rust']['additionalProperties']['packageVersion'] = config['general']['version']
generators['rust']['additionalProperties']['homePageUrl'] = config['general']['homepageUrl']
generators['rust']['additionalProperties']['repositoryUrl'] = repository_url
with open('.generation/openapitools.json', 'w', encoding='utf-8') as f:
json.dump(generator_config, f, indent=spaces)
print("Generated OpenAPI Generator configuration for TypeScript, Python, and Rust.")
# Update the backend commit in the config.ini and increment the version.
[arg("backendCommit", long="backendCommit", help="The commit hash of the backend for which to fetch the OpenAPI specification.")]
[group('config')]
update-config backendCommit: _clear (_update-config backendCommit) update-generator-configs (fetch-openapi-spec backendCommit) lint-openapi-spec
[script("python3")]
_update-config backendCommit:
import configparser
INI_FILE = '.generation/config.ini'
config = configparser.ConfigParser()
config.optionxform = str # do not convert keys to lowercase
config.read(INI_FILE)
config['input']['backendCommit'] = "{{ backendCommit }}"
# retrieve version
version_digits: list[int] = [
int(digit) for digit in config['general']['version'].split('.')]
# increment last version digit
version_digits[-1] += 1
# write back
config['general']['version'] = '.'.join(
str(digit) for digit in version_digits)
with open(INI_FILE, 'w', encoding='utf-8') as f:
config.write(f)
print(f"Updated {INI_FILE} with backendCommit={config['input']['backendCommit']} and version={config['general']['version']}.")
# Fetch the OpenAPI specification for the given backend commit from the Geo Engine repository and save it to the input directory.
[arg("backendCommit", long="backendCommit", help="The commit hash of the backend for which to fetch the OpenAPI specification.")]
[group('config')]
fetch-openapi-spec backendCommit:
@echo "Fetching OpenAPI specification for backend commit {{ backendCommit }}…"
curl \
-o .generation/input/openapi.json \
https://raw.githubusercontent.com/geo-engine/geoengine/{{ backendCommit }}/openapi.json
# Check if there are uncommitted changes in the git repository. If there are, print an error message and exit with a non-zero status code. Otherwise, print a success message.
[group('CI')]
check-no-changes-in-git-repo:
#!/usr/bin/env bash
if [ -n "$(git status --porcelain)" ]; then
echo "Error: Uncommitted changes found in git repository."
git status --porcelain
exit 1
else
echo "No uncommitted changes found in git repository."
fi
[group('test')]
test: _clear test-python test-rust test-typescript
[group('test')]
[working-directory("python")]
test-python: _clear
#!/usr/bin/env bash
python3 -m venv .venv && source .venv/bin/activate || source .venv/bin/activate
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
pytest
[group('test')]
[working-directory("rust")]
test-rust: _clear
cargo build
cargo test
[group('test')]
[working-directory("typescript")]
test-typescript: _clear
npm install
npm run build