-
Notifications
You must be signed in to change notification settings - Fork 66
[ML] Automate patch version bump in CI pipeline #3030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edsavage
wants to merge
2
commits into
elastic:main
Choose a base branch
from
edsavage:feature/version-bump-patch-only
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env python | ||
| # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| # or more contributor license agreements. Licensed under the Elastic License | ||
| # 2.0 and the following additional limitation. Functionality enabled by the | ||
| # files subject to the Elastic License 2.0 may only be used in production when | ||
| # invoked by an Elasticsearch process with a license key installed that permits | ||
| # use of machine learning features. You may not use this file except in | ||
| # compliance with the Elastic License 2.0 and the foregoing additional | ||
| # limitation. | ||
| # | ||
| # Phase 2 of the ml-cpp version-bump pipeline (uploaded by | ||
| # dev-tools/version_bump_upload_phase2.sh after validate). Step-level `if` cannot | ||
| # use Buildkite meta-data; gating is done in that shell script instead. | ||
|
|
||
| import contextlib | ||
| import json | ||
| import os | ||
|
|
||
|
|
||
| WOLFI_IMAGE = "docker.elastic.co/release-eng/wolfi-build-essential-release-eng:latest" | ||
|
|
||
|
|
||
| def main(): | ||
| pipeline_steps = [ | ||
| { | ||
| "label": "Bump version to ${NEW_VERSION}", | ||
| "key": "bump-version", | ||
| "depends_on": "schedule-version-bump-follow-up", | ||
| "agents": { | ||
| "image": WOLFI_IMAGE, | ||
| "cpu": "250m", | ||
| "memory": "512Mi", | ||
| }, | ||
| "env": { | ||
| "VERSION_BUMP_MERGE_AUTO": os.environ.get("VERSION_BUMP_MERGE_AUTO", "true"), | ||
| }, | ||
| "command": [ | ||
| "dev-tools/bump_version.sh", | ||
| ], | ||
| }, | ||
| { | ||
| "label": "Notify :slack: — version bump PR needs approval", | ||
| "key": "queue-slack-notify", | ||
| "depends_on": "bump-version", | ||
| "command": [ | ||
| ".buildkite/pipelines/send_slack_version_bump_notification.sh", | ||
| ], | ||
| "agents": { | ||
| # Same image as bump-version: the minimal python image does not ship | ||
| # buildkite-agent, so meta-data get / pipeline upload silently skipped Slack. | ||
| "image": WOLFI_IMAGE, | ||
| "cpu": "250m", | ||
| "memory": "512Mi", | ||
| }, | ||
| }, | ||
| { | ||
| "label": "Fetch DRA Artifacts", | ||
| "key": "fetch-dra-artifacts", | ||
| "depends_on": "queue-slack-notify", | ||
| "agents": { | ||
| "image": WOLFI_IMAGE, | ||
| "cpu": "250m", | ||
| "memory": "512Mi", | ||
| "ephemeralStorage": "1Gi", | ||
| }, | ||
| "command": [ | ||
| "python3", | ||
| "dev-tools/wait_version_bump_dra.py", | ||
| ], | ||
| "timeout_in_minutes": 240, | ||
| "retry": { | ||
| "automatic": [{"exit_status": "*", "limit": 2}], | ||
| "manual": {"permit_on_passed": True}, | ||
| }, | ||
| }, | ||
| ] | ||
|
|
||
| print(json.dumps({"steps": pipeline_steps}, indent=2)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| with contextlib.suppress(KeyboardInterrupt): | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.buildkite/pipelines/send_slack_version_bump_notification.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| # or more contributor license agreements. Licensed under the Elastic License | ||
| # 2.0 and the following additional limitation. Functionality enabled by the | ||
| # files subject to the Elastic License 2.0 may only be used in production when | ||
| # invoked by an Elasticsearch process with a license key installed that permits | ||
| # use of machine learning features. You may not use this file except in | ||
| # compliance with the Elastic License 2.0 and the foregoing additional | ||
| # limitation. | ||
| # | ||
| # Single Slack notification for the ml-cpp-version-bump pipeline: runs after the | ||
| # bump step opens the PR. Reads ml_cpp_version_bump_pr_url from Buildkite meta-data | ||
| # (set by dev-tools/bump_version.sh) and posts the PR link so reviewers can approve. | ||
| # | ||
| # Slack notify must live on the step (see Buildkite docs): build-level notify fires only | ||
| # on build.finished — after every downstream step including long DRA waits — so the | ||
| # message would appear hours late or never if someone checks earlier. | ||
| # | ||
| # Optional env: | ||
| # ML_CPP_VERSION_BUMP_SLACK_CHANNEL — override channel (default #machine-learn-build) | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| CHANNEL="${ML_CPP_VERSION_BUMP_SLACK_CHANNEL:-#machine-learn-build}" | ||
|
|
||
| if [[ "${BUILDKITE:-}" != "true" ]]; then | ||
| echo "BUILDKITE is not true — skipping Slack notification (local run)." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! command -v buildkite-agent >/dev/null 2>&1; then | ||
| echo "ERROR: buildkite-agent not in PATH; cannot read meta-data or upload Slack notify pipeline." >&2 | ||
| echo "Use the same agent image as bump-version (Wolfi), not a minimal python image." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| pr_url="" | ||
| changed="false" | ||
| pr_url=$(buildkite-agent meta-data get "ml_cpp_version_bump_pr_url" 2>/dev/null || true) | ||
| changed=$(buildkite-agent meta-data get "ml_cpp_version_bump_changed" 2>/dev/null || echo "false") | ||
| # Meta-data values must not contain stray whitespace (Breaks truthiness.) | ||
| pr_url=$(echo -n "${pr_url}" | tr -d '\r') | ||
| changed=$(echo -n "${changed}" | tr -d '\r') | ||
|
|
||
| if [[ -z "${pr_url}" && "${changed}" != "true" ]]; then | ||
| echo "No version-bump PR opened (pr_url empty, ml_cpp_version_bump_changed=${changed}); skipping Slack notification." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ -z "${pr_url}" && "${changed}" == "true" ]]; then | ||
| body_line="DRY RUN — no pull request URL (simulated bump)." | ||
| else | ||
| body_line="Pull request (approval required): ${pr_url}" | ||
| fi | ||
|
|
||
| ( | ||
| cat <<EOF | ||
| steps: | ||
| - label: "Schedule :slack: notification (version bump)" | ||
| command: "echo schedule :slack: notification" | ||
| notify: | ||
| - slack: | ||
| channels: | ||
| - "${CHANNEL}" | ||
| message: | | ||
| **Version bump PR — approval required** | ||
| ${body_line} | ||
| Branch: \${BUILDKITE_BRANCH} | ||
| NEW_VERSION: \${NEW_VERSION:-"(unset)"} | ||
| BRANCH (param): \${BRANCH:-"(unset)"} | ||
| VERSION_BUMP_MERGE_AUTO: \${VERSION_BUMP_MERGE_AUTO:-"(unset)"} | ||
| DRY_RUN: \${DRY_RUN:-"(unset)"} | ||
| Pipeline: \${BUILDKITE_BUILD_URL} | ||
| Build: \${BUILDKITE_BUILD_NUMBER} | ||
| Please review and approve this pull request so it can merge (subject to branch protection). | ||
| EOF | ||
| ) | buildkite-agent pipeline upload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
WOLFI_IMAGEas well?