Skip to content

Commit

Permalink
test: Unify .gitignore across all workspaces and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j3soon committed Aug 21, 2024
1 parent 26ef505 commit 1f46104
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 28 deletions.
7 changes: 3 additions & 4 deletions cartographer_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log
docker/cache/*
!docker/cache/.gazebo
docker/cache/.gazebo/*
!docker/cache/.gazebo/.gitkeep
7 changes: 1 addition & 6 deletions husky_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log

# Gazebo cache
docker/cache/*
!docker/cache/.gazebo
docker/cache/.gazebo/*
!docker/cache/.gazebo/.gitkeep
7 changes: 1 addition & 6 deletions kobuki_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log

# Gazebo cache
docker/cache/*
!docker/cache/.gazebo
docker/cache/.gazebo/*
!docker/cache/.gazebo/.gitkeep
9 changes: 9 additions & 0 deletions orbslam3_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log

# ROS2 bag files
V1_02_medium.bag
V1_02_medium/
7 changes: 3 additions & 4 deletions rtabmap_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log
docker/cache/*
!docker/cache/.gazebo
docker/cache/.gazebo/*
!docker/cache/.gazebo/.gitkeep
3 changes: 2 additions & 1 deletion template_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log
/log
8 changes: 8 additions & 0 deletions tests/diff_base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log
MULTILINE_PLACEHOLDER
12 changes: 9 additions & 3 deletions tests/lint_devcontainer.py → tests/lint_comp_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def compare_file_with_template(filepath, ignored_workspaces=[]):
logging.info(f"Checking if '{filepath}' matches the template...")
template_path = f"{repo_dir}/tests/diff_base/{filepath}"
template = Path(template_path).read_text().splitlines(keepends=True)
template = Path(template_path).read_text().splitlines(keepends=True) # keepends to preserve trailing newlines
for filename in glob.glob(f"{repo_dir}/*_ws/{filepath}"):
# Skip certain cases intentionally
if any(ws in filename for ws in ignored_workspaces):
Expand All @@ -27,13 +27,19 @@ def error(msg, i):
raise ValueError(f"'{filepath}' does not match the template: '{filename}'")
i = 0
while i < len(diff):
if "- MULTILINE_PLACEHOLDER" in diff[i]: # don't use exact match to avoid cases without trailing newline
i += 1
while i < len(diff) and diff[i].startswith('+ '):
i += 1
continue
if i+1 >= len(diff):
error("Odd lines", i)
if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '):
error("Expected no line deletion and addition", i)
regexp = "^" + re.escape(diff[i][1:]).replace('PLACEHOLDER', '.*') + "$"
if not re.match(regexp, diff[i+1][1:]):
regexp = "^" + re.escape(diff[i][2:]).replace('PLACEHOLDER', '.*') + "$"
if not re.match(regexp, diff[i+1][2:]):
error("Expected line deletion and addition to differ only in the placeholder", i)
i += 2

compare_file_with_template(".devcontainer/devcontainer.json", ["ros1_bridge_ws"])
compare_file_with_template(".gitignore")
17 changes: 17 additions & 0 deletions tests/lint_gitignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import glob
import logging
import os
from pathlib import Path

logging.basicConfig(level=logging.INFO)
current_dir = os.path.dirname(os.path.realpath(__file__))
repo_dir = os.path.realpath(f"{current_dir}/..")

logging.info("Checking `.gitignore` files...")
for filename in glob.glob(f"{repo_dir}/*_ws/.gitignore"):
logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...")
content = Path(filename).read_text()
if "gazebo" in content:
raise ValueError(f"`gazebo` should not exist since it's obsolete: '{filename}'")
if "docker/cache" in content:
raise ValueError(f"`docker/cache` should not exist since it's obsolete: '{filename}'")
7 changes: 3 additions & 4 deletions vlp_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Visual Studio Code
.vscode

# ROS2 basic directories
/build
/install
/log
docker/cache/*
!docker/cache/.gazebo
docker/cache/.gazebo/*
!docker/cache/.gazebo/.gitkeep

0 comments on commit 1f46104

Please sign in to comment.