|
| 1 | +name: "Code lint" |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + - 'users/**' |
| 11 | + paths: |
| 12 | + - 'clang-tools-extra/clang-tidy/**' |
| 13 | + |
| 14 | +jobs: |
| 15 | + code_linter: |
| 16 | + if: github.repository_owner == 'llvm' |
| 17 | + runs-on: ubuntu-24.04 |
| 18 | + defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + container: |
| 22 | + image: 'ghcr.io/llvm/ci-ubuntu-24.04:latest' |
| 23 | + timeout-minutes: 60 |
| 24 | + concurrency: |
| 25 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 26 | + cancel-in-progress: true |
| 27 | + steps: |
| 28 | + - name: Fetch LLVM sources |
| 29 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 30 | + with: |
| 31 | + fetch-depth: 2 |
| 32 | + |
| 33 | + - name: Get changed files |
| 34 | + id: changed-files |
| 35 | + uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1 |
| 36 | + with: |
| 37 | + separator: "," |
| 38 | + skip_initial_fetch: true |
| 39 | + base_sha: 'HEAD~1' |
| 40 | + sha: 'HEAD' |
| 41 | + |
| 42 | + - name: Listed files |
| 43 | + env: |
| 44 | + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 45 | + run: | |
| 46 | + echo "Changed files:" |
| 47 | + echo "$CHANGED_FILES" |
| 48 | + |
| 49 | + - name: Fetch code linting utils |
| 50 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 51 | + with: |
| 52 | + repository: ${{ github.repository }} |
| 53 | + ref: ${{ github.base_ref }} |
| 54 | + sparse-checkout: | |
| 55 | + llvm/utils/git/code-lint-helper.py |
| 56 | + llvm/utils/git/requirements_linting.txt |
| 57 | + clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py |
| 58 | + sparse-checkout-cone-mode: false |
| 59 | + path: code-lint-tools |
| 60 | + |
| 61 | + - name: Install clang-tidy |
| 62 | + uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1 |
| 63 | + with: |
| 64 | + clang-tidy: 20.1.8 |
| 65 | + |
| 66 | + - name: Setup Python env |
| 67 | + uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0 |
| 68 | + with: |
| 69 | + python-version: '3.12' |
| 70 | + |
| 71 | + - name: Install Python dependencies |
| 72 | + run: python3 -m pip install -r code-lint-tools/llvm/utils/git/requirements_linting.txt |
| 73 | + |
| 74 | + # TODO: create special mapping for 'codegen' targets, for now build predefined set |
| 75 | + # TODO: add entrypoint in 'compute_projects.py' that only adds a project and its direct dependencies |
| 76 | + - name: Configure and CodeGen |
| 77 | + run: | |
| 78 | + git config --global --add safe.directory '*' |
| 79 | +
|
| 80 | + . <(git diff --name-only HEAD~1...HEAD | python3 .ci/compute_projects.py) |
| 81 | +
|
| 82 | + if [[ "${projects_to_build}" == "" ]]; then |
| 83 | + echo "No projects to analyze" |
| 84 | + exit 0 |
| 85 | + fi |
| 86 | +
|
| 87 | + cmake -G Ninja \ |
| 88 | + -B build \ |
| 89 | + -S llvm \ |
| 90 | + -DLLVM_ENABLE_ASSERTIONS=OFF \ |
| 91 | + -DLLVM_ENABLE_PROJECTS="${projects_to_build}" \ |
| 92 | + -DCMAKE_CXX_COMPILER=clang++ \ |
| 93 | + -DCMAKE_C_COMPILER=clang \ |
| 94 | + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ |
| 95 | + -DLLVM_INCLUDE_TESTS=OFF \ |
| 96 | + -DCLANG_INCLUDE_TESTS=OFF \ |
| 97 | + -DCMAKE_BUILD_TYPE=Release |
| 98 | + |
| 99 | + ninja -C build \ |
| 100 | + clang-tablegen-targets \ |
| 101 | + genconfusable # for "ConfusableIdentifierCheck.h" |
| 102 | +
|
| 103 | + - name: Run code linter |
| 104 | + env: |
| 105 | + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} |
| 106 | + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 107 | + run: | |
| 108 | + echo "[]" > comments && |
| 109 | + python3 ./code-lint-tools/llvm/utils/git/code-lint-helper.py \ |
| 110 | + --token ${{ secrets.GITHUB_TOKEN }} \ |
| 111 | + --issue-number $GITHUB_PR_NUMBER \ |
| 112 | + --start-rev HEAD~1 \ |
| 113 | + --end-rev HEAD \ |
| 114 | + --verbose \ |
| 115 | + --changed-files "$CHANGED_FILES" |
| 116 | + |
| 117 | + - name: Upload results |
| 118 | + uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0 |
| 119 | + if: always() |
| 120 | + with: |
| 121 | + name: workflow-args |
| 122 | + path: | |
| 123 | + comments |
0 commit comments