diff --git a/.circleci/config.yml b/.circleci/config.yml index 8f4efcf698..9f73c2df05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,8 +8,8 @@ jobs: - run: apt-get install -y make - checkout - run: - name: Rebase on-top of latest develop - command: ./devops/scripts/rebase-develop.sh + name: Rebase on-top of github target + command: ./devops/scripts/rebase-ci.sh - setup_remote_docker - run: TAG=${CIRCLE_SHA1} make ci-lint-image @@ -27,8 +27,8 @@ jobs: - run: apt-get install -y make - checkout - run: - name: Rebase on-top of latest develop - command: ./devops/scripts/rebase-develop.sh + name: Rebase on-top of github target + command: ./devops/scripts/rebase-ci.sh - setup_remote_docker - restore_cache: @@ -133,8 +133,8 @@ jobs: - checkout - run: - name: Rebase on-top of latest develop - command: ./devops/scripts/rebase-develop.sh + name: Rebase on-top of github target + command: ./devops/scripts/rebase-ci.sh - run: name: Installation apt pre-reqs diff --git a/devops/scripts/rebase-develop.sh b/devops/scripts/rebase-ci.sh similarity index 53% rename from devops/scripts/rebase-develop.sh rename to devops/scripts/rebase-ci.sh index b401a0da4a..c72e136e76 100755 --- a/devops/scripts/rebase-develop.sh +++ b/devops/scripts/rebase-ci.sh @@ -1,7 +1,13 @@ #!/bin/bash +# shellcheck disable=SC2086 +# +# To be utilized in CircleCI +# Determine target branch from PR number and rebase against that set -e +GITHUB_PR_URL="https://api.github.com/repos/freedomofpress/securedrop/pulls/${CIRCLE_PULL_REQUEST##*/}" + # If current branch is not master or doesnt start with release... if [[ "$CIRCLE_BRANCH" != "master" && "$CIRCLE_BRANCH" != release* ]]; then @@ -12,9 +18,14 @@ if [[ "$CIRCLE_BRANCH" != "master" && "$CIRCLE_BRANCH" != release* ]]; then # Ensure presensce of upstream remote git ls-remote --exit-code --quiet upstream 2>/dev/null || git remote add upstream https://github.com/freedomofpress/securedrop.git + # Determine target branch via API + # + # (We are togglin' between two upstream containers here - the constant is both have python3) + target_branch="$(curl -s ${GITHUB_PR_URL} | python3 -c 'import sys, json; print(json.load(sys.stdin)["base"]["ref"])')" + # Fetch and rebase onto the latest in develop - git fetch upstream develop - git rebase upstream/develop + git fetch upstream "${target_branch}" + git rebase "upstream/${target_branch}" # Print out the current head for debugging potential CI issues git rev-parse HEAD