Skip to content

Commit b45d4c0

Browse files
authored
[ci] Add a way to trigger the entire regular PR pipeline via comment (#102256) (#102263)
1 parent c4cd840 commit b45d4c0

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

.buildkite/pull-requests.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"jobs": [
3+
{
4+
"enabled": true,
5+
"pipeline_slug": "elasticsearch-pull-request",
6+
"allow_org_users": true,
7+
"allowed_repo_permissions": [
8+
"admin",
9+
"write"
10+
],
11+
"set_commit_status": false,
12+
"build_on_commit": true,
13+
"build_on_comment": true,
14+
"trigger_comment_regex": "(run\\W+elasticsearch-ci.+)|(^\\s*(buildkite\\s*)?test\\s+this(\\s+please)?)",
15+
"cancel_intermediate_builds": true,
16+
"cancel_intermediate_builds_on_comment": false
17+
},
18+
{
19+
"enabled": true,
20+
"pipeline_slug": "elasticsearch-pull-request-check-serverless-submodule",
21+
"allow_org_users": true,
22+
"allowed_repo_permissions": [
23+
"admin",
24+
"write"
25+
],
26+
"set_commit_status": false,
27+
"build_on_commit": true,
28+
"build_on_comment": false,
29+
"labels": [
30+
"test-update-serverless"
31+
]
32+
}
33+
]
34+
}

.buildkite/scripts/pull-request/pipeline.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@ describe("generatePipelines", () => {
1212
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "";
1313
});
1414

15-
test("should generate correct pipelines with a non-docs change", () => {
16-
const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["build.gradle", "docs/README.asciidoc"]);
15+
// Helper for testing pipeline generations that should be the same when using the overall ci trigger comment "buildkite test this"
16+
const testWithTriggerCheck = (directory: string, changedFiles?: string[]) => {
17+
const pipelines = generatePipelines(directory, changedFiles);
1718
expect(pipelines).toMatchSnapshot();
19+
20+
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "buildkite test this";
21+
const pipelinesWithTriggerComment = generatePipelines(directory, changedFiles);
22+
expect(pipelinesWithTriggerComment).toEqual(pipelines);
23+
};
24+
25+
test("should generate correct pipelines with a non-docs change", () => {
26+
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle", "docs/README.asciidoc"]);
1827
});
1928

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

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

28-
const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
29-
expect(pipelines).toMatchSnapshot();
36+
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
3037
});
3138

3239
test("should generate correct pipeline when using a trigger comment for it", () => {

.buildkite/scripts/pull-request/pipeline.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ export const generatePipelines = (
144144
(pipeline) => changedFilesIncludedCheck(pipeline, changedFiles),
145145
];
146146

147-
// When triggering via comment, we ONLY want to run pipelines that match the trigger phrase, regardless of labels, etc
148-
if (process.env["GITHUB_PR_TRIGGER_COMMENT"]) {
147+
// 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
148+
// However, if we're using the overall CI trigger "[buildkite] test this [please]", we should use the regular filters above
149+
if (
150+
process.env["GITHUB_PR_TRIGGER_COMMENT"] &&
151+
!process.env["GITHUB_PR_TRIGGER_COMMENT"].match(/^\s*(buildkite\s*)?test\s+this(\s+please)?/i)
152+
) {
149153
filters = [triggerCommentCheck];
150154
}
151155

0 commit comments

Comments
 (0)