Skip to content

Commit f8db9e4

Browse files
committed
CI: compute pkg_diffs over all .repos files
1 parent 2c41ffe commit f8db9e4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.github/workflows/packages.build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
git fetch --no-tags --depth=1 origin ${{ github.base_ref }}
3030
git checkout ${{ github.base_ref }}
3131
git checkout HEAD@{1}
32-
- name: determine new packages
33-
run: python3 src/scripts/pkg_diffs.py "${{ github.base_ref }}"
32+
- name: Determine added packages
33+
run: python3 src/scripts/pkg_diffs.py "${{ github.base_ref }}" | tee /tmp/diff.repos
3434
- name: Build new packages
3535
uses: ./
3636
env:

src/scripts/pkg_diffs.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# /usr/bin/env python3
22

3+
import sys
34
import os
45
import git
56
import yaml
67
import argparse
8+
import glob
79

810

911
def load_from_commit(repo_path, sha, files):
@@ -12,7 +14,12 @@ def load_from_commit(repo_path, sha, files):
1214
content = dict()
1315
for file in files:
1416
file_content = commit.tree / file
15-
content.update(yaml.safe_load(file_content.data_stream.read()))
17+
new = yaml.safe_load(file_content.data_stream.read())
18+
# add new content to top-level keys
19+
for key, val in new.items():
20+
if key not in content:
21+
content[key] = dict()
22+
content[key].update(val)
1623
return content
1724

1825

@@ -27,9 +34,11 @@ def is_same(left, right):
2734
parser = argparse.ArgumentParser(description="Determine changed packages")
2835
parser.add_argument("sha", help="commit SHA to compare with")
2936
parser.add_argument(
30-
"files", nargs="*", default=["ros-one.repos"], help=".repos files to consider"
37+
"files", nargs="*", default=["*.repos"], help=".repos files to consider"
3138
)
3239
args = parser.parse_args()
40+
# resolve glob patterns in args.files
41+
args.files = [f for pattern in args.files for f in glob.glob(pattern)]
3342

3443
old = load_from_commit(os.getcwd(), args.sha, args.files)
3544
new = load_from_commit(os.getcwd(), "HEAD", args.files)
@@ -39,5 +48,4 @@ def is_same(left, right):
3948
if key in new["repositories"] and is_same(new["repositories"][key], val):
4049
del new["repositories"][key]
4150

42-
with open("/tmp/diff.repos", "w") as f:
43-
yaml.dump(new, f)
51+
yaml.dump(new, sys.stdout)

0 commit comments

Comments
 (0)