diff --git a/.gitlab/common.sh b/.gitlab/common.sh index ac29811d85..2f93e6160d 100755 --- a/.gitlab/common.sh +++ b/.gitlab/common.sh @@ -72,23 +72,35 @@ validate_version() { fi } +get_pr_count() { + local branch="$1" + local repo_url="$2" + + pr_count="$( gh pr list --repo "$repo_url" --head "$branch" --state open --json id --jq length )" + if [[ ! "$pr_count" =~ ^[0-9]+$ ]]; then + echo "ERROR: Failed to get PRs for the $branch branch!" >&2 + echo "$pr_count" >&2 + exit 1 + fi + + echo "$pr_count" +} + setup_branch() { local branch="$1" local repo_url="$2" + local check_for_pr="${3:-true}" # check if the branch exists if git ls-remote --exit-code --heads origin "$branch"; then - # get number of open PRs for the branch - pr_count="$( gh pr list --repo "$repo_url" --head "$branch" --state open --json id --jq length )" - if [[ ! "$pr_count" =~ ^[0-9]+$ ]]; then - echo "ERROR: Failed to get PRs for the $branch branch!" >&2 - echo "$pr_count" >&2 - exit 1 - fi - if [[ "$pr_count" != "0" ]]; then - echo ">>> The $branch branch exists and has $pr_count open PR(s)." - echo ">>> Nothing to do." - exit 0 + if [ "$check_for_pr" = "true" ]; then + # get number of open PRs for the branch + pr_count="$( get_pr_count "$branch" "$repo_url" )" + if [[ "$pr_count" != "0" ]]; then + echo ">>> The $branch branch exists and has $pr_count open PR(s)." + echo ">>> Nothing to do." + exit 0 + fi fi echo ">>> Resetting the $branch branch to main ..." git checkout "$branch" diff --git a/.gitlab/update-otel-deps.sh b/.gitlab/update-otel-deps.sh index 13e404f11c..6a89af1695 100755 --- a/.gitlab/update-otel-deps.sh +++ b/.gitlab/update-otel-deps.sh @@ -18,12 +18,16 @@ create_collector_pr() { local repo="signalfx/splunk-otel-collector" local repo_url="https://srv-gh-o11y-gdi:${GITHUB_TOKEN}@github.com/${repo}.git" local message="Update OpenTelemetry Dependencies to $OTEL_VERSION" + local check_for_pr="true" + if [ "$OTEL_VERSION" = "main" ]; then + check_for_pr="false" + fi echo ">>> Cloning the $repo repository ..." git clone "$repo_url" collector-mirror cd collector-mirror - setup_branch "$BRANCH" "$repo_url" + setup_branch "$BRANCH" "$repo_url" "$check_for_pr" echo ">>> Updating otel deps to $OTEL_VERSION ..." OTEL_VERSION="$OTEL_VERSION" ./internal/buildscripts/update-deps @@ -32,14 +36,17 @@ create_collector_pr() { if ! git diff --exit-code >/dev/null 2>&1; then git commit -S -am "$message" git push -f "$repo_url" "$BRANCH" - echo ">>> Creating the PR ..." - gh pr create \ - --draft \ - --repo "$repo" \ - --title "$message" \ - --body "$message" \ - --base main \ - --head "$BRANCH" + pr_count="$( get_pr_count "$BRANCH" "$repo_url" )" + if [ "$pr_count" = "0" ]; then + echo ">>> Creating the PR ..." + gh pr create \ + --draft \ + --repo "$repo" \ + --title "$message" \ + --body "$message" \ + --base main \ + --head "$BRANCH" + fi fi }