Skip to content

Commit

Permalink
feat(apm-*): only build docs if there's a doc change (#3066)
Browse files Browse the repository at this point in the history
* 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

* add comments

---------

Co-authored-by: Brandon Morelli <[email protected]>
  • Loading branch information
kruskall and bmorelli25 authored Sep 12, 2024
1 parent 6766ca7 commit 337a3cd
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions .buildkite/scripts/build_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +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

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

# 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"

Expand Down

0 comments on commit 337a3cd

Please sign in to comment.