|
| 1 | +name: Check Training Parameters |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + - 'XPointMLTest.py' # Only trigger when this specific file changes |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-training-params: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout PR code |
| 14 | + uses: actions/checkout@v3 |
| 15 | + with: |
| 16 | + ref: ${{ github.event.pull_request.head.sha }} |
| 17 | + path: pr-code |
| 18 | + fetch-depth: 1 |
| 19 | + |
| 20 | + - name: Checkout main branch |
| 21 | + uses: actions/checkout@v3 |
| 22 | + with: |
| 23 | + ref: main |
| 24 | + path: main-code |
| 25 | + |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: '3.10' |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: | |
| 33 | + python -m pip install --upgrade pip |
| 34 | + pip install pytest |
| 35 | +
|
| 36 | + - name: Run parameter check |
| 37 | + run: | |
| 38 | + python - <<EOF |
| 39 | +import re |
| 40 | +import sys |
| 41 | + |
| 42 | +# Training parameter patterns to check |
| 43 | +params_to_check = { |
| 44 | + 'epochs': r'--epochs\', type=int, default=(\d+),', |
| 45 | + 'trainFrameFirst': r'--trainFrameFirst\', type=int, default=(\d+),', |
| 46 | + 'trainFrameLast': r'--trainFrameLast\', type=int, default=(\d+),', |
| 47 | + 'validationFrameFirst': r'--validationFrameFirst\', type=int, default=(\d+),', |
| 48 | + 'validationFrameLast': r'--validationFrameLast\', type=int, default=(\d+),', |
| 49 | +} |
| 50 | + |
| 51 | +# Files to check |
| 52 | +files_to_check = ['main-code/XPointMLTest.py', 'pr-code/XPointMLTest.py'] |
| 53 | + |
| 54 | +main_params = {} |
| 55 | +pr_params = {} |
| 56 | + |
| 57 | +# Extract parameters from main branch |
| 58 | +with open('main-code/XPointMLTest.py', 'r') as f: |
| 59 | + content = f.read() |
| 60 | + for param, pattern in params_to_check.items(): |
| 61 | + match = re.search(pattern, content) |
| 62 | + if match: |
| 63 | + main_params[param] = int(match.group(1)) |
| 64 | + else: |
| 65 | + print(f"Warning: Could not find parameter '{param}' in main branch code") |
| 66 | + |
| 67 | +# Extract parameters from PR |
| 68 | +with open('pr-code/XPointMLTest.py', 'r') as f: |
| 69 | + content = f.read() |
| 70 | + for param, pattern in params_to_check.items(): |
| 71 | + match = re.search(pattern, content) |
| 72 | + if match: |
| 73 | + pr_params[param] = int(match.group(1)) |
| 74 | + else: |
| 75 | + print(f"Warning: Could not find parameter '{param}' in PR code") |
| 76 | + |
| 77 | +# Compare parameters |
| 78 | +mismatch = False |
| 79 | +for param in params_to_check.keys(): |
| 80 | + if param in main_params and param in pr_params: |
| 81 | + if main_params[param] != pr_params[param]: |
| 82 | + print(f"❌ Parameter '{param}' has changed: {main_params[param]} -> {pr_params[param]}") |
| 83 | + mismatch = True |
| 84 | + else: |
| 85 | + print(f"✅ Parameter '{param}' unchanged: {main_params[param]}") |
| 86 | + else: |
| 87 | + print(f"⚠️ Could not compare '{param}' - missing from one or both branches") |
| 88 | + |
| 89 | +# Summary |
| 90 | +print("\n=== Parameter Check Summary ===") |
| 91 | +if mismatch: |
| 92 | + print("❌ Training parameters have been modified!") |
| 93 | + print("Detected changes to training configuration parameters.") |
| 94 | + print("Please verify these changes are intentional and approved.") |
| 95 | + sys.exit(1) |
| 96 | +else: |
| 97 | + print("✅ All training parameters match the main branch!") |
| 98 | + sys.exit(0) |
| 99 | +EOF |
0 commit comments