From dac20e22a386f6bde91fe7e2824444c8c6fa51ad Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Thu, 12 Sep 2024 01:47:48 +0200 Subject: [PATCH 1/2] feat(apm-*): only build docs if there's a doc change extend the check to all apm repositories and use a switch to make it easier to add more repo that share common file patterns --- .buildkite/scripts/build_pr.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.buildkite/scripts/build_pr.sh b/.buildkite/scripts/build_pr.sh index caf05ea2979c..85923e6f7e8b 100755 --- a/.buildkite/scripts/build_pr.sh +++ b/.buildkite/scripts/build_pr.sh @@ -54,12 +54,27 @@ if [[ "${GITHUB_PR_BASE_REPO}" != 'docs' ]]; then git fetch origin pull/$GITHUB_PR_NUMBER/head:pr_$GITHUB_PR_NUMBER && git switch pr_$GITHUB_PR_NUMBER - if [[ "${GITHUB_PR_BASE_REPO}" == 'apm-agent-go' ]]; then - git fetch origin "$GITHUB_PR_TARGET_BRANCH" - docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs CHANGELOG.asciidoc) - else - docs_diff="always build" - fi + case $GITHUB_PR_BASE_REPO in + + "apm-aws-lambda" | "apm-agent-android" | "apm-agent-nodejs" | "apm-agent-python" | "apm-agent-ruby" | "apm-agent-rum-js" | "apm-agent-go" | "apm-agent-java" | "apm-agent-dotnet" | "apm-agent-php" | "apm-agent-ios") + git fetch origin "$GITHUB_PR_TARGET_BRANCH" + docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs CHANGELOG.asciidoc) + ;; + + "apm-k8s-attacher") + git fetch origin "$GITHUB_PR_TARGET_BRANCH" + docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs) + ;; + + "apm-server") + git fetch origin "$GITHUB_PR_TARGET_BRANCH" + docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs ./changelogs CHANGELOG.asciidoc) + ;; + + *) + docs_diff="always build" + ;; + esac if [[ -z $docs_diff ]]; then echo "pull/${GITHUB_PR_NUMBER} in ${GITHUB_PR_BASE_REPO} has no docs changes compared to ${GITHUB_PR_TARGET_BRANCH}" From 0772c90620b832aca950f55b207957910b6c2163 Mon Sep 17 00:00:00 2001 From: Brandon Morelli Date: Wed, 11 Sep 2024 17:46:47 -0700 Subject: [PATCH 2/2] add comments --- .buildkite/scripts/build_pr.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.buildkite/scripts/build_pr.sh b/.buildkite/scripts/build_pr.sh index 85923e6f7e8b..70fa3c9cd8ce 100755 --- a/.buildkite/scripts/build_pr.sh +++ b/.buildkite/scripts/build_pr.sh @@ -54,33 +54,42 @@ if [[ "${GITHUB_PR_BASE_REPO}" != 'docs' ]]; then git fetch origin pull/$GITHUB_PR_NUMBER/head:pr_$GITHUB_PR_NUMBER && git switch pr_$GITHUB_PR_NUMBER + # Some repositories allow the documentation build to exit early if there are no doc-related changes + # For these repos, we fetch the latest changes from the target branch of the pull request and check + # for changes in specified files and directories with git diff. case $GITHUB_PR_BASE_REPO in + # repositories with a docs dir and changelog "apm-aws-lambda" | "apm-agent-android" | "apm-agent-nodejs" | "apm-agent-python" | "apm-agent-ruby" | "apm-agent-rum-js" | "apm-agent-go" | "apm-agent-java" | "apm-agent-dotnet" | "apm-agent-php" | "apm-agent-ios") git fetch origin "$GITHUB_PR_TARGET_BRANCH" docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs CHANGELOG.asciidoc) ;; - + + # repositories with a docs dir "apm-k8s-attacher") git fetch origin "$GITHUB_PR_TARGET_BRANCH" docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs) ;; - + + # repositories with a docs dir, changelogs dir, and changelog "apm-server") git fetch origin "$GITHUB_PR_TARGET_BRANCH" docs_diff=$(git diff --stat "origin/$GITHUB_PR_TARGET_BRANCH"...HEAD -- ./docs ./changelogs CHANGELOG.asciidoc) ;; + # All other repos will always build *) docs_diff="always build" ;; esac + # If docs_diff is empty, exit early and succeed if [[ -z $docs_diff ]]; then echo "pull/${GITHUB_PR_NUMBER} in ${GITHUB_PR_BASE_REPO} has no docs changes compared to ${GITHUB_PR_TARGET_BRANCH}" exit 0 fi + # Regardless of whether we build or not, we print out the diff echo "diff:" echo "$docs_diff"