-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathaction.yml
More file actions
77 lines (71 loc) · 3.15 KB
/
action.yml
File metadata and controls
77 lines (71 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: "Code Style Check"
description: "Reusable action to check C/C++ code style with clang-format"
inputs:
target_dir:
description: "Directory to check for C/C++ files"
required: false
default: "."
name:
description: 'Name for the output artifact'
required: false
default: 'code-style-check-report'
fail-on-findings:
description: "Whether to fail the action if issues are found"
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y clang-format curl ca-certificates build-essential
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g diff2html-cli
shell: bash
- name: Run code style check
id: code-style-check
env:
target_dir: ${{ inputs.target_dir }}
run: |
chmod +x .github/actions/common/code-style/entrypoint.sh
./.github/actions/common/code-style/entrypoint.sh "${target_dir}" || echo "STYLE_ISSUES=true" >> $GITHUB_OUTPUT
shell: bash
- name: Analyze code style results
if: always()
run: |
if [ "${{ steps.code-style-check.outputs.STYLE_ISSUES }}" == "true" ]; then
# Count number of files with style issues
if [ -f "_output/diff.html" ]; then
# Try to count files from diff output
file_count=$(diff -u --recursive "${{ inputs.target_dir }}" "_styled/${{ inputs.target_dir }}" 2>/dev/null | grep -c "^diff -u" || echo "1+")
echo "### Code Style Check Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- ❌ **Status**: Style issues found" >> $GITHUB_STEP_SUMMARY
echo "- 📁 **Files affected**: ${file_count}" >> $GITHUB_STEP_SUMMARY
echo "- 📄 **Detailed report**: Available in artifacts (diff.html)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **Please review the code-style report artifact and apply clang-format to fix the issues.**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "💡 **Tip**: Run \`clang-format -i\` on the affected files to automatically fix formatting." >> $GITHUB_STEP_SUMMARY
fi
else
echo "### Code Style Check Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ **All code follows the style guidelines!**" >> $GITHUB_STEP_SUMMARY
fi
shell: bash
- name: Upload clang-format report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ inputs.name }}
path: _output/diff.html
if-no-files-found: ignore
- name: Fail if code style issues found
if: inputs.fail-on-findings == 'true' && steps.code-style-check.outputs.STYLE_ISSUES == 'true'
shell: bash
run: |
echo "❌ Code style issues found. Failing the job."
exit 1