|
| 1 | +name: Compliance |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + compliance_job: |
| 8 | + runs-on: ubuntu-24.04 |
| 9 | + name: Run compliance checks on patch series (PR) |
| 10 | + |
| 11 | + # Skip job if it was triggered by Renovate Bot |
| 12 | + if: ${{ !contains(github.actor, 'renovate') }} |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Installation |
| 16 | + run: | |
| 17 | + apt-get update && apt-get install --no-install-recommends -y libmagic1 git |
| 18 | + pip install west gitlint |
| 19 | +
|
| 20 | + - name: Checkout the code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + path: serial_modem |
| 24 | + ref: ${{ github.event.pull_request.head.sha }} |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Initialize |
| 28 | + working-directory: serial_modem |
| 29 | + run: | |
| 30 | + if [ ! -d "../.west" ]; then |
| 31 | + west init -l . |
| 32 | + else |
| 33 | + echo ".west folder already exists, skipping west init." |
| 34 | + fi |
| 35 | + west update -o=--depth=1 -n |
| 36 | +
|
| 37 | + - name: Install zephyr requirements |
| 38 | + run: | |
| 39 | + pip install -r zephyr/scripts/requirements-actions.txt |
| 40 | + # Junitparser v3 and 4 don't work with check_compliance.py |
| 41 | + pip install --upgrade junitparser==2.8.0 |
| 42 | +
|
| 43 | + - name: Run Compliance Tests |
| 44 | + id: compliance |
| 45 | + shell: bash |
| 46 | + env: |
| 47 | + BASE_REF: ${{ github.base_ref }} |
| 48 | + working-directory: serial_modem |
| 49 | + run: | |
| 50 | + export ZEPHYR_BASE="../zephyr" |
| 51 | + $ZEPHYR_BASE/scripts/ci/check_compliance.py \ |
| 52 | + --annotate |
| 53 | + -m Codeowners \ |
| 54 | + -m Devicetree \ |
| 55 | + -m Gitlint \ |
| 56 | + -m Identity \ |
| 57 | + -m Nits \ |
| 58 | + -m pylint \ |
| 59 | + -m checkpatch \ |
| 60 | + -c origin/${BASE_REF}.. || \ |
| 61 | + echo "COMPLIANCE_FAILED=true" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + - name: Process Compliance Results |
| 64 | + working-directory: serial_modem |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + # Check for compliance.xml existence |
| 68 | + if [[ ! -s "compliance.xml" ]]; then |
| 69 | + echo "::error::compliance.xml file is missing or empty" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +
|
| 73 | + # Initialize exit code |
| 74 | + exit_code=0 |
| 75 | +
|
| 76 | + # Define error files to check |
| 77 | + error_files=( |
| 78 | + "Nits.txt" |
| 79 | + "checkpatch.txt" |
| 80 | + "Identity.txt" |
| 81 | + "Gitlint.txt" |
| 82 | + "pylint.txt" |
| 83 | + "Devicetree.txt" |
| 84 | + "Kconfig.txt" |
| 85 | + "KconfigBasic.txt" |
| 86 | + "Codeowners.txt" |
| 87 | + ) |
| 88 | +
|
| 89 | + # Process each error file |
| 90 | + for file in "${error_files[@]}"; do |
| 91 | + if [[ -s $file ]]; then |
| 92 | + errors=$(cat $file) |
| 93 | + errors="${errors//'%'/'%25'}" |
| 94 | + errors="${errors//$'\n'/'%0A'}" |
| 95 | + errors="${errors//$'\r'/'%0D'}" |
| 96 | + echo "::error file=${file}::$errors" |
| 97 | + exit_code=1 |
| 98 | + fi |
| 99 | + done |
| 100 | +
|
| 101 | + # Check if compliance test failed |
| 102 | + if [[ "$COMPLIANCE_FAILED" == "true" ]]; then |
| 103 | + echo "::error::Compliance tests failed. Please check the logs for details." |
| 104 | + exit_code=1 |
| 105 | + fi |
| 106 | +
|
| 107 | + exit $exit_code |
0 commit comments