-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathjustfile
More file actions
160 lines (143 loc) · 5.02 KB
/
Copy pathjustfile
File metadata and controls
160 lines (143 loc) · 5.02 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
# Help commands
[private]
default:
@just --list
# Run all checks
[group('build')]
check: lint prepare test
# Run linter
[group('build')]
lint:
npm run lint
# Build TypeScript to build/ directory
[group('build')]
build:
npm run build
# Bundle for distribution (build + ncc bundle to dist/)
[group('build')]
prepare:
npm run prepare
# Run tests
[group('test')]
test:
npm test
# Run a single test file
[group('test')]
test-file file:
npx jest {{file}}
# Run tests matching a pattern
[group('test')]
test-pattern pattern:
npx jest --testNamePattern="{{pattern}}"
# Fix vulnerabilities
[group('deps')]
audit-fix:
npm audit fix
# Check for vulnerabilities
[group('deps')]
audit:
npm audit
# Install dependencies
[group('deps')]
install:
npm install
# Update dependencies
[group('deps')]
update: update-cli-scanner update-oldest-cli-scanner
nix flake update
nix develop --command just _update-deps
# (internal) Refresh deps/hooks inside the nix devshell
[private]
[group('deps')]
_update-deps: && prepare
npm update
npm audit fix
pinact run -u
prek autoupdate
# (internal) Print the latest published sysdig-cli-scanner version
[private]
[group('scanner')]
_latest-version:
@curl -sL https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt | tr -d '[:space:]'
# Find the oldest sysdig-cli-scanner version still within the support window (default 365 days)
[group('scanner')]
oldest-cli-scanner window_days="365":
#!/usr/bin/env bash
set -euo pipefail
base="https://download.sysdig.com/scanning/bin/sysdig-cli-scanner"
os="linux"; arch="amd64"
cutoff=$(( $(date -u +%s) - {{window_days}} * 86400 ))
latest=$(just _latest-version)
major=${latest%%.*}
minor=$(echo "$latest" | cut -d. -f2)
oldest_ver=""; oldest_epoch=""
for m in $(seq "$minor" -1 0); do
minor_hit=0; misses=0
for p in $(seq 0 30); do
v="$major.$m.$p"
lm=$(curl -sfI "$base/$v/$os/$arch/sysdig-cli-scanner" \
| grep -i '^last-modified:' | sed 's/^[Ll]ast-[Mm]odified: //' | tr -d '\r' || true)
if [ -z "$lm" ]; then
misses=$((misses + 1)); [ "$misses" -ge 2 ] && break; continue
fi
misses=0
epoch=$(date -u -d "$lm" +%s)
if [ "$epoch" -ge "$cutoff" ]; then
minor_hit=1
if [ -z "$oldest_epoch" ] || [ "$epoch" -lt "$oldest_epoch" ]; then
oldest_epoch=$epoch; oldest_ver=$v
fi
fi
done
# Versions are chronological: once a whole minor is out of window, stop.
[ "$minor_hit" -eq 0 ] && [ -n "$oldest_ver" ] && break
done
if [ -z "$oldest_ver" ]; then
echo "No version found within the last {{window_days}} days" >&2
exit 1
fi
echo >&2 "Oldest supported: $oldest_ver (released $(date -u -d "@$oldest_epoch" '+%Y-%m-%d'))"
echo "$oldest_ver"
# (internal) Replace the version tagged with <marker>-version-marker wherever it
# appears. Markers are HTML-comment spans in Markdown and trailing `#`/`//`
# comments in YAML/TS. Target files are discovered, not hardcoded, so a new
# marker anywhere is picked up automatically. DO NOT delete those markers.
[private]
[group('scanner')]
_set-version marker version:
#!/usr/bin/env bash
set -euo pipefail
# Discover files carrying this marker. Skip generated output (dist/build),
# deps, and the tooling/docs that only name the marker in prose.
mapfile -t files < <(grep -rl \
--exclude-dir=.git --exclude-dir=node_modules \
--exclude-dir=build --exclude-dir=dist \
--exclude=justfile --exclude=AGENTS.md \
"{{marker}}-version-marker" . | sort)
if [ "${#files[@]}" -eq 0 ]; then
echo "No files found carrying {{marker}}-version-marker" >&2
exit 1
fi
for f in "${files[@]}"; do
echo "Updating $f" >&2
# Markdown: <!-- {{marker}}-version-marker ... -->X<!-- /{{marker}}-version-marker -->
sed -i -E "s#(<!-- {{marker}}-version-marker[^>]*-->)[0-9][0-9.]*(<!-- /{{marker}}-version-marker -->)#\1{{version}}\2#g" "$f"
# YAML/TS: line carrying a `#`/`//` {{marker}}-version-marker comment
sed -i -E "/(#|\/\/)[[:space:]]*{{marker}}-version-marker/ s/[0-9]+\.[0-9]+\.[0-9]+/{{version}}/" "$f"
done
# Substitute the oldest supported version wherever the oldest-version-marker is placed
[group('scanner')]
update-oldest-cli-scanner window_days="365":
#!/usr/bin/env bash
set -euo pipefail
oldest=$(just oldest-cli-scanner {{window_days}})
just _set-version oldest "$oldest"
echo "Oldest supported version set to $oldest (via oldest-version-marker)"
# Update sysdig-cli-scanner default to the latest available version
[group('scanner')]
update-cli-scanner:
#!/usr/bin/env bash
set -euo pipefail
latest=$(just _latest-version)
just _set-version newest "$latest"
echo "Newest (default) version set to $latest (via newest-version-marker). Run 'just prepare' to rebuild dist/."