Skip to content

Commit 46028e4

Browse files
committed
Add build script for PRs
1 parent e0ff806 commit 46028e4

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

.buildkite/scripts/build_pr.sh

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,91 @@
11
#!/bin/bash
2-
echo "nothing to see yet"
2+
set -euo pipefail
3+
set +x
4+
5+
# This script should only be invoked by the Buildkite PR bot
6+
if [ -z ${GITHUB_PR_BRANCH+set} ] || [ -z ${GITHUB_PR_TARGET_BRANCH+set} ] || [ -z ${GITHUB_PR_NUMBER+set} ] || [ -z ${GITHUB_PR_BASE_REPO+set} ];then
7+
echo "One of the following env. variable GITHUB_PR_BRANCH, GITHUB_PR_TARGET_BRANCH, GITHUB_PR_NUMBER, GITHUB_PR_BASE_REPO is missing - exiting."
8+
exit 1
9+
fi
10+
11+
# Set some metadata for build filtering capabilities
12+
# https://buildkite.com/elastic/docs-build-pr/builds?meta_data[repo_pr]=tech-content_123
13+
buildkite-agent meta-data set "repo_pr" "${GITHUB_PR_BASE_REPO}_${GITHUB_PR_NUMBER}"
14+
15+
rebuild_opt=""
16+
build_args=""
17+
TARGET_BRANCH=""
18+
19+
# Define build docs arguments
20+
if [[ ${GITHUB_PR_COMMENT_VAR_REBUILD_OPT:="unset"} == "rebuild" ]];then
21+
rebuild_opt=" --rebuild"
22+
elif [[ ${GITHUB_PR_COMMENT_VAR_SKIP_OPT:="unset"} == "skiplinkcheck" ]];then
23+
build_args+=" --skiplinkcheck"
24+
if [[ ${GITHUB_PR_COMMENT_VAR_WARN_OPT:="unset"} == "warnlinkcheck" ]];then
25+
build_args+=" --warnlinkcheck"
26+
fi
27+
fi
28+
29+
buildkite-agent \
30+
annotate \
31+
--style "info" \
32+
--context 'docs-info' \
33+
"Triggered by a doc change in elastic/$GITHUB_PR_BASE_REPO PR: [#$GITHUB_PR_NUMBER](https://github.com/elastic/$GITHUB_PR_BASE_REPO/pull/$GITHUB_PR_NUMBER)"
34+
35+
36+
if [[ "${GITHUB_PR_BASE_REPO}" != 'docs' ]]; then
37+
# Buildkite PR bot for repositories other than the `elastic/docs` repo are configured to
38+
# always checkout the master branch of the `elastic/docs` repo (where the build logic resides).
39+
# We first need to checkout the product repo / branch in a sub directory, that we'll reference
40+
# in the build process.
41+
echo "Cloning the ${GITHUB_PR_BASE_REPO} PR locally"
42+
43+
git clone --reference /opt/git-mirrors/elastic-$GITHUB_PR_BASE_REPO \
44+
[email protected]:elastic/$GITHUB_PR_BASE_REPO.git ./product-repo
45+
46+
cd ./product-repo &&
47+
git fetch origin pull/$GITHUB_PR_NUMBER/head:$GITHUB_PR_BRANCH &&
48+
git switch $GITHUB_PR_BRANCH &&
49+
cd ..
50+
51+
build_args+=" --sub_dir $GITHUB_PR_BASE_REPO:$GITHUB_PR_TARGET_BRANCH:./product-repo"
52+
else
53+
# Buildkite PR bot for the `elastic/docs` repo is configured to checkout the PR directly into the workspace
54+
# We don't have to do anything else in this case.
55+
56+
# Per https://github.com/elastic/docs/issues/1821, always rebuild all
57+
# books for PRs to the docs repo, for now.
58+
# When https://github.com/elastic/docs/issues/1823 is fixed, this
59+
# should be removed and the original behavior restored.
60+
rebuild_opt=" --rebuild"
61+
fi
62+
63+
64+
# Set the target branch and preview options
65+
TARGET_BRANCH="${GITHUB_PR_BASE_REPO}_bk_${GITHUB_PR_NUMBER}"
66+
PREVIEW_URL="https://${TARGET_BRANCH}.docs-preview.app.elstc.co"
67+
68+
build_cmd="./build_docs --all --keep_hash \
69+
--target_repo [email protected]:elastic/built-docs \
70+
--reference /opt/git-mirrors/ \
71+
--target_branch ${TARGET_BRANCH} \
72+
--push \
73+
--announce_preview ${PREVIEW_URL}/diff \
74+
${rebuild_opt} \
75+
${build_args}"
76+
77+
echo "The following build command will be used"
78+
echo $build_cmd
79+
80+
# Kick off the build
81+
ssh-agent bash -c "ssh-add && $build_cmd"
82+
83+
buildkite-agent annotate \
84+
--style "success" \
85+
--context 'docs-info' \
86+
--append \
87+
"<br>Preview url: ${PREVIEW_URL}"
88+
89+
buildkite-agent meta-data set pr_comment:doc-preview:head " * Documentation preview
90+
- 📚 [HTML diff](${PREVIEW_URL}/diff)
91+
- 📙 [Preview](${PREVIEW_URL})"

0 commit comments

Comments
 (0)