|
11 | 11 | # but sadly `env` can't be used either in `runs-on`. |
12 | 12 |
|
13 | 13 | 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 | +
|
14 | 59 | protolint: |
15 | 60 | name: Check proto files with protolint |
16 | 61 | runs-on: ubuntu-24.04 |
|
0 commit comments