mirror of
https://github.com/XRPLF/clio.git
synced 2026-09-30 00:48:09 +00:00
229 lines
7.4 KiB
YAML
229 lines
7.4 KiB
YAML
name: Run clang-tidy on files
|
|
|
|
on:
|
|
push:
|
|
branches: [develop]
|
|
workflow_dispatch:
|
|
pull_request:
|
|
branches: [develop]
|
|
paths:
|
|
- .github/workflows/clang-tidy.yml
|
|
|
|
- CMakeLists.txt
|
|
- conanfile.py
|
|
- conan.lock
|
|
- "cmake/**"
|
|
- "src/**"
|
|
- "tests/**"
|
|
- "benchmarks/**"
|
|
|
|
- .clang-tidy
|
|
|
|
concurrency:
|
|
# Only cancel in-progress jobs or runs for the current workflow - matches against branch & tags
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
BUILD_DIR: build
|
|
BUILD_TYPE: Debug # Debug so that ASSERTS and such participate in clang-tidy check
|
|
|
|
OUTPUT_FILE: /tmp/clang-tidy-output.txt
|
|
FILTERED_OUTPUT_FILE: /tmp/clang-tidy-filtered-output.txt
|
|
DIFF_FILE: /tmp/clang-tidy-git-diff.txt
|
|
ISSUE_FILE: /tmp/clang-tidy-issue.md
|
|
|
|
COMPILER: clang
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
|
|
jobs:
|
|
determine-files:
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
permissions:
|
|
contents: read
|
|
uses: XRPLF/actions/.github/workflows/determine-tidy-files.yml@70145243b905dc3e040a61d39c00e178cfb96f71
|
|
|
|
run-clang-tidy:
|
|
name: Run clang tidy
|
|
needs: [determine-files]
|
|
if: ${{ needs.determine-files.outputs.cpp_changed_files != '' || needs.determine-files.outputs.need_full_run == 'true' }}
|
|
runs-on: heavy
|
|
container:
|
|
image: ghcr.io/xrplf/xrpld/nix-ubuntu:sha-cb2642b
|
|
|
|
permissions:
|
|
contents: write
|
|
issues: write
|
|
pull-requests: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Prepare runner
|
|
uses: XRPLF/actions/prepare-runner@7bf7ceca5932114abdd0d43493c3c30c5a654e13
|
|
with:
|
|
enable_ccache: false
|
|
|
|
- name: Print build environment
|
|
uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574
|
|
|
|
- name: Set compiler environment
|
|
uses: ./.github/actions/set-compiler-env
|
|
with:
|
|
compiler: ${{ env.COMPILER }}
|
|
|
|
- name: Setup conan
|
|
run: conan/init.sh
|
|
|
|
- name: Run conan
|
|
uses: ./.github/actions/conan
|
|
with:
|
|
build_dir: ${{ env.BUILD_DIR }}
|
|
build_type: ${{ env.BUILD_TYPE }}
|
|
|
|
- name: Run CMake
|
|
uses: ./.github/actions/cmake
|
|
with:
|
|
build_dir: ${{ env.BUILD_DIR }}
|
|
build_type: ${{ env.BUILD_TYPE }}
|
|
|
|
- name: Get number of processors
|
|
uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf
|
|
id: nproc
|
|
|
|
- name: Run clang tidy
|
|
continue-on-error: true
|
|
id: run_clang_tidy
|
|
env:
|
|
TARGETS: ${{ needs.determine-files.outputs.need_full_run != 'true' && needs.determine-files.outputs.cpp_changed_files || 'benchmarks src tests' }}
|
|
run: |
|
|
set -o pipefail
|
|
run-clang-tidy -j ${{ steps.nproc.outputs.nproc }} -p "${BUILD_DIR}" -quiet -fix -allow-no-checks ${TARGETS} 2>&1 | tee "${OUTPUT_FILE}"
|
|
|
|
- name: Print errors
|
|
if: ${{ steps.run_clang_tidy.outcome != 'success' }}
|
|
run: |
|
|
sed '/error\||/!d' "${OUTPUT_FILE}"
|
|
|
|
- name: Upload clang-tidy output
|
|
if: ${{ github.event.repository.visibility == 'public' && steps.run_clang_tidy.outcome != 'success' }}
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
path: ${{ env.OUTPUT_FILE }}
|
|
archive: false
|
|
retention-days: 30
|
|
|
|
- name: Check for changes
|
|
id: files_changed
|
|
continue-on-error: true
|
|
run: |
|
|
git diff --exit-code
|
|
|
|
- name: Fix style
|
|
if: ${{ steps.files_changed.outcome != 'success' }}
|
|
run: |
|
|
pre-commit run --all-files || true
|
|
|
|
- name: Generate git diff
|
|
if: ${{ steps.files_changed.outcome != 'success' }}
|
|
run: |
|
|
git diff | tee "${DIFF_FILE}"
|
|
|
|
- name: Upload clang-tidy diff output
|
|
if: ${{ github.event.repository.visibility == 'public' && steps.files_changed.outcome != 'success' }}
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
path: ${{ env.DIFF_FILE }}
|
|
archive: false
|
|
retention-days: 30
|
|
|
|
- name: Write issue header
|
|
if: ${{ steps.run_clang_tidy.outcome != 'success' }}
|
|
run: |
|
|
cat >"${ISSUE_FILE}" <<EOF
|
|
## Clang-tidy Check Failed
|
|
|
|
### Clang-tidy Output:
|
|
\`\`\`
|
|
EOF
|
|
|
|
- name: Append clang-tidy output to issue body (filter for errors and warnings)
|
|
if: ${{ steps.run_clang_tidy.outcome != 'success' }}
|
|
run: |
|
|
if [ -f "${OUTPUT_FILE}" ]; then
|
|
# Extract lines containing 'error:', 'warning:', or 'note:'
|
|
grep -E '(error:|warning:|note:)' "${OUTPUT_FILE}" >"${FILTERED_OUTPUT_FILE}" || true
|
|
|
|
# If filtered output is empty, use original (might be a different error format)
|
|
if [ ! -s "${FILTERED_OUTPUT_FILE}" ]; then
|
|
cp "${OUTPUT_FILE}" "${FILTERED_OUTPUT_FILE}"
|
|
fi
|
|
|
|
# Truncate if too large
|
|
head -c 60000 "${FILTERED_OUTPUT_FILE}" >>"${ISSUE_FILE}"
|
|
if [ "$(wc -c <"${FILTERED_OUTPUT_FILE}")" -gt 60000 ]; then
|
|
echo "" >>"${ISSUE_FILE}"
|
|
echo "... (output truncated, see artifacts for full output)" >>"${ISSUE_FILE}"
|
|
fi
|
|
|
|
rm "${FILTERED_OUTPUT_FILE}"
|
|
else
|
|
echo "No output file found" >>"${ISSUE_FILE}"
|
|
fi
|
|
|
|
- name: Append issue footer
|
|
if: ${{ steps.run_clang_tidy.outcome != 'success' }}
|
|
run: |
|
|
cat >>"${ISSUE_FILE}" <<EOF
|
|
\`\`\`
|
|
|
|
---
|
|
*This issue was automatically created by the clang-tidy workflow.*
|
|
EOF
|
|
|
|
- name: Create issue
|
|
id: create_issue
|
|
if: ${{ steps.run_clang_tidy.outcome != 'success' && github.event_name != 'pull_request' }}
|
|
uses: XRPLF/actions/create-issue@2b8bc36af85b88bca0dd7bfac2e2dc05f94ad712
|
|
with:
|
|
title: "Clang-tidy check failed"
|
|
body_file: ${{ env.ISSUE_FILE }}
|
|
labels: "bug"
|
|
assignees: "godexsoft,mathbunnyru"
|
|
|
|
- uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd # v7.0.0
|
|
if: ${{ steps.files_changed.outcome != 'success' && github.event_name != 'pull_request' }}
|
|
with:
|
|
gpg_private_key: ${{ secrets.ACTIONS_GPG_PRIVATE_KEY }}
|
|
passphrase: ${{ secrets.ACTIONS_GPG_PASSPHRASE }}
|
|
git_user_signingkey: true
|
|
git_commit_gpgsign: true
|
|
|
|
- name: Create PR with fixes
|
|
if: ${{ steps.files_changed.outcome != 'success' && github.event_name != 'pull_request' }}
|
|
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
|
env:
|
|
GH_REPO: ${{ github.repository }}
|
|
GH_TOKEN: ${{ github.token }}
|
|
with:
|
|
commit-message: "[CI] clang-tidy auto fixes"
|
|
committer: Clio CI <skuznetsov@ripple.com>
|
|
branch: "clang_tidy/autofix"
|
|
branch-suffix: timestamp
|
|
delete-branch: true
|
|
title: "style: Apply clang-tidy auto fixes"
|
|
body: >
|
|
Fixes #${{ steps.create_issue.outputs.issue_number }}.
|
|
|
|
Please review and commit clang-tidy fixes.
|
|
reviewers: "godexsoft,kuznetsss,mathbunnyru"
|
|
|
|
- name: Fail the job
|
|
if: ${{ steps.run_clang_tidy.outcome != 'success' }}
|
|
run: |
|
|
echo "Clang-tidy check failed!"
|
|
exit 1
|