Extend coi documentation #84
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 00-Check-Code-Convention | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to test' | |
| type: string | |
| default: 'main' | |
| jobs: | |
| job1: | |
| name: Check coding convention | |
| runs-on: ubuntu-22.04 #uncrustify 0.64 can not be compiled on ubuntu-24.04 | |
| steps: | |
| - name: Trigger | |
| run: echo "Triggered by ${{github.event_name}} event" | |
| - name: Check Branch Input | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| if [ -z "${{ github.event.inputs.branch }}" ]; then | |
| echo "Branch input is required for manual trigger." | |
| exit 1 | |
| fi | |
| fi | |
| - name: Checkout | |
| uses: actions/[email protected] | |
| with: | |
| ref: "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref }}" | |
| submodules: true | |
| fetch-depth: 0 | |
| - name: Log Current Branch and Commit | |
| run: | | |
| echo "Current branch: $(git rev-parse --abbrev-ref HEAD)" | |
| echo "Current commit: $(git rev-parse HEAD)" | |
| - name: Install commit check tools | |
| run: | | |
| echo "Installing pre-commit ..." | |
| python3 -m pip install pre-commit | |
| echo "Installing uncrustify 0.64 from source code ..." | |
| sudo apt-get install --no-install-recommends -y\ | |
| binutils ca-certificates git cmake make \ | |
| gcc g++ binutils libc6-dev | |
| echo "Cloning Uncrustify repository..." | |
| git clone -b uncrustify-0.64 --single-branch https://github.com/uncrustify/uncrustify.git | |
| echo "Building and installing Uncrustify..." | |
| mkdir ./uncrustify/build && cd ./uncrustify/build | |
| cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=RelWithDebInfo ../ | |
| sudo make -j "$(nproc)" | |
| sudo make install | |
| echo "Uncrustify has been installed successfully!" | |
| cd ../../ | |
| sudo cp ./.github/coding-convention-tool/tools/uncrustify/uncrustify.cfg ./uncrustify/uncrustify.cfg | |
| echo "Install clang-tidy" | |
| sudo apt-get install clang-tidy | |
| - name: Apply custom formatting configuration | |
| run: | | |
| echo "Applying custom formatting configuration..." | |
| chmod +x ./.github/coding-convention-tool/project_custom_config_handler.sh | |
| ./.github/coding-convention-tool/project_custom_config_handler.sh | |
| - name: Modify pre-commit config to exclude folders | |
| run: | | |
| echo "Installing yq for YAML processing..." | |
| sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 | |
| sudo chmod +x /usr/local/bin/yq | |
| echo "Modifying .pre-commit-config.yaml to exclude specific folders..." | |
| config_file=".github/coding-convention-tool/.pre-commit-config.yaml" | |
| new_patterns=".*lis2d(e|w)12_reg\.(c|h)" | |
| current_exclude=$(yq '.exclude' "$config_file") | |
| updated_exclude="${current_exclude}|${new_patterns}" | |
| yq -i ".exclude = \"$updated_exclude\"" "$config_file" | |
| echo "Successfully updated .pre-commit-config.yaml with exclude patterns" | |
| echo "New exclude pattern: $updated_exclude" | |
| - name: Run test | |
| run: | | |
| pre-commit install --config .github/coding-convention-tool/.pre-commit-config.yaml | |
| pre-commit run --config .github/coding-convention-tool/.pre-commit-config.yaml --all-files 2>&1 | tee CodingConventionTool.txt | |
| git diff > code-fix.patch || echo "No changes to patch." | |
| ls -lah code-fix.patch | |
| - name: Upload Result | |
| uses: actions/[email protected] | |
| with: | |
| name: CodingConventionResult | |
| path: CodingConventionTool.txt | |
| retention-days: 90 | |
| - name: Upload Patch | |
| uses: actions/[email protected] | |
| with: | |
| name: code-fix.patch | |
| path: code-fix.patch | |
| retention-days: 90 | |
| - name: Check log file to set status of the job | |
| run: | | |
| keywords=("Failed") | |
| for keyword in "${keywords[@]}"; do | |
| if grep -q "$keyword" CodingConventionTool.txt; then | |
| echo "Keyword '$keyword' found in the file." | |
| exit 1 | |
| else | |
| echo "Keyword '$keyword' not found in the file." | |
| fi | |
| done |