Skip to content

Commit 84035af

Browse files
bmorelli25nkammah
andauthored
Set build type for scheduled builds based on doc repo changes (#2931)
* check if docs repo has changed * more * updates so I can test it * build commit * lbc * gpb * more testing * a * b * mmhm * use auth token * fix quotes * c * aha! * no way this works * forgot the squigles * back up * perhaps * lsc * no squigs * jq isn’t working * quotes * try a file * ugh * d * e * move to file, echo all the things * Fixing up the script - mostly adding curl and jq flags * wire up the rebuild * fix script typo * export rebuild var * Make the script more generic * Set REBUILD value to false since empty strings are not accepted * Remove early exits used for testing purposes * Try setting concurrency group name based on branch * uncomment --------- Co-authored-by: nassimkammah <[email protected]>
1 parent c18f229 commit 84035af

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.buildkite/build_pipeline.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ steps:
2525
value: ""
2626
hint: "Should we ignore checking broken links? Should we allow to run the build without failing if there's a broken link? Ignoring broken links is dangerous not just because bad links will leak into the public site but because subsequent builds and pull requests that do not fix the links fail."
2727
- wait
28+
- label: "Full rebuild or incremental build?"
29+
if: build.source == "schedule"
30+
command: ".buildkite/scripts/compare_commits.sh"
2831
- label: ":white_check_mark: Build docs"
2932
command: |
3033
export REBUILD="$(buildkite-agent meta-data get REBUILD --default '' --log-level fatal)"
@@ -34,7 +37,7 @@ steps:
3437
provider: "gcp"
3538
image: family/docs-ubuntu-2204
3639
machineType: ${BUILD_MACHINE_TYPE}
37-
concurrency_group: build-docs
40+
concurrency_group: build-docs-${BUILDKITE_BRANCH}
3841
concurrency: 1
3942
notify:
4043
- email: "[email protected]"

.buildkite/hooks/pre-command

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "docs-build-pr" ]];then
3434
fi
3535
elif [[ "$BUILDKITE_PIPELINE_SLUG" == "docs-build" ]];then
3636
export BUILD_MACHINE_TYPE="n2-highcpu-32"
37+
export BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field=value secret/ci/elastic-docs/buildkite_token)
3738
elif [[ "$BUILDKITE_PIPELINE_SLUG" == "docs-build-air-gapped" ]] && [[ "$BUILDKITE_STEP_KEY" == "publish-air-gapped-doc" ]]; then
3839
export DOCKER_USERNAME=$(retry 5 vault kv get -field=username secret/ci/elastic-docs/docker.elastic.co)
3940
export DOCKER_PASSWORD=$(retry 5 vault kv get -field=password secret/ci/elastic-docs/docker.elastic.co)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
last_successful_build_url="https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds?branch=${BUILDKITE_BRANCH}&state=passed"
4+
LAST_SUCCESSFUL_COMMIT=$(curl -s -H "Authorization: Bearer ${BUILDKITE_API_TOKEN}" $last_successful_build_url | jq -r '.[0].commit')
5+
6+
echo "Comparing the current docs build commit ${BUILDKITE_COMMIT} to the last successful build commit ${LAST_SUCCESSFUL_COMMIT}"
7+
if [[ "$BUILDKITE_COMMIT" == "$LAST_SUCCESSFUL_COMMIT" ]]; then
8+
echo "The docs repo has not changed since the last build."
9+
buildkite-agent meta-data set "REBUILD" "false"
10+
else
11+
echo "The docs repo has changed since the last build."
12+
buildkite-agent meta-data set "REBUILD" "rebuild"
13+
fi

0 commit comments

Comments
 (0)