Skip to content

Commit

Permalink
Utilize github API to determine target PR branch
Browse files Browse the repository at this point in the history
This will hopefully resolve issues pertaining to PRs that target
non-develop branches and fail in particular ways (not to mention its not
an accurate test) when rebased against develop
  • Loading branch information
msheiny committed Jul 12, 2018
1 parent d3554e7 commit d9908dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions devops/scripts/rebase-develop.sh → devops/scripts/rebase-ci.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash
#
# 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

Expand All @@ -12,9 +17,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
Expand Down

0 comments on commit d9908dd

Please sign in to comment.