Skip to content

Commit a32fbb3

Browse files
authored
Merge branch '8.19' into backport/8.19/pr-251297
2 parents e33514c + a964d1d commit a32fbb3

5 files changed

Lines changed: 225 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/rre.schema.json
2+
apiVersion: backstage.io/v1alpha1
3+
kind: Resource
4+
metadata:
5+
name: bk-kibana-scout-update-metadata
6+
description: Updates Scout test config manifests and opens a PR with the changes
7+
links:
8+
- url: 'https://buildkite.com/elastic/kibana-scout-update-metadata'
9+
title: Pipeline link
10+
spec:
11+
type: buildkite-pipeline
12+
owner: 'group:kibana-operations'
13+
system: buildkite
14+
implementation:
15+
apiVersion: buildkite.elastic.dev/v1
16+
kind: Pipeline
17+
metadata:
18+
name: kibana / scout / update-metadata
19+
description: Updates Scout test config manifests and opens a PR with the changes
20+
spec:
21+
env:
22+
SLACK_NOTIFICATIONS_CHANNEL: '#kibana-operations-alerts'
23+
ELASTIC_SLACK_NOTIFICATIONS_ENABLED: 'true'
24+
allow_rebuilds: true
25+
# Schedules set BUILDKITE_BRANCH; the step uses it as the PR base. Add a schedule per target branch.
26+
branch_configuration: main 9.3 9.2 8.19
27+
cancel_intermediate_builds: true
28+
default_branch: main
29+
repository: elastic/kibana
30+
pipeline_file: .buildkite/pipelines/scout_update_metadata.yml
31+
provider_settings:
32+
build_branches: false
33+
build_pull_requests: false
34+
publish_commit_status: false
35+
trigger_mode: none
36+
prefix_pull_request_fork_branch_names: false
37+
skip_pull_request_builds_for_existing_commits: false
38+
teams:
39+
everyone:
40+
access_level: BUILD_AND_READ
41+
kibana-operations:
42+
access_level: MANAGE_BUILD_AND_READ
43+
appex-qa:
44+
access_level: MANAGE_BUILD_AND_READ
45+
kibana-tech-leads:
46+
access_level: MANAGE_BUILD_AND_READ
47+
schedules:
48+
Daily (main):
49+
cronline: 0 0 * * * America/New_York
50+
message: Daily Scout metadata update
51+
branch: main
52+
Daily (9.3):
53+
cronline: 0 0 * * * America/New_York
54+
message: Daily Scout metadata update
55+
branch: '9.3'
56+
Daily (9.2):
57+
cronline: 0 0 * * * America/New_York
58+
message: Daily Scout metadata update
59+
branch: '9.2'
60+
Daily (8.19):
61+
cronline: 0 0 * * * America/New_York
62+
message: Daily Scout metadata update
63+
branch: '8.19'
64+
tags:
65+
- kibana

.buildkite/pipeline-resource-definitions/locations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ spec:
2828
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-performance-data-set-extraction-daily.yml
2929
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-pr.yml
3030
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-purge-cloud-deployments.yml
31+
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-scout-update-metadata.yml
3132
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-serverless-emergency-release.yml
3233
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-serverless-quality-gates.yml
3334
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-serverless-quality-gates-emergency.yml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
steps:
2+
- command: .buildkite/scripts/steps/scout_update_metadata.sh
3+
label: 'Update Scout test metadata'
4+
timeout_in_minutes: 30
5+
agents:
6+
image: family/kibana-ubuntu-2404
7+
imageProject: elastic-images-prod
8+
provider: gcp
9+
machineType: n2-standard-4
10+
preemptible: true
11+
spotZones: us-central1-f,us-central1-c,us-central1-a
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
report_step() {
5+
echo "--- $1"
6+
}
7+
8+
# Ensure we're in the repo root
9+
cd "${KIBANA_DIR:-$(pwd)}"
10+
11+
# Target branch for the PR (set by Buildkite from the schedule's branch; override via BUILDKITE_BRANCH when triggering manually)
12+
TARGET_BRANCH="${BUILDKITE_BRANCH:-main}"
13+
echo "Target branch for PR: $TARGET_BRANCH"
14+
15+
# Capture working tree state before bootstrap so we can detect bootstrap-induced changes
16+
report_step "Capturing pre-bootstrap state"
17+
pre_bootstrap_diff=$(git diff --no-ext-diff 2>/dev/null || true)
18+
pre_bootstrap_untracked=$(git status -s -u 2>/dev/null || true)
19+
20+
report_step "Bootstrap Kibana"
21+
.buildkite/scripts/bootstrap.sh
22+
23+
# Fail if bootstrap changed anything; only metadata update changes should be committed
24+
report_step "Verifying bootstrap did not change files"
25+
post_bootstrap_diff=$(git diff --no-ext-diff 2>/dev/null || true)
26+
post_bootstrap_untracked=$(git status -s -u 2>/dev/null || true)
27+
if [[ "$pre_bootstrap_diff" != "$post_bootstrap_diff" || "$pre_bootstrap_untracked" != "$post_bootstrap_untracked" ]]; then
28+
echo "Bootstrap produced changes to the working tree. Only Scout metadata updates should be committed. Aborting."
29+
exit 1
30+
fi
31+
32+
report_step "Update Scout test config manifests"
33+
node scripts/scout.js update-test-config-manifests
34+
35+
# Check for changes from the metadata update
36+
if git diff --exit-code --quiet 2>/dev/null && git diff --cached --exit-code --quiet 2>/dev/null; then
37+
echo "No Scout metadata changes. Nothing to commit."
38+
exit 0
39+
fi
40+
41+
report_step "Scout metadata changed. Creating pull request."
42+
43+
KIBANA_MACHINE_USERNAME="kibanamachine"
44+
git config --global user.name "$KIBANA_MACHINE_USERNAME"
45+
git config --global user.email '42973632+kibanamachine@users.noreply.github.com'
46+
47+
PR_TITLE='[Scout] Update test config manifests'
48+
BRANCH_NAME="scout_metadata_update_$(date +%s)"
49+
50+
# Check if an open PR with the same title targeting this base already exists
51+
existing_pr_json=$(gh pr list --base "$TARGET_BRANCH" --search "$PR_TITLE" --state open --author "$KIBANA_MACHINE_USERNAME" --limit 1 --json number,headRefName,title 2>/dev/null || true)
52+
existing_pr_title=$(echo "$existing_pr_json" | jq -r '.[0].title // empty')
53+
if [[ "$existing_pr_title" == "$PR_TITLE" ]]; then
54+
existing_branch=$(echo "$existing_pr_json" | jq -r '.[0].headRefName // empty')
55+
existing_pr_number=$(echo "$existing_pr_json" | jq -r '.[0].number // empty')
56+
echo "An open PR for Scout metadata update (base $TARGET_BRANCH) already exists. Updating PR #$existing_pr_number (branch: $existing_branch) via force-push."
57+
git checkout -b "$BRANCH_NAME"
58+
git add -A
59+
git commit -m "[Scout] Update test config manifests"
60+
git push origin "$BRANCH_NAME:$existing_branch" --force
61+
echo "Updated existing PR: https://github.com/elastic/kibana/pull/$existing_pr_number"
62+
exit 0
63+
fi
64+
65+
git checkout -b "$BRANCH_NAME"
66+
git add -A
67+
git commit -m "[Scout] Update test config manifests"
68+
69+
report_step "Pushing branch and creating PR (base: $TARGET_BRANCH)"
70+
git push origin "$BRANCH_NAME"
71+
72+
pr_url=$(gh pr create --repo elastic/kibana --base "$TARGET_BRANCH" --head "$BRANCH_NAME" \
73+
--title "$PR_TITLE" \
74+
--body "Generated by $BUILDKITE_BUILD_URL" \
75+
--label 'release_note:skip')
76+
echo "Opened PR: $pr_url"
77+
78+
gh pr merge --repo elastic/kibana --auto --squash "$pr_url"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Generic auto-approve for machine-created PRs.
2+
# Add new rules to the whitelist in the check step; approval runs when any rule matches.
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
8+
jobs:
9+
approve:
10+
name: Auto-approve machine PR
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- id: check
16+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
17+
with:
18+
script: |
19+
const user = context.payload.pull_request.user.login;
20+
const headRef = context.payload.pull_request.head.ref;
21+
const baseRef = context.payload.pull_request.base.ref;
22+
23+
const whitelist = [
24+
// { user: 'kibanamachine', branchPrefix: 'api_docs', baseMatch: /^main$/ },
25+
// { user: 'kibanamachine', branchPrefix: 'backport', baseNotMatch: /^main$/ },
26+
{ user: 'kibanamachine', branchPrefix: 'scout_metadata_update' },
27+
// { user: 'elasticmachine', branchPrefix: 'update-bundled-packages', paths: ['fleet_packages.json'] },
28+
];
29+
30+
// Fetch the list of changed files in the PR
31+
const files = await github.rest.pulls.listFiles({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
pull_number: context.payload.pull_request.number,
35+
});
36+
37+
const changedFiles = files.data.map(file => file.filename);
38+
core.info(`Changed files: ${changedFiles.join(', ')}`);
39+
40+
const matches = whitelist.some((rule) => {
41+
if (rule.user !== user) return false;
42+
if (!headRef.startsWith(rule.branchPrefix)) return false;
43+
if (rule.baseMatch && !rule.baseMatch.test(baseRef)) return false;
44+
if (rule.baseNotMatch && rule.baseNotMatch.test(baseRef)) return false;
45+
46+
// If paths is specified, verify at least one changed file matches
47+
if (rule.paths) {
48+
const hasMatchingFile = changedFiles.some(file =>
49+
rule.paths.some(path => {
50+
// Support glob patterns
51+
if (path.includes('*')) {
52+
const regex = new RegExp('^' + path.replace(/\*/g, '.*') + '$');
53+
return regex.test(file);
54+
}
55+
return file === path;
56+
})
57+
);
58+
if (!hasMatchingFile) {
59+
core.info(`File check failed for rule ${rule.user}/${rule.branchPrefix}: no changed files match paths`);
60+
return false;
61+
}
62+
}
63+
64+
return true;
65+
});
66+
67+
core.setOutput('should_approve', matches ? 'true' : 'false');
68+
69+
- uses: hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363 # v4.0.0
70+
if: steps.check.outputs.should_approve == 'true'

0 commit comments

Comments
 (0)