From 3b3cf8087628fc36948052d739241f7ae21f955f Mon Sep 17 00:00:00 2001 From: Zachary Sims Date: Wed, 13 Jun 2018 10:07:03 +1000 Subject: [PATCH 1/3] Adds a 'trigger' mode to kick off another build --- hooks/pre-checkout | 32 +++++++++++++++++++++++++++++++- tests/pre-checkout.bats | 16 ++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/hooks/pre-checkout b/hooks/pre-checkout index 8246c3f..509157a 100755 --- a/hooks/pre-checkout +++ b/hooks/pre-checkout @@ -2,10 +2,40 @@ set -euo pipefail -if [[ -n "${BUILDKITE_PULL_REQUEST}" && "${BUILDKITE_PULL_REQUEST}" != "false" ]] ; then +mode="checkout" +if [[ -v BUILDKITE_PLUGIN_GITHUB_MERGED_PR_MODE ]]; then + mode="${BUILDKITE_PLUGIN_GITHUB_MERGED_PR_MODE}" +fi + +function trigger_merged_build() { + local slug="${BUILDKITE_PIPELINE_SLUG}" + local pr="${BUILDKITE_PULL_REQUEST}" + local ref="refs/pull/${pr}/merge" + echo "--- Triggering merged build of ${slug} for PR ${pr} (ref ${ref})" + cat < Date: Wed, 13 Jun 2018 10:15:04 +1000 Subject: [PATCH 2/3] Kicks off the merged build async --- hooks/pre-checkout | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/pre-checkout b/hooks/pre-checkout index 509157a..745cae0 100755 --- a/hooks/pre-checkout +++ b/hooks/pre-checkout @@ -15,6 +15,7 @@ function trigger_merged_build() { cat < Date: Wed, 13 Jun 2018 10:17:34 +1000 Subject: [PATCH 3/3] Add readme notes for 0.0.5 --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 94aa753..c2fdcef 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,27 @@ # GitHub Pull Request Plugin -A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) to checkout the GitHub post-merge check PR ref (`refs/pull/123/merge`) rather than building the branch `HEAD`. +A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) to help build the GitHub post-merge check PR ref (`refs/pull/123/merge`). -This ensures tests run against the "merged" branch, helping catch bad merges. +This plugin helps you run CI run against the "merged" branch, helping catch bad merges. + +The plugin has two modes: + - `mode: trigger` to async trigger another build (of the current pipeline); and + - `mode: checkout` to checkout the PR merged ref (`refs/pull/123/merge`) rather than the head (`refs/pull/123/head`) ## Example ```yml steps: - plugins: - zsims/github-merged-pr#v0.0.4: ~ + zsims/github-merged-pr#v0.0.5: + mode: checkout +``` + +```yml +steps: + - plugins: + zsims/github-merged-pr#v0.0.5: + mode: trigger ``` Ensure `Skip pull request builds for existing commits` is set to `false` in your Pipeline settings, as BuildKite will build the branch and skip the PR build.