-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTaskfile.yml
More file actions
419 lines (360 loc) · 11.9 KB
/
Taskfile.yml
File metadata and controls
419 lines (360 loc) · 11.9 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
version: '3'
silent: true
vars:
PACKAGE_SRC_DIR: flowdapt
# Docker specific variables
DOCKER_BUILDKIT: 1
IMAGE_REGISTRY: ghcr.io
IMAGE_REPOSITORY: emergentmethods/flowdapt
IMAGE_NAME: "{{.IMAGE_REGISTRY}}/{{.IMAGE_REPOSITORY}}"
IMAGE_TAG:
sh: echo "${IMAGE_TAG:-local}"
DOCKER_BUILD_ARGS: ""
PYTHON_VERSION: 3.12
tasks:
# ---------------------
download-binary:
desc: Download a binary from GitHub releases
cmds:
- |
if [ -z "{{.REPO}}" ] || [ -z "{{.TAG}}" ] || [ -z "{{.BINARY}}" ]; then
echo "REPO TAG, and BINARY are required"
exit 1
fi
if [ -z "{{.DEBUG}}" ]; then
DEBUG="false"
else
DEBUG="{{.DEBUG}}"
fi
if [ -z "{{.EXTRACT_PATH}}" ]; then
EXTRACT_PATH="/usr/local/bin"
else
EXTRACT_PATH=$(echo "{{.EXTRACT_PATH}}" | sed 's:/*$::')
fi
if [ -z "{{.BINARY}}" ]; then
BASENAME=$(basename "{{.REPO}}")
else
BASENAME="{{.BINARY}}"
fi
if [ -z "{{.SKIP_CHECK}}" ]; then
if ! command -v $BASENAME > /dev/null; then
if [ "$DEBUG" != "false" ]; then
echo "No $BASENAME found, downloading"
fi
else
exit 0
fi
fi
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $ARCH in
x86_64)
if [ "{{.PREFER_X86}}" = "true" ]; then
ARCH="x86_64"
else
ARCH="amd64"
fi
;;
aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
# Determine whether to use curl or wget
DOWNLOAD_CMD=""
if command -v curl > /dev/null; then
DOWNLOAD_CMD="curl -s -L -o"
elif command -v wget > /dev/null; then
DOWNLOAD_CMD="wget -O"
else
if [ "$DEBUG" != "false" ]; then
echo "Neither curl nor wget is available, please install one and retry."
fi
exit 1
fi
# Fetch the release information
if [ "{{.TAG}}" = "latest" ]; then
TAG=$(curl -s "https://api.github.com/repos/{{.REPO}}/releases/latest" | grep "tag_name" | cut -d '"' -f 4)
else
TAG="{{.TAG}}"
fi
RELEASE_INFO=$(curl -s "https://api.github.com/repos/{{.REPO}}/releases/tags/$TAG")
URL=$(echo $RELEASE_INFO | grep -o '"browser_download_url": *"[^"]*"' | grep -E "${OS}_${ARCH}\.(tar\.gz|gz|zip)" | cut -d '"' -f 4)
if [ -z "$URL" ]; then
URL=$(echo $RELEASE_INFO | grep -o '"browser_download_url": *"[^"]*"' | grep -E "${OS}_${ARCH}" | cut -d '"' -f 4)
fi
# Check if a URL was found
if [ -z "$URL" ]; then
echo "Failed to find a release for tag '$TAG' with filename '$FILENAME'."
exit 1
fi
if [[ "$URL" =~ \.tar.gz$ ]]; then
FILETYPE="tar.gz"
elif [[ "$URL" =~ \.zip$ ]]; then
FILETYPE="zip"
elif [[ "$URL" =~ \.gz$ ]]; then
FILETYPE="gz"
else
FILETYPE="binary"
fi
# Construct the download URL and filename
if [ "$FILETYPE" = "binary" ]; then
FILENAME="${BASENAME}_${TAG}_${OS}_${ARCH}"
else
FILENAME="${BASENAME}_${TAG}_${OS}_${ARCH}.${FILETYPE}"
fi
# Download and extract the tar.gz file
if [ "$DEBUG" != "false" ]; then
echo "Downloading $FILENAME from $URL"
fi
$DOWNLOAD_CMD $FILENAME $URL
# Extract the binary
if [ "$DEBUG" != "false" ]; then
echo "Extracting $BASENAME to $EXTRACT_PATH"
fi
if [ "$FILETYPE" = "tar.gz" ]; then
tar -xzf $FILENAME -C . $BASENAME
elif [ "$FILETYPE" = "zip" ]; then
unzip -o $FILENAME -d . $BASENAME
elif [ "$FILETYPE" = "gz" ]; then
gunzip -c $FILENAME > $BASENAME
elif [ "$FILETYPE" = "binary" ]; then
mv $FILENAME $BASENAME
else
echo "Unsupported filetype: $FILETYPE"
exit 1
fi
# Make the binary executable
chmod +x $BASENAME
# Move the binary to the desired location
if [ "{{.CI}}" = "true" ] || [ -w $EXTRACT_PATH ] || ! command -v sudo > /dev/null; then
mv $BASENAME $EXTRACT_PATH/$BASENAME
else
sudo mv $BASENAME $EXTRACT_PATH/$BASENAME
fi
# Cleanup the downloaded tar.gz file if it exists
if [ -f $FILENAME ]; then
rm $FILENAME
fi
download-atlas:
desc: Download the atlas-cli
vars:
TAG: latest
cmds:
- |
if [ -z "{{.DEBUG}}" ]; then
DEBUG="false"
else
DEBUG="{{.DEBUG}}"
fi
if [ -z "{{.EXTRACT_PATH}}" ]; then
EXTRACT_PATH="/usr/local/bin"
else
EXTRACT_PATH=$(echo "{{.EXTRACT_PATH}}" | sed 's:/*$::')
fi
if [ -z "{{.SKIP_CHECK}}" ]; then
if ! command -v atlas > /dev/null; then
if [ "$DEBUG" != "false" ]; then
echo "No atlas found, downloading"
fi
else
exit 0
fi
fi
DOWNLOAD_CMD=""
if command -v curl > /dev/null; then
DOWNLOAD_CMD="curl -sSfL"
elif command -v wget > /dev/null; then
DOWNLOAD_CMD="wget -qO-"
else
if [ "$DEBUG" != "false" ]; then
echo "Neither curl nor wget is available, please install one and retry."
fi
exit 1
fi
$DOWNLOAD_CMD https://atlasgo.sh | CI=true sh -s -- -y --no-install -o ./atlas > /dev/null 2>&1
if [ ! -e ./atlas ]; then
echo "Failed to download atlas"
exit 1
fi
chmod +x ./atlas
# Move to the desired location
if [ "{{.CI}}" = "true" ] || [ -w $EXTRACT_PATH ] || ! command -v sudo > /dev/null; then
mv ./atlas $EXTRACT_PATH/atlas
else
sudo mv ./atlas $EXTRACT_PATH/atlas
fi
install-devtools:
desc: Install development tools
cmds:
- task: download-binary
vars:
REPO: git-chglog/git-chglog
TAG: latest
BINARY: git-chglog
- task: download-binary
vars:
REPO: caarlos0/svu
TAG: v2.2.0
BINARY: svu
build-docker:
desc: Build the Docker image
cmds:
- docker build -f Dockerfile --build-arg BUILD_VERSION={{.BUILD_VERSION}} {{.DOCKER_BUILD_ARGS}} -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}} .
version:
desc: Print the version
deps: [install-devtools]
cmds:
- svu current --strip-prefix {{.CLI_ARGS}}
next-version:
desc: Get the next version given SemVer
deps: [install-devtools]
cmds:
- |
NEXT=$(svu next --strip-prefix {{.CLI_ARGS}})
if [ -n "{{.PRE_RELEASE}}" ]; then
NEXT="$NEXT-{{.PRE_RELEASE}}"
fi
if [ -n "{{.BUILD_NUMBER}}" ]; then
NEXT="$NEXT+{{.BUILD_NUMBER}}"
fi
echo $NEXT
update-version-file:
desc: Update the version in a specified file
cmds:
- |
NEXT_VERSION="{{.NEXT_VERSION}}"
VERSION_FILE="{{.VERSION_FILE}}"
LANGUAGE="{{.LANGUAGE}}"
if [ -z "$NEXT_VERSION" ] || [ -z "$VERSION_FILE" ] || [ -z "$LANGUAGE" ]; then
echo "CURRENT_VERSION, NEXT_VERSION, VERSION_FILE and LANGUAGE are required"
exit 1
fi
if [ -z "{{.DEBUG}}" ]; then
DEBUG="false"
else
DEBUG="{{.DEBUG}}"
fi
case $LANGUAGE in
python)
VERSION_PATTERN='^version = ".*"'
NEW_VERSION_FORMAT="version = \"$NEXT_VERSION\""
;;
nodejs)
VERSION_PATTERN='^\s*"version": ".*",'
NEW_VERSION_FORMAT="\"version\": \"$NEXT_VERSION\","
;;
rust)
VERSION_PATTERN='^version = ".*"'
NEW_VERSION_FORMAT="version = \"$NEXT_VERSION\""
;;
*)
echo "Unsupported language: $LANGUAGE"
exit 1
;;
esac
# Using sed to replace the line with more precise targeting
sed -i "/$VERSION_PATTERN/c\\$NEW_VERSION_FORMAT" $VERSION_FILE
if [ "$DEBUG" != "false" ]; then
echo "Updated version in $VERSION_FILE to $NEXT_VERSION"
fi
changelog:
desc: Generate the changelog
deps: [install-devtools]
cmds:
- git-chglog {{.CLI_ARGS}}
bump-version:
desc: Bump the version
deps: [install-devtools]
cmds:
- |
CURRENT_VERSION=$(svu current --strip-prefix)
NEXT_VERSION=$(svu next --strip-prefix)
if [ "$CURRENT_VERSION" == "$NEXT_VERSION" ]; then
echo "No new version found, skipping bump"
exit 1
fi
git-chglog -o CHANGELOG.md --next-tag $NEXT_VERSION || true
git add CHANGELOG.md
if [ -n "{{.VERSION_FILE}}" ]; then
if ! task update-version-file NEXT_VERSION=$NEXT_VERSION VERSION_FILE="{{.VERSION_FILE}}" LANGUAGE="{{.LANGUAGE}}"; then
echo "Failed to update version in {{.VERSION_FILE}}"
exit 1
fi
git add "{{.VERSION_FILE}}"
fi
git commit -m "chore(release): Release $NEXT_VERSION"
git tag "$NEXT_VERSION" -m "chore(release): Release $NEXT_VERSION"
exit 0
# Linting
lint:
cmds:
- |
if [ -n "{{.SRC_DIR}}" ]; then
export SRC_DIR="{{.SRC_DIR}}"
else
export SRC_DIR="{{.PACKAGE_SRC_DIR}}"
fi
- uvx ruff check $SRC_DIR {{.CLI_ARGS}}
- |
if [ "{{.FORMAT}}" = "true" ]; then
uvx ruff format $SRC_DIR {{.CLI_ARGS}}
fi
# Run unit tests
unit-tests:
cmds:
- coverage run -m pytest --junitxml=report.xml {{.CLI_ARGS}}
- coverage report
- coverage xml
- coverage html -d coverage-report
# Build the documentation
build-docs:
cmds:
- cp openapi.json docs/reference/api/openapi.json
- mkdocs build
run-docs:
cmds:
- mkdocs serve
# ---------------------
build-whl:
cmds:
- uv build --wheel
# Build the docs image
build-docker-docs:
requires:
vars: [
IMAGE_NAME,
IMAGE_TAG,
PYTHON_VERSION,
]
cmds:
- docker build -f docker/docs.Dockerfile {{.DOCKER_BUILD_ARGS}} --build-arg PYTHON_VERSION={{.PYTHON_VERSION}} -t {{.IMAGE_NAME}}:docs-{{.IMAGE_TAG}} -t {{.IMAGE_NAME}}:docs-latest .
# Build the base image
build-docker-base:
requires:
vars: [
IMAGE_NAME,
IMAGE_TAG,
PYTHON_VERSION,
]
cmds:
- docker build -f docker/base.Dockerfile {{.DOCKER_BUILD_ARGS}} --build-arg PYTHON_VERSION={{.PYTHON_VERSION}} -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}} .
# Build the full image, including flowml, the openmeteo plugin and build dependencies
build-docker-full:
requires:
vars: [
IMAGE_NAME,
IMAGE_TAG,
PYTHON_VERSION,
]
cmds:
- docker build -f docker/complete.Dockerfile {{.DOCKER_BUILD_ARGS}} --build-arg PYTHON_VERSION={{.PYTHON_VERSION}} --build-arg BASE_IMAGE={{.IMAGE_NAME}}:{{.IMAGE_TAG}} -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}}-full .
# Build the gpu image with CUDA support on top of the full image
build-docker-gpu:
requires:
vars: [
IMAGE_NAME,
IMAGE_TAG,
PYTHON_VERSION,
]
cmds:
- docker build -f docker/gpu.Dockerfile {{.DOCKER_BUILD_ARGS}} --build-arg PYTHON_VERSION={{.PYTHON_VERSION}} --build-arg BASE_IMAGE={{.IMAGE_NAME}}:{{.IMAGE_TAG}} -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}}-gpu .
- docker build -f docker/gpu.Dockerfile {{.DOCKER_BUILD_ARGS}} --build-arg PYTHON_VERSION={{.PYTHON_VERSION}} --build-arg BASE_IMAGE={{.IMAGE_NAME}}:{{.IMAGE_TAG}}-full -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}}-full-gpu .