File: cmake_format.yml

package info (click to toggle)
amdsmi 7.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,500 kB
  • sloc: cpp: 42,954; python: 23,437; ansic: 14,296; sh: 762; makefile: 20
file content (99 lines) | stat: -rw-r--r-- 2,804 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# caution: most of this file was written using Claude 3.7 Sonnet
name: CMake Format Check

on:
  push:
    branches: [ amd-staging ]
    paths:
      - '**/*.cmake'
      - '**/CMakeLists.txt'
      - '**/*.cmake.in'
  pull_request:
    branches: [ amd-staging ]
    paths:
      - '**/*.cmake'
      - '**/CMakeLists.txt'
      - '**/*.cmake.in'
  workflow_dispatch:  # Allows manual triggering

defaults:
  run:
    shell: bash

jobs:
  check-cmake-format:
    name: Check CMake files formatting
    runs-on: self-hosted
    container: catthehacker/ubuntu:act-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        fetch-depth: 0  # Full history for better diff context

    - name: Setup Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.10'
        cache: 'pip'

    - name: Install cmake-format
      run: |
        python -m pip install --upgrade pip
        pip install cmake-format==0.6.13

    - name: Check CMake formatting
      id: check-format
      run: |
        echo "::group::Finding CMake files"
        FILES=$(find . -type f \( -name "CMakeLists.txt" -o -name "*.cmake" -o -name "*.cmake.in" \) \
                -not -path "*/esmi_ib_library/*" \
                -not -path "*/\.*" \
                -not -path "*/build/*")
        echo "Found $(echo "$FILES" | wc -l) CMake files to check"
        echo "::endgroup::"

        # Create an array to store failed files
        declare -a failed_files

        # Check if files are formatted correctly
        for file in $FILES; do
          echo "Checking $file..."
          if ! cmake-format --check "$file"; then
            failed_files+=("$file")
            echo "::error file=$file::File needs formatting"
          fi
        done

        # Generate report and exit with error if any files failed
        if [ ${#failed_files[@]} -ne 0 ]; then
          echo "Failed files: ${failed_files[*]}"
          echo "FAILED_FILES=${failed_files[*]}" >> $GITHUB_ENV
          exit 1
        else
          echo "All CMake files are formatted correctly!"
        fi

    - name: Generate diff for failed files
      if: failure() && env.FAILED_FILES != ''
      run: |
        echo "## CMake Format Check Failed" >> $GITHUB_STEP_SUMMARY
        echo "The following files need formatting:" >> $GITHUB_STEP_SUMMARY
        echo "" >> $GITHUB_STEP_SUMMARY

        for file in ${FAILED_FILES}; do
          echo "### $file" >> $GITHUB_STEP_SUMMARY
        done

        cat << 'EOF' >> $GITHUB_STEP_SUMMARY
        ### How to fix
        Run this command locally to fix formatting issues:
        ```bash
        # Install cmake-format
        pip install cmake-format==0.6.13

        # Format files
        cmake-format -i <file>
        ```
        EOF