Skip to content

Commit 83f6c12

Browse files
committed
fix: determine root when used with docker* plugins
1 parent c6eb45d commit 83f6c12

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

hooks/post-command

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,52 @@
33
set -euo pipefail
44
shopt -s globstar nullglob
55

6+
find_root () {
7+
if echo "$BUILDKITE_PLUGINS" | grep -q docker-compose-buildkite-plugin; then
8+
log 'It looks like this step was run via Docker Compose.'
9+
ROOT=''
10+
if [ -f Dockerfile ]; then
11+
log 'Attempting to parsed Dockerfile'
12+
ROOT="$(awk '/WORKDIR/ {print $2}' Dockerfile | tail -n 1)"
13+
else
14+
log 'No Dockerfile found.'
15+
fi
16+
17+
if [ "$ROOT" == '' ]; then
18+
log 'Could not determine root from Dockerfile. Assuming "/" for root.'
19+
echo '/'
20+
fi
21+
elif echo "$BUILDKITE_PLUGINS" | grep -q docker-buildkite-plugin; then
22+
log 'It looks like this step was run via Docker.'
23+
24+
if [ "${BUILDKITE_PLUGIN_DOCKER_WORKDIR:-}" != '' ]; then
25+
log 'Using the configured docker plugin workdir'
26+
echo "$BUILDKITE_PLUGIN_DOCKER_WORKDIR"
27+
else
28+
log 'Using the default docker plugin workdir'
29+
echo '/workdir'
30+
fi
31+
else
32+
log 'It looks like this step was run right on the agent. Using PWD for root'
33+
pwd
34+
fi
35+
}
36+
37+
log () {
38+
echo "$@" 1>&2
39+
}
40+
641
LABEL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_LABEL:-$BUILDKITE_LABEL}
7-
ROOT=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_ROOT:-$(pwd)}
42+
ROOT=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_ROOT:-$(find_root)}
843
SHA=$BUILDKITE_COMMIT
944
TOKEN=$BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_TOKEN
1045
URL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_URL:-https://www.check-run-reporter.com/api/v1/submissions}
1146

47+
log 'Running check-run-reporter-buildkite-plugin with the following parameters'
48+
log "LABEL=$LABEL"
49+
log "ROOT=$ROOT"
50+
log "SHA=$SHA"
51+
1252
CMD="curl -v $URL"
1353
CMD="$CMD --user token:'$TOKEN'"
1454
CMD="$CMD -F label'=$LABEL'"

0 commit comments

Comments
 (0)