Skip to content

Commit f4f5e87

Browse files
committed
chore: utilise do-exclusively on eks testing
run the eks integration test only once concurrently, because the same environment is used, and multiple tests will interrupt each other.
1 parent 60622a3 commit f4f5e87

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jobs:
188188
export IMAGE_TAG=$([[ "$CIRCLE_BRANCH" == "staging" ]] && echo "staging-candidate" || echo "discardable") &&
189189
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=snyk/kubernetes-monitor:${IMAGE_TAG}-${CIRCLE_SHA1} &&
190190
docker pull ${KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG} &&
191-
npm run test:integration:eks
191+
.circleci/do-exclusively --branch staging npm run test:integration:eks
192192
- run:
193193
name: Notify Slack on failure
194194
command: |

.circleci/do-exclusively

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
3+
# copied from https://github.com/bellkev/circle-lock-test
4+
5+
# sets $branch, $tag, $rest
6+
parse_args() {
7+
while [[ $# -gt 0 ]]; do
8+
case $1 in
9+
-b|--branch) branch="$2" ;;
10+
-t|--tag) tag="$2" ;;
11+
*) break ;;
12+
esac
13+
shift 2
14+
done
15+
rest=("$@")
16+
}
17+
18+
# reads $branch, $tag, $commit_message
19+
should_skip() {
20+
if [[ "$branch" && "$CIRCLE_BRANCH" != "$branch" ]]; then
21+
echo "Not on branch $branch. Skipping..."
22+
return 0
23+
fi
24+
25+
if [[ "$tag" && "$commit_message" != *\[$tag\]* ]]; then
26+
echo "No [$tag] commit tag found. Skipping..."
27+
return 0
28+
fi
29+
30+
return 1
31+
}
32+
33+
# reads $branch, $tag
34+
# sets $jq_prog
35+
make_jq_prog() {
36+
local jq_filters=""
37+
38+
if [[ $branch ]]; then
39+
jq_filters+=" and .branch == \"$branch\""
40+
fi
41+
42+
if [[ $tag ]]; then
43+
jq_filters+=" and (.subject | contains(\"[$tag]\"))"
44+
fi
45+
46+
jq_prog=".[] | select(.build_num < $CIRCLE_BUILD_NUM and (.status | test(\"running|pending|queued\")) $jq_filters) | .build_num"
47+
}
48+
49+
50+
if [[ "$0" != *bats* ]]; then
51+
set -e
52+
set -u
53+
set -o pipefail
54+
55+
branch=""
56+
tag=""
57+
rest=()
58+
api_url="https://circleci.com/api/v1/project/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME?circle-token=$CIRCLE_TOKEN&limit=100"
59+
60+
parse_args "$@"
61+
commit_message=$(git log -1 --pretty=%B)
62+
if should_skip; then exit 0; fi
63+
make_jq_prog
64+
65+
echo "Checking for running builds..."
66+
67+
while true; do
68+
builds=$(curl -s -H "Accept: application/json" "$api_url" | jq "$jq_prog")
69+
if [[ $builds ]]; then
70+
echo "Waiting on builds:"
71+
echo "$builds"
72+
else
73+
break
74+
fi
75+
echo "Retrying in 5 seconds..."
76+
sleep 5
77+
done
78+
79+
echo "Acquired lock"
80+
81+
if [[ "${#rest[@]}" -ne 0 ]]; then
82+
"${rest[@]}"
83+
fi
84+
fi

0 commit comments

Comments
 (0)