-
Notifications
You must be signed in to change notification settings - Fork 598
[backports] Add .backports.yml inventory, validator, and dry-run trigger (#19210) #19362
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
base: main
Are you sure you want to change the base?
Changes from 47 commits
2df0710
c864a16
d0336af
cc6346d
f5089b7
b708b96
d941937
534fbb8
85523c6
d9e05a9
42048a5
0c4698a
ce009ee
b1f1cc6
3a40a7e
6718cfb
05274f6
0c34bf0
ea3a4fd
99ec6bf
4b91e99
b0f9a53
454c7ac
d803643
a4dd077
03f4b78
6a09283
514e4b1
65f0990
2f8571a
305099c
956747b
35e57d8
382ecdb
9152481
a704c18
9dbedde
72ff7c6
6ad8428
9ca6828
3a3c25f
aeb87cb
7b30533
2a1d58a
4bea349
dcbbab2
58215a1
f60e65e
f237dd0
1436a4e
da0a5a0
3e36fd9
c45d060
d7fa665
9ca3737
23c6012
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
|
|
||
| source .buildkite/scripts/common.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| add_bin_path | ||
| with_mage | ||
| with_yq | ||
|
|
||
| echo "--- Validate .backports.yml inventory schema" | ||
| mage -d "${WORKSPACE}" -v validateBackportsInventory | ||
|
|
||
| echo "--- Check if any files modified" | ||
| check_git_diff |
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will trigger a DRY_RUN build of the integrations-backport for each new entry detected. For this first time, it has been set that it will not trigger any build. This is detected when in the main branch there is no It has also been set in the .buildkite/pipeline.yml file that this step is just triggered in Pull Requests targeting main brnach. if_changed:
- ".backports.yml"
if: |
build.env('BUILDKITE_PULL_REQUEST') != "false" &&
build.env('BUILDKITE_PIPELINE_SLUG') == "integrations" &&
build.env('BUILDKITE_PULL_REQUEST_BASE_BRANCH') == "main" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #!/bin/bash | ||
| # Triggered from the main pipeline when .backports.yml changes in a PR. | ||
| # For each entry that is new (absent from the base branch), uploads a trigger | ||
| # step that runs the integrations-backport pipeline in DRY_RUN mode. | ||
|
|
||
| source .buildkite/scripts/common.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if [[ "${BUILDKITE_PULL_REQUEST}" == "false" ]]; then | ||
| echo "Not a pull request, skipping backport dry-run trigger" | ||
| exit 0 | ||
| fi | ||
|
|
||
| add_bin_path | ||
| with_yq | ||
|
|
||
| from="$(get_from_changeset)" | ||
| to="$(get_to_changeset)" | ||
| commit_merge="$(git merge-base "${from}" "${to}")" | ||
|
|
||
| if ! git diff --name-only "${commit_merge}" "${to}" | grep -qE '^\.backports\.yml$'; then | ||
| echo ".backports.yml not changed, skipping backport dry-run trigger" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "--- .backports.yml changed — finding new entries" | ||
|
|
||
| BASE_BRANCH="${BUILDKITE_PULL_REQUEST_BASE_BRANCH}" | ||
|
|
||
| OLD_INVENTORY="" | ||
| PIPELINE_FILE="" | ||
|
|
||
| cleanup() { | ||
| local exit_code=$? | ||
| [[ -n "${OLD_INVENTORY}" ]] && rm -f "${OLD_INVENTORY}" | ||
| [[ -n "${PIPELINE_FILE}" ]] && rm -f "${PIPELINE_FILE}" | ||
| exit "${exit_code}" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| OLD_INVENTORY="$(mktemp)" | ||
| NEW_INVENTORY=".backports.yml" | ||
|
|
||
| if ! git show "origin/${BASE_BRANCH}:.backports.yml" > "${OLD_INVENTORY}" 2>/dev/null; then | ||
| echo ".backports.yml is new on ${BASE_BRANCH} — skipping dry-runs for initial entries" | ||
| echo "To validate new entries, add them in a follow-up PR after this one merges." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! yq -e '.backports' "${OLD_INVENTORY}" > /dev/null; then | ||
| echo "ERROR: old inventory is not valid YAML or missing 'backports' key: ${OLD_INVENTORY}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! yq -e '.backports' "${NEW_INVENTORY}" > /dev/null; then | ||
| echo "ERROR: new inventory is not valid YAML or missing 'backports' key: ${NEW_INVENTORY}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| PIPELINE_FILE="$(mktemp --suffix=.yml)" | ||
| entries_found=0 | ||
|
|
||
| while IFS= read -r branch; do | ||
| entry=".backports[] | select(.branch == \"${branch}\")" | ||
|
|
||
| archived="$(yq "${entry} | .archived" "${NEW_INVENTORY}")" | ||
| if [[ "${archived}" == "true" ]]; then | ||
| echo " Skipping archived entry: ${branch}" | ||
| continue | ||
| fi | ||
|
|
||
| # Only trigger for entries that are new (absent from the old inventory). | ||
| # If the entry already existed, the git branch is already created; there is | ||
| # nothing to provision. This also covers re-activating a previously archived | ||
| # entry (archived:true → false): the branch exists, so no dry-run is needed. | ||
| old_branch="$(yq "${entry} | .branch" "${OLD_INVENTORY}")" | ||
|
|
||
| if [[ -n "${old_branch}" ]]; then | ||
| echo " Skipping existing entry: ${branch} (already present in base branch)" | ||
| continue | ||
| fi | ||
|
|
||
| pkg="$(yq "${entry} | .package" "${NEW_INVENTORY}")" | ||
| base_version="$(yq "${entry} | .base_version" "${NEW_INVENTORY}")" | ||
| base_commit="$(yq "${entry} | .base_commit" "${NEW_INVENTORY}")" | ||
|
|
||
| echo " Queuing dry-run: ${branch} (package=${pkg} version=${base_version} base_commit=${base_commit})" | ||
|
|
||
| if [[ "${entries_found}" -eq 0 ]]; then | ||
| printf 'steps:\n' > "${PIPELINE_FILE}" | ||
| fi | ||
|
|
||
| cat >> "${PIPELINE_FILE}" <<EOF | ||
| - label: ":git: Backport dry-run: ${branch}" | ||
| trigger: "integrations-backport" | ||
| build: | ||
| env: | ||
| DRY_RUN: "true" | ||
| PACKAGE_NAME: "${pkg}" | ||
| PACKAGE_VERSION: "${base_version}" | ||
| BASE_COMMIT: "${base_commit}" | ||
| EOF | ||
|
|
||
| entries_found=$(( entries_found + 1 )) | ||
|
|
||
| done < <(yq '.backports[].branch' "${NEW_INVENTORY}") | ||
|
|
||
| rm -f "${OLD_INVENTORY}" | ||
|
|
||
| if [[ "${entries_found}" -eq 0 ]]; then | ||
| echo "No new non-archived entries found, skipping dry-run trigger" | ||
| rm -f "${PIPELINE_FILE}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "--- Uploading ${entries_found} dry-run trigger(s)" | ||
| cat "${PIPELINE_FILE}" | ||
| buildkite-agent pipeline upload "${PIPELINE_FILE}" | ||
| rm -f "${PIPELINE_FILE}" |
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.
To be removed before merging.
Keep it for now in case it is needed to push more changes.