-
-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathrun
More file actions
executable file
·81 lines (61 loc) · 2.05 KB
/
run
File metadata and controls
executable file
·81 lines (61 loc) · 2.05 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
#!/usr/bin/env bash
# Helper script to manage the project itself.
set -o errexit
set -o pipefail
lint() {
# Lint all supported file types
local shellcheck_cmd=(shellcheck)
local ruff_cmd=(ruff)
if ! command -v shellcheck >/dev/null 2>&1; then
local shellcheck_cmd=(docker container run --rm -i -v "${PWD}:/mnt" koalaman/shellcheck:stable)
fi
if ! command -v ruff >/dev/null 2>&1; then
local ruff_cmd=(docker container run --rm -i -v "${PWD}:/io" -u "$(id -u):$(id -g)" ghcr.io/astral-sh/ruff:0.11.1)
fi
find . -type f \
! -path "./.git/*" \
! -path "./.ruff_cache/*" \
! -path "./.pytest_cache/*" \
! -path "./mnt/c/*" \
-exec sh -c 'head -n 1 "${1}" | grep --quiet -E "^(#!.*sh|# shellcheck shell=)"' _ {} \; \
-exec "${shellcheck_cmd[@]}" {} +
"${ruff_cmd[@]}" check "${@}"
}
format() {
# Format all supported file types
local shfmt_cmd=(shfmt)
local ruff_cmd=(ruff)
if ! command -v shfmt >/dev/null 2>&1; then
local shfmt_cmd=(docker container run --rm -i -v "${PWD}:/mnt" -u "$(id -u):$(id -g)" -w /mnt mvdan/shfmt:v3)
fi
if ! command -v ruff >/dev/null 2>&1; then
local ruff_cmd=(docker container run --rm -i -v "${PWD}:/io" -u "$(id -u):$(id -g)" ghcr.io/astral-sh/ruff:0.11.1)
fi
local shfmt_args=("--write")
for arg in "${@}"; do
[ "${arg}" == "--check" ] && shfmt_args+=("--diff")
if [ "${arg}" == "-d" ] || [ "${arg}" == "--diff" ] || [ "${shfmt_args[1]}" == "--diff" ]; then
unset "shfmt_args[0]"
fi
done
"${shfmt_cmd[@]}" "${shfmt_args[@]}" . .config/zsh/.{aliases,zprofile,zshrc}
"${ruff_cmd[@]}" check --fix
"${ruff_cmd[@]}" format "${@}"
}
quality() {
# Perform all code quality commands together
lint "${@}"
format "${@}"
}
ci:test() {
# Execute Continuous Integration (CI) pipeline
lint
format --check --diff
}
help() {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"