Skip to content

Commit

Permalink
[ci] Add a way to trigger the entire regular PR pipeline via comment (e…
Browse files Browse the repository at this point in the history
…lastic#102256)

(cherry picked from commit 9063088)

# Conflicts:
#	.buildkite/pull-requests.json
  • Loading branch information
brianseeders committed Nov 15, 2023
1 parent 3b75543 commit 102e713
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
5 changes: 1 addition & 4 deletions .buildkite/pull-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"set_commit_status": false,
"build_on_commit": true,
"build_on_comment": true,
"trigger_comment_regex": "buildkite\\W+elasticsearch-ci.+",
"labels": [
"buildkite-opt-in"
],
"trigger_comment_regex": "(run\\W+elasticsearch-ci.+)|(^\\s*(buildkite\\s*)?test\\s+this(\\s+please)?)",
"cancel_intermediate_builds": true,
"cancel_intermediate_builds_on_comment": false
},
Expand Down
19 changes: 13 additions & 6 deletions .buildkite/scripts/pull-request/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ describe("generatePipelines", () => {
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "";
});

test("should generate correct pipelines with a non-docs change", () => {
const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["build.gradle", "docs/README.asciidoc"]);
// Helper for testing pipeline generations that should be the same when using the overall ci trigger comment "buildkite test this"
const testWithTriggerCheck = (directory: string, changedFiles?: string[]) => {
const pipelines = generatePipelines(directory, changedFiles);
expect(pipelines).toMatchSnapshot();

process.env["GITHUB_PR_TRIGGER_COMMENT"] = "buildkite test this";
const pipelinesWithTriggerComment = generatePipelines(directory, changedFiles);
expect(pipelinesWithTriggerComment).toEqual(pipelines);
};

test("should generate correct pipelines with a non-docs change", () => {
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle", "docs/README.asciidoc"]);
});

test("should generate correct pipelines with only docs changes", () => {
const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["docs/README.asciidoc"]);
expect(pipelines).toMatchSnapshot();
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["docs/README.asciidoc"]);
});

test("should generate correct pipelines with full BWC expansion", () => {
process.env["GITHUB_PR_LABELS"] = "test-full-bwc";

const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
expect(pipelines).toMatchSnapshot();
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
});

test("should generate correct pipeline when using a trigger comment for it", () => {
Expand Down
8 changes: 6 additions & 2 deletions .buildkite/scripts/pull-request/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ export const generatePipelines = (
(pipeline) => changedFilesIncludedCheck(pipeline, changedFiles),
];

// When triggering via comment, we ONLY want to run pipelines that match the trigger phrase, regardless of labels, etc
if (process.env["GITHUB_PR_TRIGGER_COMMENT"]) {
// When triggering via the "run elasticsearch-ci/step-name" comment, we ONLY want to run pipelines that match the trigger phrase, regardless of labels, etc
// However, if we're using the overall CI trigger "[buildkite] test this [please]", we should use the regular filters above
if (
process.env["GITHUB_PR_TRIGGER_COMMENT"] &&
!process.env["GITHUB_PR_TRIGGER_COMMENT"].match(/^\s*(buildkite\s*)?test\s+this(\s+please)?/i)
) {
filters = [triggerCommentCheck];
}

Expand Down

0 comments on commit 102e713

Please sign in to comment.