Skip to content

Commit e4b15af

Browse files
committed
bk: added pre-command hook
The pre-command hook runs before the command steps. We need that to check for github labels, in order to run in parallel any steps we want
1 parent 41539a1 commit e4b15af

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.buildkite/hooks/pre-command

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# This file should be kept in sync with vtools's pre-command file.
4+
# https://github.com/redpanda-data/vtools/.buildkite/hooks/pre-command
5+
6+
set -uo pipefail
7+
set +e
8+
9+
PARALLEL_STEPS=1
10+
11+
repo=$(echo $BUILDKITE_REPO | awk -F/ '{print $NF}' | awk -F. '{print $1}')
12+
13+
if [[ ${BUILDKITE_PULL_REQUEST} != false ]]; then
14+
labels=$(curl \
15+
--retry 3 --retry-connrefused --fail \
16+
-H "Accept: application/vnd.github.v3+json" \
17+
-H "Authorization: token ${GITHUB_API_TOKEN}" \
18+
"https://api.github.com/repos/redpanda-data/${repo}/issues/${BUILDKITE_PULL_REQUEST}/labels")
19+
20+
if [[ $? == "0" ]]; then
21+
set -e
22+
parallel=$(echo "${labels}" | jq -r '.[].name|select(startswith("ci-repeat-"))|ltrimstr("ci-repeat-")' | head -1)
23+
curl \
24+
-X "DELETE" \
25+
--retry 3 --retry-connrefused --silent \
26+
-H "Accept: application/vnd.github.v3+json" \
27+
-H "Authorization: token ${GITHUB_API_TOKEN}" \
28+
"https://api.github.com/repos/redpanda-data/${repo}/issues/${BUILDKITE_PULL_REQUEST}/labels/ci-repeat-$parallel"
29+
30+
if ((parallel > 1 && parallel < 20)); then
31+
PARALLEL_STEPS=$parallel
32+
else
33+
echo >&2 "Provided parallel number is out of range(2-19). Changing to 1."
34+
PARALLEL_STEPS=1
35+
fi
36+
fi
37+
fi
38+
39+
export PARALLEL_STEPS

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*.out
2626
*.app
2727
/*build*
28+
!.buildkite
2829
/dbuild
2930
bin
3031
_e2e_artifacts/
@@ -240,4 +241,4 @@ vbuild/
240241
# VSCode java settings
241242
.classpath
242243
.factorypath
243-
.settings/
244+
.settings/

0 commit comments

Comments
 (0)