Skip to content

Commit fe267de

Browse files
Fetch CI for full history and handle sparse checkout for codecov
Signed-off-by: Leander Stephen D'Souza <[email protected]>
1 parent b4d38c3 commit fe267de

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
steps:
3131
- name: Checkout repository
3232
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
33+
with:
34+
fetch-depth: 0
3335

3436
- name: Set up Python ${{ matrix.python-version }}
3537
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0

test/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import yaml
1616

17+
REPO_LINK = 'https://github.com/ros-infrastructure/vcs2l.git'
18+
1719

1820
def to_file_url(path):
1921
return urljoin('file:', pathname2url(path))
@@ -30,7 +32,29 @@ def setup_git_repository(temp_dir):
3032
repo_root = os.path.dirname(os.path.dirname(__file__))
3133
gitrepo_path = os.path.join(temp_dir.name, 'gitrepo')
3234

33-
subprocess.check_call(['git', 'clone', '--branch', 'main', repo_root, gitrepo_path])
35+
commits_count = int(
36+
subprocess.check_output(
37+
['git', 'rev-list', '--count', 'HEAD'], cwd=repo_root
38+
).strip()
39+
)
40+
41+
if commits_count == 1:
42+
repo_root = REPO_LINK # codecov sparsely clones the repo
43+
44+
subprocess.check_call(['git', 'clone', repo_root, gitrepo_path])
45+
try:
46+
subprocess.check_call(['git', 'checkout', 'main'], cwd=gitrepo_path)
47+
except subprocess.CalledProcessError:
48+
branch_names = subprocess.check_output(
49+
['git', 'branch', '-a'], cwd=gitrepo_path
50+
).decode('utf-8')
51+
52+
print('Available branches:\n', branch_names)
53+
54+
# Create branch named 'main' if CI cannot checkout main directly
55+
subprocess.check_call(
56+
['git', 'checkout', '-b', 'main'], cwd=gitrepo_path
57+
)
3458

3559
return gitrepo_path
3660

0 commit comments

Comments
 (0)