From 1ea8c7b55d31edd0001ab447687a0bf88c61d44c Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 31 Mar 2020 13:54:37 -0700 Subject: [PATCH] Fix case when pull request already exists If a PR with the given title exists, we clone the existing PR branch so that it doesn't get overridden by master. See gh-20530 --- ci/pipeline.yml | 1 + ci/scripts/create-pull-request.sh | 2 +- ci/scripts/detect-docker-updates.sh | 38 +++++++++++++++-------------- ci/tasks/detect-docker-updates.yml | 1 + 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index d7362c22b9..2a7222a9db 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -189,6 +189,7 @@ jobs: - name: detect-docker-updates plan: - get: git-repo + - get: git-repo-ci-docker - get: every-wednesday trigger: true - get: spring-boot-ci-image diff --git a/ci/scripts/create-pull-request.sh b/ci/scripts/create-pull-request.sh index b8e020288e..63f09db346 100755 --- a/ci/scripts/create-pull-request.sh +++ b/ci/scripts/create-pull-request.sh @@ -11,5 +11,5 @@ if [[ -f commit-details/message ]]; then -X \ POST "https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/pulls" > /dev/null || { echo "Failed to create pull request" >&2; exit 1; } else - echo "Already up-to-date" + echo "Already up-to-date." fi \ No newline at end of file diff --git a/ci/scripts/detect-docker-updates.sh b/ci/scripts/detect-docker-updates.sh index 7ef834ccf6..371a4e98cf 100755 --- a/ci/scripts/detect-docker-updates.sh +++ b/ci/scripts/detect-docker-updates.sh @@ -1,5 +1,16 @@ #!/bin/bash +existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/pulls\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster ) +existing_upgrade_issues=$( echo "$existing_tasks" | jq -c --arg TITLE "$ISSUE_TITLE" '.[] | select(.title==$TITLE)' ) + +if [[ ${existing_upgrade_issues} = "" ]]; then + git clone git-repo git-repo-updated > /dev/null +else + git clone git-repo-ci-docker git-repo-updated > /dev/null + echo "Pull request already exists." + exit 0 +fi + latest_version=$(curl -I -s https://github.com/docker/docker-ce/releases/latest | grep "location:" | awk '{n=split($0, parts, "/"); print substr(parts[n],2);}' | awk '{$1=$1;print}' | tr -d '\r' | tr -d '\n' ) if [[ $latest_version =~ (beta|rc) ]]; then @@ -15,21 +26,12 @@ if [[ $current = $latest ]]; then exit 0; fi -existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/pulls\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster ) -existing_upgrade_issues=$( echo "$existing_tasks" | jq -c --arg TITLE "$ISSUE_TITLE" '.[] | select(.title==$TITLE)' ) - -git clone git-repo git-repo-updated > /dev/null - -if [[ ${existing_upgrade_issues} = "" ]]; then - pushd git-repo-updated > /dev/null - git config user.name "Spring Buildmaster" > /dev/null - git config user.email "buildmaster@springframework.org" > /dev/null - sed -i "s/version=.*/version=\"$latest_version\"/" ci/images/get-docker-url.sh - git add ci/images/get-docker-url.sh > /dev/null - commit_message="Upgrade to Docker $latest_version in CI" - git commit -m "$commit_message" > /dev/null - popd - echo ${commit_message} > commit-details/message -else - echo "Pull request already exists." -fi +pushd git-repo-updated > /dev/null +git config user.name "Spring Buildmaster" > /dev/null +git config user.email "buildmaster@springframework.org" > /dev/null +sed -i "s/version=.*/version=\"$latest_version\"/" ci/images/get-docker-url.sh +git add ci/images/get-docker-url.sh > /dev/null +commit_message="Upgrade to Docker $latest_version in CI" +git commit -m "$commit_message" > /dev/null +popd +echo ${commit_message} > commit-details/message \ No newline at end of file diff --git a/ci/tasks/detect-docker-updates.yml b/ci/tasks/detect-docker-updates.yml index bfced31c98..73000e9449 100644 --- a/ci/tasks/detect-docker-updates.yml +++ b/ci/tasks/detect-docker-updates.yml @@ -2,6 +2,7 @@ platform: linux inputs: - name: git-repo + - name: git-repo-ci-docker outputs: - name: git-repo-updated - name: commit-details