1name: Build with Clang/LLVM 2 3on: pull_request_target 4 5concurrency: 6 group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }} 7 cancel-in-progress: true 8 9jobs: 10 clang-build: 11 if: github.repository_owner == 'zephyrproject-rtos' 12 runs-on: 13 group: zephyr-runner-v2-linux-x64-4xlarge 14 container: 15 image: ghcr.io/zephyrproject-rtos/ci-repo-cache:v0.27.4.20241026 16 options: '--entrypoint /bin/bash' 17 strategy: 18 fail-fast: false 19 matrix: 20 platform: ["native_sim"] 21 env: 22 CCACHE_DIR: /node-cache/ccache-zephyr 23 CCACHE_REMOTE_STORAGE: "redis://cache-*.keydb-cache.svc.cluster.local|shards=1,2,3" 24 CCACHE_REMOTE_ONLY: "true" 25 LLVM_TOOLCHAIN_PATH: /usr/lib/llvm-16 26 COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} 27 BASE_REF: ${{ github.base_ref }} 28 outputs: 29 report_needed: ${{ steps.twister.outputs.report_needed }} 30 steps: 31 - name: Apply container owner mismatch workaround 32 run: | 33 # FIXME: The owner UID of the GITHUB_WORKSPACE directory may not 34 # match the container user UID because of the way GitHub 35 # Actions runner is implemented. Remove this workaround when 36 # GitHub comes up with a fundamental fix for this problem. 37 git config --global --add safe.directory ${GITHUB_WORKSPACE} 38 39 - name: Print cloud service information 40 run: | 41 echo "ZEPHYR_RUNNER_CLOUD_PROVIDER = ${ZEPHYR_RUNNER_CLOUD_PROVIDER}" 42 echo "ZEPHYR_RUNNER_CLOUD_NODE = ${ZEPHYR_RUNNER_CLOUD_NODE}" 43 echo "ZEPHYR_RUNNER_CLOUD_POD = ${ZEPHYR_RUNNER_CLOUD_POD}" 44 45 - name: Clone cached Zephyr repository 46 continue-on-error: true 47 run: | 48 git clone --shared /repo-cache/zephyrproject/zephyr . 49 git remote set-url origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} 50 51 - name: Checkout 52 uses: actions/checkout@v4 53 with: 54 ref: ${{ github.event.pull_request.head.sha }} 55 fetch-depth: 0 56 persist-credentials: false 57 58 - name: Environment Setup 59 run: | 60 echo "$HOME/.local/bin" >> $GITHUB_PATH 61 git config --global user.email "bot@zephyrproject.org" 62 git config --global user.name "Zephyr Bot" 63 rm -fr ".git/rebase-apply" 64 rm -fr ".git/rebase-merge" 65 git rebase origin/${BASE_REF} 66 git clean -f -d 67 git log --pretty=oneline | head -n 10 68 west init -l . || true 69 west config --global update.narrow true 70 west config manifest.group-filter -- +ci,+optional 71 # In some cases modules are left in a state where they can't be 72 # updated (i.e. when we cancel a job and the builder is killed), 73 # So first retry to update, if that does not work, remove all modules 74 # and start over. (Workaround until we implement more robust module 75 # west caching). 76 west update --path-cache /repo-cache/zephyrproject 2>&1 1> west.log || west update --path-cache /repo-cache/zephyrproject 2>&1 1> west2.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /repo-cache/zephyrproject) 77 78 echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-$( cat SDK_VERSION )" >> $GITHUB_ENV 79 80 - name: Check Environment 81 run: | 82 cmake --version 83 ${LLVM_TOOLCHAIN_PATH}/bin/clang --version 84 gcc --version 85 ls -la 86 87 - name: Set up ccache 88 run: | 89 mkdir -p ${CCACHE_DIR} 90 ccache -M 10G 91 ccache -p 92 ccache -z -s -vv 93 94 - name: Update BabbleSim to manifest revision 95 run: | 96 export BSIM_VERSION=$( west list bsim -f {revision} ) 97 echo "Manifest points to bsim sha $BSIM_VERSION" 98 cd /opt/bsim_west/bsim 99 git fetch -n origin ${BSIM_VERSION} 100 git -c advice.detachedHead=false checkout ${BSIM_VERSION} 101 west update 102 make everything -s -j 8 103 104 - name: Run Tests with Twister 105 id: twister 106 run: | 107 export ZEPHYR_BASE=${PWD} 108 export ZEPHYR_TOOLCHAIN_VARIANT=llvm 109 110 # check if we need to run a full twister or not based on files changed 111 python3 ./scripts/ci/test_plan.py --no-detailed-test-id --platform ${{ matrix.platform }} -c origin/${BASE_REF}.. 112 113 # We can limit scope to just what has changed 114 if [ -s testplan.json ]; then 115 echo "report_needed=1" >> $GITHUB_OUTPUT 116 # Full twister but with options based on changes 117 ./scripts/twister --no-detailed-test-id --force-color --inline-logs -M -N -v --load-tests testplan.json --retry-failed 2 118 else 119 # if nothing is run, skip reporting step 120 echo "report_needed=0" >> $GITHUB_OUTPUT 121 fi 122 123 - name: Print ccache stats 124 if: always() 125 run: | 126 ccache -s -vv 127 128 - name: Upload Unit Test Results 129 if: always() && steps.twister.outputs.report_needed != 0 130 uses: actions/upload-artifact@v4 131 with: 132 name: Unit Test Results (Subset ${{ matrix.platform }}) 133 path: twister-out/twister.xml 134 135 clang-build-results: 136 name: "Publish Unit Tests Results" 137 needs: clang-build 138 runs-on: ubuntu-22.04 139 if: (success() || failure() ) && needs.clang-build.outputs.report_needed != 0 140 steps: 141 - name: Download Artifacts 142 uses: actions/download-artifact@v4 143 with: 144 path: artifacts 145 - name: Merge Test Results 146 run: | 147 pip install junitparser junit2html 148 junitparser merge artifacts/*/twister.xml junit.xml 149 junit2html junit.xml junit-clang.html 150 151 - name: Upload Unit Test Results in HTML 152 if: always() 153 uses: actions/upload-artifact@v4 154 with: 155 name: HTML Unit Test Results 156 if-no-files-found: ignore 157 path: | 158 junit-clang.html 159 160 - name: Publish Unit Test Results 161 uses: EnricoMi/publish-unit-test-result-action@v2 162 if: always() 163 with: 164 check_name: Unit Test Results 165 files: "**/twister.xml" 166 comment_mode: off 167