Skip to content

Commit e678071

Browse files
committed
chore(common): add smoke test bash script for ci
1 parent 95a253b commit e678071

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ROOT_DIR := $(CURDIR)
66
BUILDPACK_DIR := $(ROOT_DIR)
77
PYTHON_BIN ?= python3
88

9-
.PHONY: test-buildpack clean-test-buildpack start-local
9+
.PHONY: test-buildpack clean-test-buildpack smoke-test start-local
1010

1111
# Reset the temporary staging directories used for local buildpack testing.
1212
clean-test-buildpack:
@@ -17,15 +17,22 @@ clean-test-buildpack:
1717
test-buildpack: clean-test-buildpack
1818
mkdir -p $(BUILD_DIR) $(CACHE_DIR) $(ENV_DIR)
1919
cp -R $(APP_DIR)/. $(BUILD_DIR)
20-
cd $(APP_DIR) && ../../bin/detect
20+
# Run detect from the fixture app directory, but use the buildpack script from the repo root.
21+
cd $(APP_DIR) && $(BUILDPACK_DIR)/bin/detect
2122
$(BUILDPACK_DIR)/bin/compile $(BUILD_DIR) $(CACHE_DIR) $(ENV_DIR)
23+
# Confirm staged dependencies are importable before checking the release metadata.
2224
cd $(BUILD_DIR) && /bin/bash -lc 'source .profile.d/python.sh && $(PYTHON_BIN) -c "import fastapi; print(fastapi.__version__)"'
2325
cd $(BUILD_DIR) && $(BUILDPACK_DIR)/bin/release
2426

27+
# Run the single-app smoke test target against every app fixture under test/smoke.
28+
smoke-test:
29+
@./scripts/smoke-test.sh
30+
2531
# Start the staged sample app locally using the dependencies prepared by `test-buildpack`.
2632
start-local:
2733
@cd $(BUILD_DIR) && /bin/bash -lc '\
2834
source .profile.d/python.sh && \
35+
# Prefer the app Procfile, otherwise reuse the buildpack release logic. \
2936
if [ -f Procfile ]; then \
3037
WEB_CMD=$$(awk -F": " '\''$$1 == "web" { print $$2; exit }'\'' Procfile); \
3138
else \
@@ -35,5 +42,6 @@ start-local:
3542
echo "Could not determine a web command to run locally."; \
3643
exit 1; \
3744
fi; \
45+
# Local machines often expose `python3` instead of `python`, so normalize that here. \
3846
WEB_CMD=$$(printf "%s" "$$WEB_CMD" | sed "s/^python /$(PYTHON_BIN) /"); \
3947
eval "$$WEB_CMD"'

bin/release

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ else
1010
fi
1111

1212
resolve_script_target() {
13+
# Parse pyproject.toml with Python so we can safely read TOML instead of
14+
# relying on brittle grep/awk parsing.
1315
"$PYTHON_BIN" -c '
1416
import sys
1517
try:
@@ -29,6 +31,8 @@ print(scripts.get(project_name) or scripts.get("start", ""))
2931
}
3032

3133
build_python_entrypoint() {
34+
# Convert a console-script target like `server.main:start` into a command
35+
# that invokes the same callable directly with the resolved interpreter.
3236
local target="$1"
3337
local module_name="${target%%:*}"
3438
local function_name="${target##*:}"

scripts/smoke-test.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6+
# Allow CI or local runs to point at a different smoke-fixture directory.
7+
SMOKE_DIR="${SMOKE_DIR:-$ROOT_DIR/test/smoke}"
8+
9+
if [ ! -d "$SMOKE_DIR" ]; then
10+
echo "Smoke test directory not found: $SMOKE_DIR"
11+
exit 1
12+
fi
13+
14+
found_app=0
15+
16+
# Run the single-app make target for every fixture app under test/smoke.
17+
for app_dir in "$SMOKE_DIR"/*; do
18+
[ -d "$app_dir" ] || continue
19+
found_app=1
20+
echo "==> Smoke testing $(basename "$app_dir")"
21+
if ! make -C "$ROOT_DIR" test-buildpack APP_DIR="${app_dir#$ROOT_DIR/}"; then
22+
# Clean staged files before failing so the next run starts fresh.
23+
make -C "$ROOT_DIR" clean-test-buildpack
24+
exit 1
25+
fi
26+
# Clean after every app to keep smoke-test runs isolated from each other.
27+
make -C "$ROOT_DIR" clean-test-buildpack
28+
done
29+
30+
if [ "$found_app" -eq 0 ]; then
31+
echo "No smoke test apps found in $SMOKE_DIR"
32+
exit 1
33+
fi

0 commit comments

Comments
 (0)