Skip to content

Commit

Permalink
Setup CI to explicitly fetch upstream not just use master which may b…
Browse files Browse the repository at this point in the history
…e out of date on forks.

Fixes ros#24377

Signed-off-by: Tully Foote <[email protected]>
  • Loading branch information
tfoote committed Apr 7, 2020
1 parent e27f682 commit 556bff8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Fetch master (to enable diff)
- name: Fetch upstream (to enable diff)
run: |
git fetch --no-tags --depth=1 origin master
git remote add unittest_upstream_comparision [email protected]:ros/rosdistro.git || git remote set-url unittest_upstream_comparision [email protected]:ros/rosdistro.git
git fetch --no-tags --depth=1 unittest_upstream_comparision master
- name: Install Dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
32 changes: 28 additions & 4 deletions test/test_url_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
# for commented debugging code below
# import pprint

DIFF_TARGET = 'origin/master'
UPSTREAM_NAME = 'unittest_upstream_comparision'
DIFF_BRANCH = 'master'
DIFF_REPO = '[email protected]:ros/rosdistro.git'


TARGET_FILE_BLACKLIST = []
Expand Down Expand Up @@ -277,14 +279,36 @@ def isolate_yaml_snippets_from_line_numbers(yaml_dict, line_numbers):


def main():
cmd = ('git diff --unified=0 %s' % DIFF_TARGET).split()
diff = subprocess.check_output(cmd).decode('utf-8')
detected_errors = []

# See if UPSTREAM_NAME remote is available and use it as it's expected to be setup by CI
# Otherwise fall back to origin/master
try:
cmd = ('git config --get remote.%s.url' % UPSTREAM_NAME).split()
try:
remote_url = subprocess.check_output(cmd).decode('utf-8').strip()
# Remote exists
# Check url
if remote_url != DIFF_REPO:
detected_errors.append('%s remote url [%s] is different than %s' % (UPSTREAM_NAME, remote_url, DIFF_REPO))
return detected_errors

target_branch = '%s/%s' % (UPSTREAM_NAME, DIFF_BRANCH)
except subprocess.CalledProcessError:
# No remote so fall back to origin/master
print('WARNING: No remote %s detected, falling back to origin master. Make sure it is up to date.' % UPSTREAM_NAME)
target_branch = 'origin/master'

cmd = ('git diff --unified=0 %s' % target_branch).split()
diff = subprocess.check_output(cmd).decode('utf-8')
except subprocess.CalledProcessError as ex:
detected_errors.append('%s' % ex)
return detected_errors
# print("output", diff)

diffed_lines = detect_lines(diff)
# print("Diff lines %s" % diffed_lines)

detected_errors = []

for path, lines in diffed_lines.items():
directory = os.path.join(os.path.dirname(__file__), '..')
Expand Down

0 comments on commit 556bff8

Please sign in to comment.