Skip to content

Commit

Permalink
Use a more stable method to detect rosdep changes (#30694)
Browse files Browse the repository at this point in the history
* Use a more stable method to detect rosdep changes

The method for detecting rosdep changes in the repository checking
system doesn't seem to work very well under all circumstances, and
sometimes fails to determine the differences resulting in a failed job.

This change switches the test to use a line change detection mechanism
already in use in another test, so it should be more stable.

Reverts bdf1c62

* fixup! Use a more stable method to detect rosdep changes
  • Loading branch information
cottsay committed Sep 8, 2021
1 parent 9be739d commit f1df73b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build_test.yaml
Expand Up @@ -10,17 +10,14 @@ jobs:
python-version: [3.8]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Fetch upstream (to enable diff)
run: |
git remote add unittest_upstream_comparision https://github.com/ros/rosdistro.git || git remote set-url unittest_upstream_comparision https://github.com/ros/rosdistro.git
git fetch --no-tags --depth=5 unittest_upstream_comparision master
git fetch --no-tags --depth=5 origin $GITHUB_BASE_REF
git fetch --no-tags --depth=1 unittest_upstream_comparision master
- name: Install Dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
27 changes: 23 additions & 4 deletions test/rosdep_repo_check/test_rosdep_repo_check.py
Expand Up @@ -57,10 +57,25 @@ def detect_lines(diffstr):


def get_changed_line_numbers():
base_ref = ''
GITHUB_BASE_REF = os.environ.get('GITHUB_BASE_REF')
if GITHUB_BASE_REF:
base_ref = 'remotes/origin/' + GITHUB_BASE_REF + '...'
UPSTREAM_NAME = 'unittest_upstream_comparision'
DIFF_BRANCH = 'master'
DIFF_REPO = 'https://github.com/ros/rosdistro.git'

# 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
cmd = 'git config --get remote.%s.url' % UPSTREAM_NAME
try:
remote_url = subprocess.check_output(cmd.split()).decode('utf-8').strip()
# Remote exists
# Check url
assert remote_url == DIFF_REPO, \
'%s remote url [%s] is different than %s' % (UPSTREAM_NAME, remote_url, DIFF_REPO)
base_ref = '%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, file=sys.stderr)
base_ref = 'origin/master'

cmd = 'git diff --unified=0 %s -- rosdep' % (base_ref,)
print("Detecting changed rules with '%s'" % (cmd,))
diff = subprocess.check_output(cmd.split()).decode('utf-8')
Expand All @@ -77,6 +92,10 @@ def setUpClass(cls):
cls._isolated_data = {}
cls._repo_root = os.path.join(os.path.dirname(__file__), '..', '..')

# For clarity in the logs, show as 'skipped' rather than 'passed'
if not cls._changed_lines:
raise unittest.SkipTest('No rosdep changes were detected')

for path in ('rosdep/base.yaml', 'rosdep/python.yaml'):
if path not in cls._changed_lines:
continue
Expand Down

0 comments on commit f1df73b

Please sign in to comment.