Update pylint.yml to llvm ones
diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml
index f81d60c..e6d72b4 100644
--- a/.github/workflows/pylint.yml
+++ b/.github/workflows/pylint.yml
@@ -1,15 +1,28 @@
-name: Black (python)
+name: "Check code formatting"
-on: [push, pull_request]
+permissions:
+ contents: read
+
+on:
+ pull_request:
+ branches:
+ - main
jobs:
- lint:
+ code_formatter:
runs-on: ubuntu-latest
steps:
- - name: Checkout branch
- uses: actions/checkout@v3
+ - name: Fetch sources
+ uses: actions/checkout@v4
with:
- fetch-depth: 0
+ ref: ${{ github.event.pull_request.head.sha }}
+
+ - name: Checkout through merge base
+ uses: rmacklin/fetch-through-merge-base@v0
+ with:
+ base_ref: ${{ github.event.pull_request.base.ref }}
+ head_ref: ${{ github.event.pull_request.head.sha }}
+ deepen_length: 500
- name: Get changed files
id: changed-files
@@ -18,12 +31,63 @@
separator: ","
skip_initial_fetch: true
- - name: Setup Python env
- uses: actions/setup-python@v3
+ # We need to pull the script from the main branch, so that we ensure
+ # we get the latest version of this script.
+ - name: Fetch code formatting utils
+ uses: actions/checkout@v4
+ with:
+ repository: ${{ github.repository }}
+ ref: ${{ github.base_ref }}
+ sparse-checkout: |
+ llvm/utils/git/requirements_formatting.txt
+ llvm/utils/git/code-format-helper.py
+ sparse-checkout-cone-mode: false
+ path: code-format-tools
- - name: Install black and reorder-python-imports
- run: pip install black reorder-python-imports
-
- - name: Black and Sort changed files
+ - name: "Listed files"
+ env:
+ CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
- black --check reorder-python-imports ${{ steps.changed-files.outputs.all_changed_files }}
+ echo "Formatting files:"
+ echo "$CHANGED_FILES"
+ - name: Install clang-format
+ uses: aminya/setup-cpp@v1
+ with:
+ clangformat: 18.1.1
+
+ - name: Setup Python env
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.11'
+ cache: 'pip'
+ cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
+
+ - name: Install python dependencies
+ run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
+
+ - name: Run code formatter
+ env:
+ GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
+ START_REV: ${{ github.event.pull_request.base.sha }}
+ END_REV: ${{ github.event.pull_request.head.sha }}
+ CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
+ # TODO(boomanaiden154): Once clang v18 is released, we should be able
+ # to take advantage of the new --diff_from_common_commit option
+ # explicitly in code-format-helper.py and not have to diff starting at
+ # the merge base.
+ # Create an empty comments file so the pr-write job doesn't fail.
+ run: |
+ echo "[]" > comments &&
+ python ./code-format-tools/llvm/utils/git/code-format-helper.py \
+ --write-comment-to-file \
+ --token ${{ secrets.GITHUB_TOKEN }} \
+ --issue-number $GITHUB_PR_NUMBER \
+ --start-rev $(git merge-base $START_REV $END_REV) \
+ --end-rev $END_REV \
+ --changed-files "$CHANGED_FILES"
+ - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
+ if: always()
+ with:
+ name: workflow-args
+ path: |
+ comments