Skip to content

Commit 04119f8

Browse files
committed
CI: Check py folders for init files
1 parent 47ebd6e commit 04119f8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

.github/workflows/ci-pr.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,51 @@ env:
1111
# but sadly `env` can't be used either in `runs-on`.
1212

1313
jobs:
14+
validate-structure:
15+
name: Validate Python Package Structure
16+
runs-on: ubuntu-latest # Using latest as specific version isn't critical here
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Check for __init__.py files
21+
run: |
22+
echo "Checking if Python package structure mirrors Protobuf structure..."
23+
PROTO_BASE="proto/frequenz/api/common"
24+
PYTHON_BASE="py/frequenz/api/common"
25+
MISSING_INIT=false # Initialize flag
26+
27+
# Use process substitution to avoid subshell issues with the while loop
28+
while IFS= read -r proto_dir; do
29+
# Construct the corresponding python path
30+
relative_path="${proto_dir#$PROTO_BASE/}"
31+
# Handle the base directory case
32+
if [ "$proto_dir" == "$PROTO_BASE" ]; then
33+
relative_path=""
34+
fi
35+
36+
python_dir="$PYTHON_BASE/$relative_path"
37+
38+
# Check if the corresponding python directory exists
39+
if [ -d "$python_dir" ]; then
40+
# Check if __init__.py exists in the python directory
41+
if [ ! -f "$python_dir/__init__.py" ]; then
42+
echo "Error: Missing __init__.py in $python_dir (corresponding to $proto_dir)"
43+
MISSING_INIT=true # Set the flag
44+
fi
45+
# Optional check for missing python directories
46+
# else
47+
# echo "Warning: Python directory $python_dir not found for proto directory $proto_dir"
48+
fi
49+
done < <(find "$PROTO_BASE" -type d) # Feed find output via process substitution
50+
51+
# Check the flag after the loop finishes
52+
if [ "$MISSING_INIT" = true ]; then
53+
echo "Validation failed: Found missing __init__.py files."
54+
exit 1
55+
else
56+
echo "Validation successful: All corresponding Python directories have __init__.py."
57+
fi
58+
1459
protolint:
1560
name: Check proto files with protolint
1661
runs-on: ubuntu-24.04

0 commit comments

Comments
 (0)