ref(upstream): FULL TREE — Deep-Spark xllm (1470) + ds_vllm csrc/models (703)
Replaces cherry-picked upstream_ref with complete source trees. xllm/ — Iluvatar official C++ inference engine (15MB, 1470 files) Complete: kernels → layers → models → runtime → scheduler → api Excluded: .git, binary images, third_party submodule checkouts ds_vllm/ — Iluvatar official vllm fork (8MB, 703 files) Included: csrc/ (ALL CUDA kernels), fused_moe/, qwen3_5 model, _custom_ops Excluded: tests, benchmarks, docs, examples (not needed for reference) Critical call chains now fully traceable: MoE: moe_topk_softmax_kernels.cuh → ixformer.h → fused_moe.cpp → layer GDN: qwen3_gated_delta_net_base.cpp → qwen3_5_gated_delta_net.cpp Attention: ixformer.h → xllm_paged_attention → attention.cpp
This commit is contained in:
122
upstream_ref/xllm/.github/workflows/build_x86_64_cuda.yaml
vendored
Normal file
122
upstream_ref/xllm/.github/workflows/build_x86_64_cuda.yaml
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
name: xLLM Build x86_64 CUDA
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'cibuild/**'
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
types: [opened, synchronize, reopened]
|
||||
paths-ignore:
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
paths:
|
||||
- '.github/**.yaml'
|
||||
- 'cibuild/**.sh'
|
||||
- 'setup.py'
|
||||
- 'examples/generate.py'
|
||||
|
||||
env:
|
||||
JOBNAME: xllm-x86_64-cuda-cibuild-${{ github.run_id }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
|
||||
|
||||
jobs:
|
||||
# need to review code first when sensitive files are modified.
|
||||
check-sensitive:
|
||||
runs-on: [self-hosted]
|
||||
outputs:
|
||||
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
|
||||
do_build: ${{ steps.decide.outputs.do_build }}
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Ensure we can compare commits
|
||||
|
||||
- name: Install jq
|
||||
run: yum install -y jq
|
||||
|
||||
- name: Check if sensitive files were changed
|
||||
id: check_sensitive
|
||||
run: |
|
||||
sensitive_files=(
|
||||
".github/**.yaml"
|
||||
"cibuild/**.sh"
|
||||
"setup.py"
|
||||
)
|
||||
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
|
||||
requires_approval="false"
|
||||
while IFS= read -r changed_file; do
|
||||
[[ -z "$changed_file" ]] && continue
|
||||
for pattern in "${sensitive_files[@]}"; do
|
||||
if [[ "$changed_file" == $pattern ]]; then
|
||||
requires_approval="true"
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
|
||||
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Decide whether to check build
|
||||
id: decide
|
||||
run: |
|
||||
event="${{ github.event_name }}"
|
||||
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
elif [[ "$event" == "pull_request" ]]; then
|
||||
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" == "true" ]; then
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
elif [[ "$event" == "pull_request_review" ]]; then
|
||||
# Since pull_request_review now only triggers when sensitive files are modified,
|
||||
# we only need to check if the review is approved
|
||||
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
build:
|
||||
needs: check-sensitive
|
||||
if: >
|
||||
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
|
||||
needs.check-sensitive.outputs.do_build == 'true'
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
timeout-minutes: 5
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Build
|
||||
if: ${{ success() }}
|
||||
timeout-minutes: 60
|
||||
run: |
|
||||
chmod +x ./cibuild/build_cuda.sh
|
||||
bash cibuild/build_cuda.sh 'pip install pre-commit -i https://pypi.tuna.tsinghua.edu.cn/simple; python setup.py build --device cuda'
|
||||
122
upstream_ref/xllm/.github/workflows/build_x86_64_ilu.yaml
vendored
Normal file
122
upstream_ref/xllm/.github/workflows/build_x86_64_ilu.yaml
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
name: xLLM Build x86_64 ILU
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'cibuild/**'
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
types: [opened, synchronize, reopened]
|
||||
paths-ignore:
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
paths:
|
||||
- '.github/**.yaml'
|
||||
- 'cibuild/**.sh'
|
||||
- 'setup.py'
|
||||
- 'examples/generate.py'
|
||||
|
||||
env:
|
||||
JOBNAME: xllm-x86_64-ilu-cibuild-${{ github.run_id }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
|
||||
|
||||
jobs:
|
||||
# need to review code first when sensitive files are modified.
|
||||
check-sensitive:
|
||||
runs-on: [self-hosted]
|
||||
outputs:
|
||||
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
|
||||
do_build: ${{ steps.decide.outputs.do_build }}
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Ensure we can compare commits
|
||||
|
||||
- name: Install jq
|
||||
run: yum install -y jq
|
||||
|
||||
- name: Check if sensitive files were changed
|
||||
id: check_sensitive
|
||||
run: |
|
||||
sensitive_files=(
|
||||
".github/**.yaml"
|
||||
"cibuild/**.sh"
|
||||
"setup.py"
|
||||
)
|
||||
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
|
||||
requires_approval="false"
|
||||
while IFS= read -r changed_file; do
|
||||
[[ -z "$changed_file" ]] && continue
|
||||
for pattern in "${sensitive_files[@]}"; do
|
||||
if [[ "$changed_file" == $pattern ]]; then
|
||||
requires_approval="true"
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
|
||||
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Decide whether to check build
|
||||
id: decide
|
||||
run: |
|
||||
event="${{ github.event_name }}"
|
||||
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
elif [[ "$event" == "pull_request" ]]; then
|
||||
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" == "true" ]; then
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
elif [[ "$event" == "pull_request_review" ]]; then
|
||||
# Since pull_request_review now only triggers when sensitive files are modified,
|
||||
# we only need to check if the review is approved
|
||||
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
build:
|
||||
needs: check-sensitive
|
||||
if: >
|
||||
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
|
||||
needs.check-sensitive.outputs.do_build == 'true'
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
timeout-minutes: 5
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Build
|
||||
if: ${{ success() }}
|
||||
timeout-minutes: 60
|
||||
run: |
|
||||
chmod +x ./cibuild/build_ilu.sh
|
||||
bash cibuild/build_ilu.sh 'pip3 install pre-commit -i https://pypi.tuna.tsinghua.edu.cn/simple && python setup.py build --device ilu'
|
||||
122
upstream_ref/xllm/.github/workflows/build_x86_64_mlu.yaml
vendored
Normal file
122
upstream_ref/xllm/.github/workflows/build_x86_64_mlu.yaml
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
name: xLLM Build x86_64 MLU
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'cibuild/**'
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
types: [opened, synchronize, reopened]
|
||||
paths-ignore:
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
paths:
|
||||
- '.github/**.yaml'
|
||||
- 'cibuild/**.sh'
|
||||
- 'setup.py'
|
||||
- 'examples/generate.py'
|
||||
|
||||
env:
|
||||
JOBNAME: xllm-x86_64-mlu-cibuild-${{ github.run_id }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
|
||||
|
||||
jobs:
|
||||
# need to review code first when sensitive files are modified.
|
||||
check-sensitive:
|
||||
runs-on: [self-hosted]
|
||||
outputs:
|
||||
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
|
||||
do_build: ${{ steps.decide.outputs.do_build }}
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Ensure we can compare commits
|
||||
|
||||
- name: Install jq
|
||||
run: yum install -y jq
|
||||
|
||||
- name: Check if sensitive files were changed
|
||||
id: check_sensitive
|
||||
run: |
|
||||
sensitive_files=(
|
||||
".github/**.yaml"
|
||||
"cibuild/**.sh"
|
||||
"setup.py"
|
||||
)
|
||||
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
|
||||
requires_approval="false"
|
||||
while IFS= read -r changed_file; do
|
||||
[[ -z "$changed_file" ]] && continue
|
||||
for pattern in "${sensitive_files[@]}"; do
|
||||
if [[ "$changed_file" == $pattern ]]; then
|
||||
requires_approval="true"
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
|
||||
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Decide whether to check build
|
||||
id: decide
|
||||
run: |
|
||||
event="${{ github.event_name }}"
|
||||
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
elif [[ "$event" == "pull_request" ]]; then
|
||||
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" == "true" ]; then
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
elif [[ "$event" == "pull_request_review" ]]; then
|
||||
# Since pull_request_review now only triggers when sensitive files are modified,
|
||||
# we only need to check if the review is approved
|
||||
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
build:
|
||||
needs: check-sensitive
|
||||
if: >
|
||||
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
|
||||
needs.check-sensitive.outputs.do_build == 'true'
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
timeout-minutes: 5
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Build
|
||||
if: ${{ success() }}
|
||||
timeout-minutes: 60
|
||||
run: |
|
||||
chmod +x ./cibuild/build_mlu.sh
|
||||
bash cibuild/build_mlu.sh 'pip install pre-commit -i https://pypi.tuna.tsinghua.edu.cn/simple; python setup.py build --device mlu'
|
||||
136
upstream_ref/xllm/.github/workflows/build_x86_64_npu.yaml
vendored
Normal file
136
upstream_ref/xllm/.github/workflows/build_x86_64_npu.yaml
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
name: xLLM Build x86_64 NPU
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'cibuild/**'
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
types: [opened, synchronize, reopened]
|
||||
paths-ignore:
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
- '*.md'
|
||||
- '*.txt'
|
||||
- '*.yml'
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
paths:
|
||||
- '.github/**.yaml'
|
||||
- 'cibuild/**.sh'
|
||||
- 'setup.py'
|
||||
- 'examples/generate.py'
|
||||
|
||||
env:
|
||||
JOBNAME: xllm-x86_64-npu-cibuild-${{ github.run_id }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
|
||||
|
||||
jobs:
|
||||
# need to review code first when sensitive files are modified.
|
||||
check-sensitive:
|
||||
runs-on: [self-hosted]
|
||||
outputs:
|
||||
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
|
||||
do_build: ${{ steps.decide.outputs.do_build }}
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Ensure we can compare commits
|
||||
|
||||
- name: Install jq
|
||||
run: yum install -y jq
|
||||
|
||||
- name: Check if sensitive files were changed
|
||||
id: check_sensitive
|
||||
run: |
|
||||
sensitive_files=(
|
||||
".github/**.yaml"
|
||||
"cibuild/**.sh"
|
||||
"setup.py"
|
||||
"examples/generate.py"
|
||||
)
|
||||
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
|
||||
requires_approval="false"
|
||||
while IFS= read -r changed_file; do
|
||||
[[ -z "$changed_file" ]] && continue
|
||||
for pattern in "${sensitive_files[@]}"; do
|
||||
if [[ "$changed_file" == $pattern ]]; then
|
||||
requires_approval="true"
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
|
||||
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Decide whether to check build
|
||||
id: decide
|
||||
run: |
|
||||
event="${{ github.event_name }}"
|
||||
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
elif [[ "$event" == "pull_request" ]]; then
|
||||
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" == "true" ]; then
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
elif [[ "$event" == "pull_request_review" ]]; then
|
||||
# Since pull_request_review now only triggers when sensitive files are modified,
|
||||
# we only need to check if the review is approved
|
||||
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
|
||||
echo "do_build=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
else
|
||||
echo "do_build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
build:
|
||||
needs: check-sensitive
|
||||
if: >
|
||||
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
|
||||
needs.check-sensitive.outputs.do_build == 'true'
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Prepare submodule checkout
|
||||
run: |
|
||||
git config --global url."https://gitcode.com/xLLM-AI/tvm".insteadOf "https://github.com/TileLang/tvm"
|
||||
git config --global url."https://gitcode.com/xLLM-AI/composable_kernel".insteadOf "https://github.com/ROCm/composable_kernel"
|
||||
git config --global url."https://gitcode.com/xLLM-AI/cutlass".insteadOf "https://github.com/NVIDIA/cutlass"
|
||||
if [ -d .git/modules ]; then
|
||||
find .git/modules -type f -name '*.lock' -print -delete || true
|
||||
fi
|
||||
|
||||
rm -rf .git/modules/third_party/tilelang-ascend
|
||||
rm -rf third_party/tilelang-ascend
|
||||
|
||||
- name: Checkout Code
|
||||
timeout-minutes: 5
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
clean: true
|
||||
submodules: recursive
|
||||
|
||||
- name: Build
|
||||
if: ${{ success() }}
|
||||
timeout-minutes: 60
|
||||
run: |
|
||||
chmod +x ./cibuild/build_npu.sh
|
||||
bash cibuild/build_npu.sh 'pip install pre-commit -i https://pypi.tuna.tsinghua.edu.cn/simple; python setup.py bdist_wheel; pip install dist/* --force-reinstall; python examples/generate.py --model="/export/home/models/Qwen2-7B-Instruct" --devices="npu:7"'
|
||||
104
upstream_ref/xllm/.github/workflows/check_format.yml
vendored
Normal file
104
upstream_ref/xllm/.github/workflows/check_format.yml
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
name: CheckFormat
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'cibuild/**'
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'cibuild/**'
|
||||
- 'cmake/**'
|
||||
- 'docs/**'
|
||||
- 'third_party/**'
|
||||
- 'tools/**'
|
||||
|
||||
jobs:
|
||||
format-check:
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
pip install clang-format==20.1.6
|
||||
clang-format --version
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Determine base commit for comparison
|
||||
id: get_base_commit
|
||||
run: |
|
||||
# pull_request action
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
echo "base_commit=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
# push action
|
||||
echo "base_commit=${{ github.sha }}~1" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Verify clang-format configuration
|
||||
run: |
|
||||
if [ ! -f ".clang-format" ]; then
|
||||
echo "❌ .clang-format file not found in repository root"
|
||||
exit 1
|
||||
fi
|
||||
clang-format --style=file --dump-config > /dev/null || {
|
||||
echo "❌ .clang-format file has invalid format"
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Check code format
|
||||
shell: /usr/bin/bash {0}
|
||||
run: |
|
||||
BASE_COMMIT="${{ steps.get_base_commit.outputs.base_commit }}"
|
||||
CLANG_FORMAT_FILE="$(pwd)/.clang-format"
|
||||
|
||||
# ignore path
|
||||
IGNORED_PATHS=(
|
||||
"^.github/.*"
|
||||
"^cibuild/.*"
|
||||
"^cmake/.*"
|
||||
"^docs/.*"
|
||||
"^third_party/.*"
|
||||
"^tools/.*"
|
||||
)
|
||||
|
||||
# igonore files
|
||||
FILES=$(git diff --name-only "$BASE_COMMIT" -- '*.c' '*.h' '*.cc' '*.cp' '*.cpp' '*.c++' '*.cxx' '*.hh' '*.hpp' '*.hxx' '*.inc' '*.cu' '*.cuh' | \
|
||||
grep -v -E "$(IFS=\|; echo "${IGNORED_PATHS[*]}")")
|
||||
|
||||
if [ -z "$FILES" ]; then
|
||||
echo "✅ No files to check (all excluded)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# run clang-format
|
||||
diff=$(git-clang-format \
|
||||
--style=file:"$CLANG_FORMAT_FILE" \
|
||||
--extensions="c,h,cc,cp,cpp,c++,cxx,hh,hpp,hxx,inc,cu,cuh" \
|
||||
--commit "$BASE_COMMIT" \
|
||||
--diff \
|
||||
-- $FILES)
|
||||
|
||||
# check diff
|
||||
if [ "$diff" = "no modified files to format" ] || [ "$diff" = "clang-format did not modify any files" ]; then
|
||||
echo "✅ Code format is correct"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "\n❌ You have introduced coding style breakages.\n"
|
||||
|
||||
printf "\n\033[1mSuggested changes:\n\n"
|
||||
echo "$diff"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user