From e9ec4abc592d0a57bdf86da6eeb97546c6a1a5fd Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:48:57 +0200 Subject: [PATCH 1/2] feat: skip build for APM Server if there are no code changes docs/build-pr is the slowest job in apm-server CI pipeline and it is impacting significantly developer velocity when merging PRs. Update the buildkite pipeline to exit early if there are no docs changes. APM Server docs is actually in a separate repository (observability-docs) and the few remaining files are barely touched (except for the changelog) --- .buildkite/scripts/build_pr.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.buildkite/scripts/build_pr.sh b/.buildkite/scripts/build_pr.sh index 3aa9159e5bae2..8250255337558 100755 --- a/.buildkite/scripts/build_pr.sh +++ b/.buildkite/scripts/build_pr.sh @@ -52,8 +52,20 @@ if [[ "${GITHUB_PR_BASE_REPO}" != 'docs' ]]; then cd ./product-repo && git fetch origin pull/$GITHUB_PR_NUMBER/head:pr_$GITHUB_PR_NUMBER && - git switch pr_$GITHUB_PR_NUMBER && - cd .. + git switch pr_$GITHUB_PR_NUMBER + + if [[ "${GITHUB_PR_BASE_REPO}" == 'apm-server' ]]; then + git diff --quiet HEAD $GITHUB_PR_TARGET_BRANCH -- ./docs ./changelogs CHANGELOG.asciidoc + + empty=$? + + if [ $empty -eq 0 ]; then + echo "${GITHUB_PR_TARGET_BRANCH} in ${GITHUB_PR_BASE_REPO} has no docs changes" + exit 0 + fi + fi + + cd .. # For product repos - context in https://github.com/elastic/docs/commit/5b06c2dc1f50208fcf6025eaed6d5c4e81200330 build_args+=" --keep_hash" build_args+=" --sub_dir $GITHUB_PR_BASE_REPO:$GITHUB_PR_TARGET_BRANCH:./product-repo" From 0ab7eda33142e7a70354440028797c611f62bf38 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Sun, 8 Sep 2024 23:00:40 +0200 Subject: [PATCH 2/2] fix: diff with merge-base of target branch instead of tip --- .buildkite/scripts/build_pr.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.buildkite/scripts/build_pr.sh b/.buildkite/scripts/build_pr.sh index 8250255337558..dbd26227e817b 100755 --- a/.buildkite/scripts/build_pr.sh +++ b/.buildkite/scripts/build_pr.sh @@ -55,16 +55,19 @@ if [[ "${GITHUB_PR_BASE_REPO}" != 'docs' ]]; then git switch pr_$GITHUB_PR_NUMBER if [[ "${GITHUB_PR_BASE_REPO}" == 'apm-server' ]]; then - git diff --quiet HEAD $GITHUB_PR_TARGET_BRANCH -- ./docs ./changelogs CHANGELOG.asciidoc - - empty=$? + docs_diff=$(git diff --stat "$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs ./changelogs CHANGELOG.asciidoc) + else + docs_diff=$(git diff --stat "$GITHUB_PR_TARGET_BRANCH"...HEAD) + fi - if [ $empty -eq 0 ]; then - echo "${GITHUB_PR_TARGET_BRANCH} in ${GITHUB_PR_BASE_REPO} has no docs changes" - exit 0 - fi + if [[ -z $docs_diff ]]; then + echo "${GITHUB_PR_TARGET_BRANCH} in ${GITHUB_PR_BASE_REPO} has no docs changes" + exit 0 fi + echo "diff:" + echo "$docs_diff" + cd .. # For product repos - context in https://github.com/elastic/docs/commit/5b06c2dc1f50208fcf6025eaed6d5c4e81200330 build_args+=" --keep_hash"