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