-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
321 lines (284 loc) · 10.8 KB
/
justfile
File metadata and controls
321 lines (284 loc) · 10.8 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
# ===============================================================================
# vigOS Devcontainer - Just Recipes
# Build automation for devcontainer image development
# ===============================================================================
# ===============================================================================
# VARIABLES
# ===============================================================================
# Allow TEST_REGISTRY to override REPO for testing (e.g., localhost:5000/test/)
repo := env("TEST_REGISTRY", "ghcr.io/vig-os/devcontainer")
# ===============================================================================
# INFO
# ===============================================================================
# Show available commands (default)
[group('info')]
default:
@just --list --unsorted
# Show available commands
[group('info')]
help:
@just --list
# ===============================================================================
# CODE QUALITY
# ===============================================================================
# Run all linters
[group('quality')]
lint:
uv run ruff check .
# Format code
[group('quality')]
format:
uv run ruff format .
# Run pre-commit hooks on all files
[group('quality')]
precommit:
uv run pre-commit run --all-files
# Show image information
[group('info')]
info:
#!/usr/bin/env bash
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then
NATIVE_ARCH="linux/arm64"
else
NATIVE_ARCH="linux/amd64"
fi
echo "Image: {{ repo }}"
echo "Containerfile: Containerfile"
echo "Native arch: $NATIVE_ARCH"
# Install system dependencies and setup development environment
[group('info')]
init *args:
./scripts/init.sh {{ args }}
# Generate documentation from templates
[group('info')]
docs:
uv run python docs/generate.py
# Sync workspace templates from repo root to assets/workspace/
[group('info')]
sync-workspace:
uv run python scripts/sync_manifest.py sync assets/workspace/
# Test login to GHCR
[group('info')]
login:
#!/usr/bin/env bash
echo "Logging in to GitHub Container Registry..."
podman login ghcr.io
# ===============================================================================
# BUILD
# ===============================================================================
# Build local development image
[group('build')]
build no_cache="":
#!/usr/bin/env bash
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then
NATIVE_ARCH="linux/arm64"
else
NATIVE_ARCH="linux/amd64"
fi
if [ -n "{{ no_cache }}" ]; then
./scripts/build.sh --no-cache dev "{{ repo }}" "$NATIVE_ARCH"
else
./scripts/build.sh dev "{{ repo }}" "$NATIVE_ARCH"
fi
# ===============================================================================
# TEST
# ===============================================================================
# Helper to ensure dev image exists before running image/integration tests
[private]
_ensure-dev-image version="dev":
#!/usr/bin/env bash
if ! podman image exists "{{ repo }}:{{ version }}"; then
if [ "{{ version }}" = "dev" ]; then
echo "Building dev image..."
just build
else
echo "[ERROR] Image {{ repo }}:{{ version }} not found. Please build it first."
exit 1
fi
fi
# Run image tests only
[group('test')]
test-image version="dev":
@just _ensure-dev-image {{ version }}
#!/usr/bin/env bash
TEST_CONTAINER_TAG={{ version }} uv run pytest tests/test_image.py -v --tb=short
# Run integration tests only
[group('test')]
test-integration version="dev":
@just _ensure-dev-image {{ version }}
#!/usr/bin/env bash
TEST_CONTAINER_TAG={{ version }} uv run pytest tests/test_integration.py -v --tb=short
# Run utils tests only
[group('test')]
test-utils:
#!/usr/bin/env bash
uv run pytest tests/test_utils.py -v -s --tb=short
# Run install script tests only
[group('test')]
test-install:
#!/usr/bin/env bash
uv run pytest tests/test_install_script.py -v -s --tb=short
# Run validate commit msg tests only
[group('test')]
test-validate-commit-msg:
#!/usr/bin/env bash
uv run pytest tests/test_validate_commit_msg.py -v -s --tb=short
# Run check action pins tests only
[group('test')]
test-vig-utils:
#!/usr/bin/env bash
uv run pytest packages/vig-utils/tests -v -s --tb=short
# Run BATS shell script tests
[group('test')]
test-bats:
#!/usr/bin/env bash
# Use GNU parallel if available for faster test execution
if command -v parallel >/dev/null 2>&1; then
echo "Running BATS tests in parallel..."
find tests/bats -name '*.bats' -print0 | parallel -0 -j+0 npx bats {}
else
echo "Running BATS tests sequentially (install 'parallel' for faster execution)..."
npx bats tests/bats/
fi
# Clean up lingering containers before running tests
[private]
_test-cleanup-check:
#!/usr/bin/env bash
if podman ps -a --filter "name=workspace-devcontainer" -q 2>/dev/null | grep -q .; then
echo "[!] Lingering test containers found, cleaning up..."
just clean-test-containers
fi
# Run all test suites
[group('test')]
test version="dev":
@just _test-cleanup-check
@just _ensure-dev-image {{ version }}
#!/usr/bin/env bash
TEST_CONTAINER_TAG={{ version }} uv run pytest tests -v -s --tb=short
@just test-bats
# ===============================================================================
# RELEASE MANAGEMENT
# ===============================================================================
# Unified release workflow via GitHub Actions (.github/workflows/release.yml)
#
# Process:
# 1. just prepare-release X.Y.Z - Create release/X.Y.Z branch, draft PR
# 2. Test release branch, fix bugs as needed via PRs to release branch
# 3. Mark PR ready for review (gh pr ready PR_NUMBER)
# 4. Get PR approval from reviewer
# 5. just finalize-release X.Y.Z - Triggers GitHub Actions workflow that:
# - Validates PR status and all prerequisites
# - Sets release date in CHANGELOG, syncs PR docs
# - Builds and tests container images
# - Creates vX.Y.Z tag
# - Publishes images to GHCR
# - On failure: automatic rollback and issue creation
# 6. Merge release PR to main - Triggers sync-main-to-dev.yml automatically:
# - Opens PR to merge main into dev
# - Auto-merges if no conflicts
# ===============================================================================
# Prepare release branch for testing (step 1)
[group('release')]
prepare-release version ref="" *flags:
#!/usr/bin/env bash
set -euo pipefail
# Trigger the prepare-release workflow via GitHub Actions
# The workflow handles: validate inputs, create release branch, prepare CHANGELOG, create draft PR
REF="{{ ref }}"
if [ -z "$REF" ]; then
REF="dev"
fi
gh workflow run prepare-release.yml --ref "$REF" -f "version={{ version }}" {{ flags }}
echo ""
echo "✓ Release preparation workflow triggered for version {{ version }}"
echo "Monitor progress: gh run list --workflow prepare-release.yml"
# Finalize and publish release via GitHub Actions workflow (step 3, after testing)
[group('release')]
finalize-release version ref="" *flags:
#!/usr/bin/env bash
set -euo pipefail
# Trigger the release workflow via GitHub Actions
# The workflow handles: finalize CHANGELOG, build/test images, create final tag, publish
REF="{{ ref }}"
if [ -z "$REF" ]; then
REF="release/{{ version }}"
fi
gh workflow run release.yml --ref "$REF" -f "version={{ version }}" -f "release-kind=final" {{ flags }}
echo ""
echo "✓ Release workflow triggered for version {{ version }}"
echo "Monitor progress: gh run list --workflow release.yml"
# Publish release candidate via GitHub Actions workflow
[group('release')]
publish-candidate version ref="" *flags:
#!/usr/bin/env bash
set -euo pipefail
# Trigger release workflow in candidate mode (default mode in workflow)
REF="{{ ref }}"
if [ -z "$REF" ]; then
REF="release/{{ version }}"
fi
gh workflow run release.yml --ref "$REF" -f "version={{ version }}" -f "release-kind=candidate" {{ flags }}
echo ""
echo "✓ Candidate release workflow triggered for version {{ version }}"
echo "Monitor progress: gh run list --workflow release.yml"
# Reset CHANGELOG Unreleased section (after merging release to dev)
[group('release')]
reset-changelog:
uv run prepare-changelog reset CHANGELOG.md
# Pull image from registry (default: latest)
[group('release')]
pull version="latest":
#!/usr/bin/env bash
echo "Pulling image {{ repo }}:{{ version }}..."
TLS_FLAG=""
if [ "${REGISTRY_TEST:-}" = "1" ]; then
TLS_FLAG="--tls-verify=false"
fi
podman pull $TLS_FLAG "{{ repo }}:{{ version }}" || echo "[!] Failed to pull {{ repo }}:{{ version }}"
# ===============================================================================
# BUILD / CLEAN
# ===============================================================================
# Remove image (default: dev)
[group('build')]
clean version="dev":
#!/usr/bin/env bash
# Use TEST_REGISTRY from environment if set, otherwise use repo variable
# This allows tests to override the repo via TEST_REGISTRY at runtime
export TEST_REGISTRY
REPO="${TEST_REGISTRY:-{{ repo }}}"
# If TEST_REGISTRY was used and doesn't contain a path, append /test
# This handles cases where TEST_REGISTRY=localhost:PORT instead of localhost:PORT/test
if [[ -n "$TEST_REGISTRY" && "$REPO" == "$TEST_REGISTRY" && "$REPO" != *"/"* ]]; then
REPO="${REPO}/test"
fi
./scripts/clean.sh "{{ version }}" "$REPO"
# Clean up lingering test containers
[group('build')]
clean-test-containers:
#!/usr/bin/env bash
echo "Cleaning Cleaning up lingering test containers..."
FMT=$(printf '\x7b\x7b.ID\x7d\x7d')
DEVCONTAINERS=$(podman ps -a --filter "name=workspace-devcontainer" --format "$FMT" 2>/dev/null)
SIDECARS=$(podman ps -a --filter "name=test-sidecar" --format "$FMT" 2>/dev/null)
if [ -n "$DEVCONTAINERS" ] || [ -n "$SIDECARS" ]; then
if [ -n "$DEVCONTAINERS" ]; then
echo " Removing workspace devcontainers..."
echo "$DEVCONTAINERS" | xargs -r podman rm -f
fi
if [ -n "$SIDECARS" ]; then
echo " Removing test sidecars..."
echo "$SIDECARS" | xargs -r podman rm -f
fi
echo "[OK] Cleanup complete"
else
echo "[*] No lingering test containers found"
fi
# ===============================================================================
# PODMAN
# ===============================================================================
# Podman container & image management recipes
import 'justfile.podman'
import 'justfile.gh'
import 'justfile.worktree'