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