|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +if [[ -z "${BUILDKITE_PULL_REQUEST:-}" ]]; then |
| 5 | + echo "Not a pull request, skipping transport version update" |
| 6 | + exit 0 |
| 7 | +fi |
| 8 | + |
| 9 | +if ! git diff --exit-code; then |
| 10 | + echo "Changes are present before updating transport versions, not running" |
| 11 | + git status |
| 12 | + exit 0 |
| 13 | +fi |
| 14 | + |
| 15 | +NEW_COMMIT_MESSAGE="[CI] Update transport version definitions" |
| 16 | + |
| 17 | +echo "--- Generating updated transport version definitions" |
| 18 | +# Calculate backport branches based on pull request version labels |
| 19 | +backport_branches=$( |
| 20 | + echo "${GITHUB_PR_LABELS}" \ |
| 21 | + | tr ',' '\n' \ |
| 22 | + | grep -E "v[0-9]+\.[0-9]+\.[0-9]+" \ |
| 23 | + | sed -E 's/^v([0-9]+)\.([0-9]+)\.[0-9]+$/\1.\2/' \ |
| 24 | + | paste -sd, - |
| 25 | +) |
| 26 | + |
| 27 | +if [[ -z "${backport_branches}" ]]; then |
| 28 | + echo "Skipping as pull request contains no version labels" |
| 29 | + exit 0 |
| 30 | +fi |
| 31 | + |
| 32 | +.ci/scripts/run-gradle.sh generateTransportVersion --backport-branches="${backport_branches}" |
| 33 | + |
| 34 | +if git diff --exit-code; then |
| 35 | + echo "No changes found after updating transport versions. Don't need to auto commit." |
| 36 | + exit 0 |
| 37 | +fi |
| 38 | + |
| 39 | +git config --global user.name elasticsearchmachine |
| 40 | +git config --global user.email '[email protected]' |
| 41 | + |
| 42 | +gh pr checkout "${BUILDKITE_PULL_REQUEST}" |
| 43 | +git add -A . |
| 44 | +git commit -m "$NEW_COMMIT_MESSAGE" |
| 45 | +git push |
| 46 | + |
| 47 | +# After the git push, the new commit will trigger a new build within a few seconds and this build should get cancelled |
| 48 | +# So, let's just sleep to give the build time to cancel itself without an error |
| 49 | +# If it doesn't get cancelled for some reason, then exit with an error, because we don't want this build to be green (we just don't want it to generate an error either) |
| 50 | +sleep 300 |
| 51 | +exit 1 |
0 commit comments