
After https://github.com/llvm/llvm-project/pull/133023, `START_REV` and `END_REV` env variables became redundant.
91 lines
2.9 KiB
YAML
91 lines
2.9 KiB
YAML
name: "Check code formatting"
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- 'users/**'
|
|
|
|
jobs:
|
|
code_formatter:
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 30
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: true
|
|
if: github.repository == 'llvm/llvm-project'
|
|
steps:
|
|
- name: Fetch LLVM sources
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
with:
|
|
fetch-depth: 2
|
|
|
|
- name: Get changed files
|
|
id: changed-files
|
|
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
|
|
with:
|
|
separator: ","
|
|
skip_initial_fetch: true
|
|
base_sha: 'HEAD~1'
|
|
sha: 'HEAD'
|
|
|
|
# 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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
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: "Listed files"
|
|
env:
|
|
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
|
run: |
|
|
echo "Formatting files:"
|
|
echo "$CHANGED_FILES"
|
|
|
|
- name: Install clang-format
|
|
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
|
|
with:
|
|
clangformat: 20.1.8
|
|
|
|
- name: Setup Python env
|
|
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
|
|
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 }}
|
|
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
|
# 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 HEAD~1 \
|
|
--end-rev HEAD \
|
|
--changed-files "$CHANGED_FILES"
|
|
|
|
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
|
|
if: always()
|
|
with:
|
|
name: workflow-args
|
|
path: |
|
|
comments
|