Skip to content

Commit 3a3ae8c

Browse files
author
Scott Schneider
committed
Only run C++ build and test if C++ code has changed
1 parent 1aff23e commit 3a3ae8c

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

cpp/build-and-test.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#!/bin/bash
22

33
TARGETS="benchmark_driver benchmark_driver_stats ooo_adversary data_benchmark test dynamic_benchmark"
4-
FQDN_IMAGE="swag-builder-cpp"
4+
IMAGE="swag-builder-cpp"
55
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
66

7+
# only proceed if this directory is in the latest commit
8+
if [ $(./can-skip.sh .) ]; then
9+
echo "Skipping build and test for C++ code."
10+
exit 0
11+
fi
12+
713
# build the docker image if not present
8-
[ ! -z $(docker images -q ${FQDN_IMAGE}) ] || make -C ${CWD} builder-image
14+
[ ! -z $(docker images -q ${IMAGE}) ] || make -C ${CWD} builder-image
915

1016
docker run -it \
1117
--user $(id -u):$(id -g) \
1218
-v ${CWD}:/stage \
13-
${FQDN_IMAGE} \
19+
${IMAGE} \
1420
bash -c "cd /stage; make ${TARGETS} && make zip && ./bin/test"
1521

cpp/can-skip.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Determines if we can skip build and test based on the provided paths we care
4+
# about. If the provided paths DO NOT appear in the latest commits, then we can
5+
# skip build and test. We exit with 0 to indicate we can skip tests and 1 if
6+
# we need to run tests. Based on:
7+
# https://fant.io/p/circleci-early-exit/
8+
set -e
9+
10+
PATHS_TO_SEARCH="$*"
11+
12+
# an empty path trivially means we can skip build and tests
13+
if [ -z "$PATHS_TO_SEARCH" ]; then
14+
exit 0
15+
fi
16+
17+
LATEST_COMMIT=$(git rev-parse HEAD)
18+
LATEST_COMMIT_IN_PATH=$(git log -1 --format=format:%H --full-diff $PATHS_TO_SEARCH)
19+
20+
# if the given path is not in the latest commit, then we can skip build and tests
21+
if [ $LATEST_COMMIT != $LATEST_COMMIT_IN_PATH ]; then
22+
exit 0
23+
fi
24+
25+
# we need to run the tests
26+
exit 1

0 commit comments

Comments
 (0)