|
| 1 | +name: Verify Constants |
| 2 | + |
| 3 | +# Define the file paths under `paths` to trigger this check only when specific files are modified. |
| 4 | +# This script will then execute checks only on files that have changed, rather than all files listed in `paths`. |
| 5 | + |
| 6 | +# **Note** : To add a new file for checks, include its path in: |
| 7 | +# - `on` -> `push` and `pull_request` sections |
| 8 | +# - `jobs` -> `verify-constants` -> `steps` -> Verify constants -> Add a new if else for your file, with check logic inside it. |
| 9 | + |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + paths: |
| 14 | + - "chebai/preprocessing/reader.py" |
| 15 | + pull_request: |
| 16 | + paths: |
| 17 | + - "chebai/preprocessing/reader.py" |
| 18 | + |
| 19 | +jobs: |
| 20 | + verify-constants: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + python-version: [ |
| 26 | +# Only use 3.10 as of now |
| 27 | +# "3.9", |
| 28 | + "3.10", |
| 29 | +# "3.11" |
| 30 | + ] |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout code |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Set PYTHONPATH |
| 37 | + run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV |
| 38 | + |
| 39 | + - name: Get list of changed files |
| 40 | + id: changed_files |
| 41 | + run: | |
| 42 | + git fetch origin dev |
| 43 | +
|
| 44 | + # Get the list of changed files compared to origin/dev and save them to a file |
| 45 | + git diff --name-only origin/dev > changed_files.txt |
| 46 | +
|
| 47 | + # Print the names of changed files on separate lines |
| 48 | + echo "Changed files:" |
| 49 | + while read -r line; do |
| 50 | + echo "Changed File name : $line" |
| 51 | + done < changed_files.txt |
| 52 | +
|
| 53 | + - name: Set up Python ${{ matrix.python-version }} |
| 54 | + uses: actions/setup-python@v5 |
| 55 | + with: |
| 56 | + python-version: ${{ matrix.python-version }} |
| 57 | + |
| 58 | + - name: Install dependencies |
| 59 | + # Setting a fix version for torch due to an error with latest version (2.5.1) |
| 60 | + # ImportError: cannot import name 'T_co' from 'torch.utils.data.dataset' |
| 61 | + run: | |
| 62 | + python -m pip install --upgrade pip |
| 63 | + python -m pip install --upgrade pip setuptools wheel |
| 64 | + python -m pip install torch==2.4.1 --index-url https://download.pytorch.org/whl/cpu |
| 65 | + python -m pip install -e . |
| 66 | +
|
| 67 | + - name: Export constants |
| 68 | + run: python .github/workflows/export_constants.py |
| 69 | + |
| 70 | + - name: Load constants into environment variables |
| 71 | + id: load_constants |
| 72 | + # "E_" is appended as suffix to every constant, to protect overwriting other sys env variables with same name |
| 73 | + run: | |
| 74 | + constants=$(cat constants.json) |
| 75 | + echo "$constants" | jq -r 'to_entries|map("E_\(.key)=\(.value|tostring)")|.[]' >> $GITHUB_ENV |
| 76 | +
|
| 77 | + - name: Print all environment variables |
| 78 | + run: printenv |
| 79 | + |
| 80 | + - name: Verify constants |
| 81 | + run: | |
| 82 | + file_name="chebai/preprocessing/reader.py" |
| 83 | + if grep -q "$file_name" changed_files.txt; then |
| 84 | + echo "----------------------- Checking file : $file_name ----------------------- " |
| 85 | +
|
| 86 | + # Define expected values for constants |
| 87 | + exp_embedding_offset="10" |
| 88 | + exp_cls_token="2" |
| 89 | + exp_padding_token_index="0" |
| 90 | + exp_mask_token_index="1" |
| 91 | +
|
| 92 | + # Debugging output to check environment variables |
| 93 | + echo "Current Environment Variables:" |
| 94 | + echo "E_EMBEDDING_OFFSET = $E_EMBEDDING_OFFSET" |
| 95 | + echo "Expected: $exp_embedding_offset" |
| 96 | +
|
| 97 | + # Verify constants match expected values |
| 98 | + if [ "$E_EMBEDDING_OFFSET" != "$exp_embedding_offset" ]; then |
| 99 | + echo "EMBEDDING_OFFSET ($E_EMBEDDING_OFFSET) does not match expected value ($exp_embedding_offset)!" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | + if [ "$E_CLS_TOKEN" != "$exp_cls_token" ]; then |
| 103 | + echo "CLS_TOKEN ($E_CLS_TOKEN) does not match expected value ($exp_cls_token)!" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | + if [ "$E_PADDING_TOKEN_INDEX" != "$exp_padding_token_index" ]; then |
| 107 | + echo "PADDING_TOKEN_INDEX ($E_PADDING_TOKEN_INDEX) does not match expected value ($exp_padding_token_index)!" |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + if [ "$E_MASK_TOKEN_INDEX" != "$exp_mask_token_index" ]; then |
| 111 | + echo "MASK_TOKEN_INDEX ($E_MASK_TOKEN_INDEX) does not match expected value ($exp_mask_token_index)!" |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + else |
| 115 | + echo "$file_name not found in changed_files.txt; skipping check." |
| 116 | + fi |
0 commit comments