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

buildkite: skip clone for GitHub check notifications #3106

Merged
merged 7 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 23 additions & 5 deletions .buildkite/build_pr_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ steps:
command: ".buildkite/scripts/cancel_running_pr.sh || true"
- key: "build-pr-setup"
label: "setup"
command: ".buildkite/scripts/build_pr_commit_status.sh pending"
command: |
curl -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $${VAULT_GITHUB_TOKEN}" \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid interpolation and therefore exposing credentials

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an interesting read in Slack

-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \
-d '{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}'
plugins:
- 'uber-workflow/run-without-clone':
- key: "build-pr"
label: ":hammer: Build docs PR"
command: ".buildkite/scripts/build_pr.sh"
Expand All @@ -21,11 +30,20 @@ steps:
- key: "teardown"
label: "teardown"
command: |
if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then
.buildkite/scripts/build_pr_commit_status.sh success
else
.buildkite/scripts/build_pr_commit_status.sh failure
status_state=failure
if [ $$(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then
status_state=success
Comment on lines -24 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, is there a performance reason for changing this logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these 2 steps take about ~ 25 seconds each, and that's only to notify the status in the GitHub PRs using GH checks. I came up with this after discussing different areas of improvement in https://github.com/elastic/observability-robots/issues/2408

In a nutshell, Buildkite does not allow to skip the checkout or speed up the checkout out of the box. In this case, I decided to remove the script from the repository and use the content in the Buildkite pipeline - by doing so, those 2 steps don't need the cloned repository.

However, if this complicates things, we can keep it as is.

fi
export status_state
curl -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $${VAULT_GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \
-d '{"state":"'$$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}'
depends_on:
- step: "build-pr"
allow_failure: true
plugins:
- 'uber-workflow/run-without-clone':
33 changes: 0 additions & 33 deletions .buildkite/scripts/build_pr_commit_status.sh

This file was deleted.