|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +# This action checks that required kernel configs have not been removed or |
| 5 | +# modified to an undesirable value. |
| 6 | +name: Kernel Required Configs Check |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: [3.0*, fasttrack/*] |
| 11 | + paths: |
| 12 | + - 'SPECS/kernel*/config*' |
| 13 | + pull_request: |
| 14 | + branches: [3.0*, fasttrack/*] |
| 15 | + paths: |
| 16 | + - 'SPECS/kernel*/config*' |
| 17 | + |
| 18 | +jobs: |
| 19 | + check: |
| 20 | + name: Kernel configs check |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + # Checkout the branch of our repo that triggered this action |
| 25 | + - name: Workflow trigger checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Get base commit for PRs |
| 29 | + if: ${{ github.event_name == 'pull_request' }} |
| 30 | + run: | |
| 31 | + git fetch origin ${{ github.base_ref }} |
| 32 | + echo "base_sha=$(git rev-parse origin/${{ github.base_ref }})" >> $GITHUB_ENV |
| 33 | + echo "Merging ${{ github.sha }} into ${{ github.base_ref }}" |
| 34 | +
|
| 35 | + - name: Get base commit for Pushes |
| 36 | + if: ${{ github.event_name == 'push' }} |
| 37 | + run: | |
| 38 | + git fetch origin ${{ github.event.before }} |
| 39 | + echo "base_sha=${{ github.event.before }}" >> $GITHUB_ENV |
| 40 | + echo "Merging ${{ github.sha }} into ${{ github.event.before }}" |
| 41 | +
|
| 42 | + # For consistency, we use the same major/minor version of Python that Azure Linux ships |
| 43 | + - name: Setup Python 3.12 |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: 3.12 |
| 47 | + |
| 48 | + - name: Get Python dependencies |
| 49 | + run: python3 -m pip install -r toolkit/scripts/requirements.txt |
| 50 | + |
| 51 | + # Check if kernel configs changed |
| 52 | + - name: Check if config files changed |
| 53 | + run: | |
| 54 | + echo "Files changed: '$(git diff-tree --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }})'" |
| 55 | + changed_configs=$(git diff-tree --diff-filter=d --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }} | { grep "SPECS/kernel.*/config.*$" || test $? = 1; }) |
| 56 | + echo "Files to validate: '${changed_configs}'" |
| 57 | + echo "updated_configs<<EOF" >> $GITHUB_ENV |
| 58 | + echo "${changed_configs}" >> $GITHUB_ENV |
| 59 | + echo "EOF" >> $GITHUB_ENV |
| 60 | +
|
| 61 | + # Run kernel config checker against each changed config file |
| 62 | + - name: Run kernel config checking script |
| 63 | + if: ${{ env.updated_configs != '' }} |
| 64 | + run: | |
| 65 | + JSON_PATH="toolkit/scripts/kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json" |
| 66 | +
|
| 67 | + # Extract kernel names that have overrides in the JSON (these are the kernels we track) |
| 68 | + tracked_kernels=$(python3 -c " |
| 69 | + import json |
| 70 | + with open('${JSON_PATH}') as f: |
| 71 | + data = json.load(f) |
| 72 | + for o in data['overrides']: |
| 73 | + print(o['name']) |
| 74 | + ") |
| 75 | + echo "Tracked kernels: ${tracked_kernels}" |
| 76 | +
|
| 77 | + failed=0 |
| 78 | + holder="${{ env.updated_configs }}" |
| 79 | + for file in $holder; do |
| 80 | + # Extract kernel name from path (e.g., SPECS/kernel-hwe/config -> kernel-hwe) |
| 81 | + kernel_name=$(echo "$file" | sed 's|SPECS/\([^/]*\)/.*|\1|') |
| 82 | +
|
| 83 | + # Skip kernels that don't have overrides in the JSON |
| 84 | + if ! echo "${tracked_kernels}" | grep -qx "${kernel_name}"; then |
| 85 | + echo "============================================" |
| 86 | + echo "Skipping: ${file} (kernel=${kernel_name} not tracked in JSON)" |
| 87 | + echo "============================================" |
| 88 | + continue |
| 89 | + fi |
| 90 | +
|
| 91 | + # Determine architecture from filename |
| 92 | + if [[ "$file" == *"aarch64"* ]]; then |
| 93 | + arch="arm64" |
| 94 | + else |
| 95 | + arch="x86_64" |
| 96 | + fi |
| 97 | +
|
| 98 | + echo "============================================" |
| 99 | + echo "Checking: ${file} (kernel=${kernel_name}, arch=${arch})" |
| 100 | + echo "============================================" |
| 101 | +
|
| 102 | + if ! (cd toolkit/scripts && python3 -m kernel_config_checker.check_config \ |
| 103 | + "../../${file}" \ |
| 104 | + kernel_config_checker/kernel_configs_json/azl3-os-required-kernel-configs.json \ |
| 105 | + "${kernel_name}" "${arch}"); then |
| 106 | + failed=1 |
| 107 | + fi |
| 108 | + done |
| 109 | +
|
| 110 | + if [ "$failed" -eq 1 ]; then |
| 111 | + echo "" |
| 112 | + echo "✗ One or more kernel config checks failed" |
| 113 | + exit 1 |
| 114 | + fi |
0 commit comments