Skip to content

Commit 113b256

Browse files
committed
Add pre and post commit hooks
1 parent 46028e4 commit 113b256

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.buildkite/hooks/post-command

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# This hook should only be invoked for builds triggered by the Buildkite PR bot
6+
if [ -z ${GITHUB_PR_OWNER+set} ] || [ -z ${GITHUB_PR_REPO+set} ] || [ -z ${GITHUB_PR_TRIGGERED_SHA+set} ];then
7+
exit 0
8+
fi
9+
10+
gitHubToken=$(vault read -field=value secret/ci/elastic-docs/docs_preview_cleaner)
11+
12+
if [ -n "$BUILDKITE_COMMAND_EXIT_STATUS" ] && [ "$BUILDKITE_COMMAND_EXIT_STATUS" -eq "0" ];then
13+
status_state="success"
14+
else
15+
status_state="failure"
16+
fi
17+
18+
githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_OWNER}/${GITHUB_PR_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}"
19+
data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished.","context":"buildkite/docs"}'
20+
echo "Setting buildkite/docs commit status to ${status_state}"
21+
curl -s -L \
22+
-X POST \
23+
-H "Accept: application/vnd.github+json" \
24+
-H "Authorization: Bearer ${gitHubToken}" \
25+
-H "X-GitHub-Api-Version: 2022-11-28" \
26+
"${githubPublishStatus}" \
27+
-d "${data}"

.buildkite/hooks/pre-command

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Configure the git author and committer information
6+
export GIT_AUTHOR_NAME='Buildkite CI'
7+
export GIT_AUTHOR_EMAIL='[email protected]'
8+
export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME
9+
export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL
10+
11+
# The reminder of this hook should only be invoked for builds triggered by the Buildkite PR bot
12+
if [ -z ${GITHUB_PR_OWNER+set} ] || [ -z ${GITHUB_PR_REPO+set} ] || [ -z ${GITHUB_PR_TRIGGERED_SHA+set} ];then
13+
exit 0
14+
fi
15+
16+
gitHubToken=$(vault read -field=value secret/ci/elastic-docs/docs_preview_cleaner)
17+
18+
githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_OWNER}/${GITHUB_PR_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}"
19+
data='{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started.","context":"buildkite/docs"}'
20+
echo "Setting buildkite/docs commit status to pending"
21+
curl -s -L \
22+
-X POST \
23+
-H "Accept: application/vnd.github+json" \
24+
-H "Authorization: Bearer ${gitHubToken}" \
25+
-H "X-GitHub-Api-Version: 2022-11-28" \
26+
"${githubPublishStatus}" \
27+
-d "${data}"

0 commit comments

Comments
 (0)