From 41f34d9c9dee57c6b43a15f6bc4349e3361451f0 Mon Sep 17 00:00:00 2001 From: Amal Bijoy Date: Sun, 5 Apr 2026 22:20:07 +0530 Subject: [PATCH] Add deterministic Java compile smoke test and CI --- .github/workflows/compile-smoke.yml | 22 ++++++++++ README.md | 7 +++- scripts/compile_smoke.sh | 63 +++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/compile-smoke.yml create mode 100755 scripts/compile_smoke.sh diff --git a/.github/workflows/compile-smoke.yml b/.github/workflows/compile-smoke.yml new file mode 100644 index 0000000..1e9e14e --- /dev/null +++ b/.github/workflows/compile-smoke.yml @@ -0,0 +1,22 @@ +name: Java Compile Smoke Test + +on: + pull_request: + workflow_dispatch: + +jobs: + compile-smoke: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - name: Run compile smoke test + run: ./scripts/compile_smoke.sh diff --git a/README.md b/README.md index 64f85cc..95f8a16 100644 --- a/README.md +++ b/README.md @@ -78,5 +78,10 @@ These programs are written to clearly show algorithm flow and logic rather than ## Development Checks - Run a Java compile smoke test: ```bash - ./scripts/java-compile-smoke.sh + ./scripts/compile_smoke.sh ``` +- The smoke test: + - Scans `Searching-algorithms/`, `Sorting-algorithms/`, and `Data-Structures/`. + - Compiles files in deterministic (sorted) order. + - Uses isolated temporary output folders per file to avoid default-package collisions. + - Prints `[PASS]` / `[FAIL]` per file and exits non-zero when any file fails. diff --git a/scripts/compile_smoke.sh b/scripts/compile_smoke.sh new file mode 100755 index 0000000..ad10a79 --- /dev/null +++ b/scripts/compile_smoke.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$repo_root" + +search_roots=( + "Searching-algorithms" + "Sorting-algorithms" + "Data-Structures" +) + +mapfile -t java_files < <( + find "${search_roots[@]}" -type f -name '*.java' 2>/dev/null | LC_ALL=C sort +) + +if [[ ${#java_files[@]} -eq 0 ]]; then + echo "No Java files found in target directories: ${search_roots[*]}" + exit 0 +fi + +tmp_dir="$(mktemp -d)" +trap 'rm -rf "$tmp_dir"' EXIT + +failures=0 + +echo "Compiling ${#java_files[@]} Java file(s) with isolated output folders..." + +for i in "${!java_files[@]}"; do + file="${java_files[$i]}" + + work_dir="$tmp_dir/work/$i" + out_dir="$tmp_dir/out/$i" + err_file="$tmp_dir/err/$i.log" + mkdir -p "$work_dir" "$out_dir" "$(dirname "$err_file")" + + class_name="$(sed -nE 's/^[[:space:]]*public[[:space:]]+(class|interface|enum)[[:space:]]+([A-Za-z_][A-Za-z0-9_]*).*/\2/p' "$file" | head -n 1)" + + if [[ -n "$class_name" ]]; then + compile_target="$work_dir/${class_name}.java" + else + compile_target="$work_dir/$(basename "$file")" + fi + + cp "$file" "$compile_target" + + if javac -d "$out_dir" "$compile_target" > /dev/null 2>"$err_file"; then + echo "[PASS] $file" + else + echo "[FAIL] $file" + sed 's/^/ /' "$err_file" + failures=$((failures + 1)) + fi +done + +if [[ $failures -gt 0 ]]; then + echo + echo "Java compile smoke test failed: $failures file(s) did not compile." + exit 1 +fi + +echo +echo "Java compile smoke test passed."