Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,68 @@ exports[`generatePipelines should generate correct pipelines with a non-docs cha
},
]
`;

exports[`generatePipelines should generate correct pipelines with a different branch that is not skipped 1`] = `
[
{
"name": "bwc-snapshots",
"pipeline": {
"steps": [
{
"group": "bwc-snapshots",
"steps": [
{
"agents": {
"buildDirectory": "/dev/shm/bk",
"image": "family/elasticsearch-ubuntu-2404",
"machineType": "custom-32-98304",
"provider": "gcp",
},
"command": ".ci/scripts/run-gradle.sh -Dignore.tests.seed v{{matrix.BWC_VERSION}}#bwcTest",
"env": {
"BWC_VERSION": "{{matrix.BWC_VERSION}}",
},
"label": "{{matrix.BWC_VERSION}} / bwc-snapshots",
"matrix": {
"setup": {
"BWC_VERSION": [
"7.17.14",
"8.10.3",
"8.11.0",
],
},
},
"timeout_in_minutes": 300,
},
],
},
],
},
},
{
"name": "skip-branch",
"pipeline": {
"steps": [
{
"command": "echo 1",
"label": "skip-me",
},
],
},
},
{
"name": "using-defaults",
"pipeline": {
"env": {
"CUSTOM_ENV_VAR": "value",
},
"steps": [
{
"command": "echo 'hello world'",
"label": "test-step",
},
],
},
},
]
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config:
skip-target-branches: "test-branch"
steps:
- label: skip-me
command: echo 1
7 changes: 7 additions & 0 deletions .buildkite/scripts/pull-request/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("generatePipelines", () => {
setBwcVersionsPath(`${import.meta.dir}/mocks/bwcVersions`);
setSnapshotBwcVersionsPath(`${import.meta.dir}/mocks/snapshotBwcVersions`);

process.env["GITHUB_PR_TARGET_BRANCH"] = "test-branch";
process.env["GITHUB_PR_LABELS"] = "test-label-1,test-label-2";
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "";
});
Expand Down Expand Up @@ -36,6 +37,12 @@ describe("generatePipelines", () => {
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
});

test("should generate correct pipelines with a different branch that is not skipped", () => {
process.env["GITHUB_PR_TARGET_BRANCH"] = "main";

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

test("should generate correct pipeline when using a trigger comment for it", () => {
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "run elasticsearch-ci/using-defaults";

Expand Down
9 changes: 9 additions & 0 deletions .buildkite/scripts/pull-request/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ const changedFilesIncludedCheck = (pipeline: EsPipeline, changedFiles: string[])
return true;
};

const checkTargetBranch = (pipeline: EsPipeline, targetBranch: string | undefined) => {
if (!targetBranch || !pipeline.config?.["skip-target-branches"]) {
return true;
}

return !getArray(pipeline.config["skip-target-branches"]).some((branch) => branch === targetBranch);
};

const triggerCommentCheck = (pipeline: EsPipeline): boolean => {
if (process.env["GITHUB_PR_TRIGGER_COMMENT"] && pipeline.config?.["trigger-phrase"]) {
return !!process.env["GITHUB_PR_TRIGGER_COMMENT"].match(pipeline.config["trigger-phrase"]);
Expand Down Expand Up @@ -138,6 +146,7 @@ export const generatePipelines = (
}

let filters: ((pipeline: EsPipeline) => boolean)[] = [
(pipeline) => checkTargetBranch(pipeline, process.env["GITHUB_PR_TARGET_BRANCH"]),
(pipeline) => labelCheckAllow(pipeline, labels),
(pipeline) => labelCheckSkip(pipeline, labels),
(pipeline) => changedFilesExcludedCheck(pipeline, changedFiles),
Expand Down
1 change: 1 addition & 0 deletions .buildkite/scripts/pull-request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type EsPipelineConfig = {
"included-regions"?: string | string[];
"excluded-regions"?: string | string[];
"trigger-phrase"?: string;
"skip-target-branches"?: string | string[];
};
};

Expand Down