|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# NOTE: this script is meant to be run on the GitLab CI, it depends on GitLab CI variables |
| 5 | +# Based on https://github.com/signalfx/splunk-otel-java/blob/c9134906c84e9a32a974dec4b380453fe1757410/scripts/propagate-version.sh |
| 6 | + |
| 7 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 8 | + |
| 9 | +# shellcheck source-path=SCRIPTDIR |
| 10 | +source "${SCRIPT_DIR}/common.sh" |
| 11 | + |
| 12 | +ROOT_DIR="${SCRIPT_DIR}/../" |
| 13 | +cd "${ROOT_DIR}" |
| 14 | + |
| 15 | +create_collector_pr() { |
| 16 | + local repo="signalfx/splunk-otel-collector" |
| 17 | + local repo_url="https://srv-gh-o11y-gdi:${GITHUB_TOKEN}@github.com/${repo}.git" |
| 18 | + local branch="create-pull-request/update-javaagent" |
| 19 | + local message="Update splunk-otel-javaagent to latest" |
| 20 | + |
| 21 | + echo ">>> Cloning the $repo repository ..." |
| 22 | + git clone "$repo_url" collector-mirror |
| 23 | + cd collector-mirror |
| 24 | + |
| 25 | + setup_branch "$branch" "$repo_url" |
| 26 | + |
| 27 | + echo ">>> Getting latest splunk-otel-javaagent release ..." |
| 28 | + tag="$( gh release view --repo "https://github.com/signalfx/splunk-otel-java" --json tagName --jq 'select(.isDraft|not and .isPrelease|not) | .tagName' )" |
| 29 | + if [[ -n "$tag" ]]; then |
| 30 | + echo ">>> Updating splunk-otel-javaagent version to $tag ..." |
| 31 | + echo "$tag" > instrumentation/packaging/java-agent-release.txt |
| 32 | + else |
| 33 | + echo "ERROR: Failed to get latest release tag from https://github.com/signalfx/splunk-otel-java !" >&2 |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + |
| 37 | + # Only create the PR if there are changes |
| 38 | + if ! git diff --exit-code >/dev/null 2>&1; then |
| 39 | + git commit -S -am "$message" |
| 40 | + git push -f "$repo_url" "$branch" |
| 41 | + echo ">>> Creating the PR ..." |
| 42 | + gh pr create \ |
| 43 | + --draft \ |
| 44 | + --repo "$repo" \ |
| 45 | + --title "$message" \ |
| 46 | + --body "$message" \ |
| 47 | + --base main \ |
| 48 | + --head "$branch" |
| 49 | + fi |
| 50 | +} |
| 51 | + |
| 52 | +setup_gpg |
| 53 | +import_gpg_secret_key "$GITHUB_BOT_GPG_KEY" |
| 54 | +setup_git |
| 55 | +create_collector_pr |
0 commit comments