Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apm-*): only build docs if there's a doc change #3066

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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