Skip to content

Commit 646cd3f

Browse files
PicazsooCopilot
andcommitted
ci: add smart change detection to CircleCI nodes to skip unnecessary tests
Add should_run_tests() helper function that checks if relevant files changed since origin/master before running each node's integration tests. Decision logic (in order): 1. If origin/master unavailable (fresh CI env) → run tests (safe default) 2. If git diff fails → run tests (safe default) 3. If generator/config changed (modules/, bin/configs/, pom.xml, .mvn/) → run tests 4. If node's sample directories changed → run tests 5. Otherwise → skip tests Logs the decision-making process clearly for each node so users can understand why tests ran or were skipped. Prevents wasted CI resources on pure .github/ changes or unrelated sample changes (e.g., don't run perl tests if only ruby sample changed). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 39bfcef commit 646cd3f

1 file changed

Lines changed: 86 additions & 15 deletions

File tree

CI/circle_parallel.sh

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,107 @@ set -e
99

1010
export NODE_ENV=test
1111

12+
# Helper function to check if tests should run for this node based on changed files
13+
should_run_tests() {
14+
local node_index=$1
15+
local sample_patterns=$2 # space-separated glob patterns for samples this node tests
16+
17+
echo ""
18+
echo "════════════════════════════════════════════════════════════════"
19+
echo "Node $node_index: Determining if tests should run"
20+
echo "════════════════════════════════════════════════════════════════"
21+
22+
# Always run tests if origin/master doesn't exist (e.g., fresh CI environment)
23+
if ! git rev-parse origin/master >/dev/null 2>&1; then
24+
echo "ℹ️ origin/master not available locally (fresh checkout or CI environment)"
25+
echo "✓ DECISION: Running tests (cannot determine changes safely)"
26+
return 0
27+
fi
28+
29+
# Try to get list of changed files since origin/master
30+
local changed
31+
changed=$(git diff --name-only origin/master HEAD 2>/dev/null) || {
32+
echo "⚠️ git diff origin/master HEAD failed"
33+
echo "✓ DECISION: Running tests (cannot determine changes safely)"
34+
return 0
35+
}
36+
37+
if [ -z "$changed" ]; then
38+
echo "ℹ️ No files changed since origin/master"
39+
echo "✗ DECISION: Skipping tests (nothing to test)"
40+
return 1
41+
fi
42+
43+
echo "Changed files:"
44+
echo "$changed" | sed 's/^/ /'
45+
46+
# Check if generator source or config changed (affects all samples)
47+
echo ""
48+
echo "Checking for generator/config changes (affects all samples)..."
49+
if echo "$changed" | grep -qE '^(modules/|bin/configs/|pom\.xml|\.mvn/)'; then
50+
echo "✓ Found: generator or config files changed"
51+
echo "✓ DECISION: Running tests (generator/config affects all samples)"
52+
return 0
53+
fi
54+
55+
# Check if this node's sample directories changed
56+
echo ""
57+
echo "Checking for sample changes relevant to this node..."
58+
for pattern in $sample_patterns; do
59+
if echo "$changed" | grep -q "^$pattern"; then
60+
echo "✓ Found: $pattern"
61+
echo "✓ DECISION: Running tests (relevant sample changed)"
62+
return 0
63+
fi
64+
done
65+
66+
echo "✗ No relevant sample changes found for node $node_index"
67+
echo "✗ DECISION: Skipping tests (no relevant changes)"
68+
return 1
69+
}
70+
1271
if [ "$NODE_INDEX" = "1" ]; then
1372
echo "Running node $NODE_INDEX ..."
1473

15-
sudo apt-get -y install cpanminus
74+
if should_run_tests "$NODE_INDEX" "samples/client/petstore/perl/"; then
75+
sudo apt-get -y install cpanminus
1676

17-
echo "Testing perl"
18-
(cd samples/client/petstore/perl && /bin/bash ./test.bash)
77+
echo "Testing perl"
78+
(cd samples/client/petstore/perl && /bin/bash ./test.bash)
79+
else
80+
echo "Skipping perl tests — no relevant changes"
81+
fi
1982

2083

2184
elif [ "$NODE_INDEX" = "2" ]; then
2285
echo "Running node $NODE_INDEX to test cpp-restsdk"
2386

24-
# install cpprestsdk
25-
sudo apt-get install libcpprest-dev
26-
wget "https://github.com/aminya/setup-cpp/releases/download/v0.37.0/setup-cpp-x64-linux"
27-
chmod +x ./setup-cpp-x64-linux
28-
sudo ./setup-cpp-x64-linux --compiler llvm --cmake true --ninja true
29-
source ~/.cpprc # activate cpp environment variables
87+
if should_run_tests "$NODE_INDEX" "samples/client/petstore/cpp-restsdk/"; then
88+
# install cpprestsdk
89+
sudo apt-get install libcpprest-dev
90+
wget "https://github.com/aminya/setup-cpp/releases/download/v0.37.0/setup-cpp-x64-linux"
91+
chmod +x ./setup-cpp-x64-linux
92+
sudo ./setup-cpp-x64-linux --compiler llvm --cmake true --ninja true
93+
source ~/.cpprc # activate cpp environment variables
3094

31-
(cd samples/client/petstore/cpp-restsdk/client && mvn integration-test)
95+
(cd samples/client/petstore/cpp-restsdk/client && mvn integration-test)
96+
else
97+
echo "Skipping cpp-restsdk tests — no relevant changes"
98+
fi
3299

33100
elif [ "$NODE_INDEX" = "3" ]; then
34101

35102
echo "Running node $NODE_INDEX ... "
36103

37-
echo "Testing ruby"
38-
(cd samples/client/petstore/ruby && mvn integration-test)
39-
(cd samples/client/petstore/ruby-faraday && mvn integration-test)
40-
(cd samples/client/petstore/ruby-httpx && mvn integration-test)
41-
(cd samples/client/petstore/ruby-autoload && mvn integration-test)
104+
if should_run_tests "$NODE_INDEX" "samples/client/petstore/ruby"; then
105+
echo "Testing ruby"
106+
(cd samples/client/petstore/ruby && mvn integration-test)
107+
(cd samples/client/petstore/ruby-faraday && mvn integration-test)
108+
(cd samples/client/petstore/ruby-httpx && mvn integration-test)
109+
(cd samples/client/petstore/ruby-autoload && mvn integration-test)
110+
else
111+
echo "Skipping ruby tests — no relevant changes"
112+
fi
42113

43114
else
44115
echo "Running node $NODE_INDEX ..."

0 commit comments

Comments
 (0)