Skip to content

Commit

Permalink
use a python venv (#173)
Browse files Browse the repository at this point in the history
* use a python venv
  adheres to PEP668 and addresses #171
* use powershell to manage py venv in windows runners
* leverage steps.if with duplicated scripts
  should support thee OS's native shell
* Add warning to README about debian only support
  • Loading branch information
2bndy5 authored Dec 11, 2023
1 parent e163f22 commit 10b0f10
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 39 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of annotations, thread comments, and step summary.

> [!WARNING]
> We only support Linux runners using a Debian based Linux OS (like Ubuntu and many others).
>
> MacOS and Windows runners are supported as well.
## What's New

v2
Expand Down
122 changes: 83 additions & 39 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,58 +102,102 @@ inputs:
outputs:
checks-failed:
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy and clang-format.
value: ${{ steps.cpp-linter.outputs.checks-failed }}
value: ${{ steps.cpp-linter-unix.outputs.checks-failed || steps.cpp-linter-windows.outputs.checks-failed }}
clang-tidy-checks-failed:
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy only.
value: ${{ steps.cpp-linter.outputs.clang-tidy-checks-failed }}
value: ${{ steps.cpp-linter-unix.outputs.clang-tidy-checks-failed || steps.cpp-linter-windows.outputs.clang-tidy-checks-failed }}
clang-format-checks-failed:
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-format only.
value: ${{ steps.cpp-linter.outputs.clang-format-checks-failed }}
value: ${{ steps.cpp-linter-unix.outputs.clang-format-checks-failed || steps.cpp-linter-windows.outputs.clang-format-checks-failed }}
runs:
using: "composite"
steps:
- name: Install action dependencies
- name: Install python
uses: actions/setup-python@v4
id: setup-python
with:
python-version: '3.11'
update-environment: false

- name: Install Linux clang dependencies
if: runner.os == 'Linux'
shell: bash
run: |
if [[ "${{runner.os}}" == "Linux" ]]; then
sudo apt-get update
# First try installing from default Ubuntu repositories before trying LLVM script
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
wget https://apt.llvm.org/llvm.sh -O $GITHUB_ACTION_PATH/llvm_install.sh
chmod +x $GITHUB_ACTION_PATH/llvm_install.sh
if sudo $GITHUB_ACTION_PATH/llvm_install.sh ${{ inputs.version }}; then
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
fi
sudo apt-get update
# First try installing from default Ubuntu repositories before trying LLVM script
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
wget https://apt.llvm.org/llvm.sh -O $GITHUB_ACTION_PATH/llvm_install.sh
chmod +x $GITHUB_ACTION_PATH/llvm_install.sh
if sudo $GITHUB_ACTION_PATH/llvm_install.sh ${{ inputs.version }}; then
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
fi
fi
if [[ "${{runner.os}}" == "macOS" ]]; then
python3 -m venv "$GITHUB_ACTION_PATH/venv"
source "$GITHUB_ACTION_PATH/venv/bin/activate"
fi
python3 -m pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
- name: Setup python venv (Unix)
if: runner.os == 'Linux' || runner.os == 'macOS'
shell: bash
run: |
${{ steps.setup-python.outputs.python-path }} -m venv "$GITHUB_ACTION_PATH/venv"
source "$GITHUB_ACTION_PATH/venv/bin/activate"
pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
clang-tools -i ${{ inputs.version }} -b
- name: Run cpp-linter
id: cpp-linter
- name: Run cpp-linter (Unix)
id: cpp-linter-unix
if: runner.os == 'Linux' || runner.os == 'macOS'
shell: bash
run: |
if [[ "${{runner.os}}" == "macOS" ]]; then
source "$GITHUB_ACTION_PATH/venv/bin/activate"
fi
source "$GITHUB_ACTION_PATH/venv/bin/activate"
cpp-linter \
--style="${{ inputs.style }}" \
--extensions=${{ inputs.extensions }} \
--tidy-checks="${{ inputs.tidy-checks }}" \
--repo-root=${{ inputs.repo-root }} \
--version=${{ inputs.version }} \
--verbosity=${{ inputs.verbosity }} \
--lines-changed-only=${{ inputs.lines-changed-only }} \
--files-changed-only=${{ inputs.files-changed-only }} \
--thread-comments=${{ inputs.thread-comments }} \
--no-lgtm=${{ inputs.no-lgtm }} \
--step-summary=${{ inputs.step-summary }} \
--ignore="${{ inputs.ignore }}" \
--database=${{ inputs.database }} \
--file-annotations=${{ inputs.file-annotations }} \
--extra-arg="${{ inputs.extra-args }}"
--style="${{ inputs.style }}" \
--extensions=${{ inputs.extensions }} \
--tidy-checks="${{ inputs.tidy-checks }}" \
--repo-root=${{ inputs.repo-root }} \
--version=${{ inputs.version }} \
--verbosity=${{ inputs.verbosity }} \
--lines-changed-only=${{ inputs.lines-changed-only }} \
--files-changed-only=${{ inputs.files-changed-only }} \
--thread-comments=${{ inputs.thread-comments }} \
--no-lgtm=${{ inputs.no-lgtm }} \
--step-summary=${{ inputs.step-summary }} \
--ignore="${{ inputs.ignore }}" \
--database=${{ inputs.database }} \
--file-annotations=${{ inputs.file-annotations }} \
--extra-arg="${{ inputs.extra-args }}"
- name: Setup python venv (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
${{ steps.setup-python.outputs.python-path }} -m venv "$env:GITHUB_ACTION_PATH/venv"
Invoke-Expression -Command "$env:GITHUB_ACTION_PATH/venv/Scripts/Activate.ps1"
pip install -r "$env:GITHUB_ACTION_PATH/requirements.txt"
clang-tools -i ${{ inputs.version }} -b
- name: Run cpp-linter (Windows)
id: cpp-linter-windows
if: runner.os == 'Windows'
shell: pwsh
run: |
Invoke-Expression -Command "$env:GITHUB_ACTION_PATH/venv/Scripts/Activate.ps1"
$app = 'cpp-linter' +
' --style="${{ inputs.style }}"' +
' --extensions=${{ inputs.extensions }}' +
' --tidy-checks="${{ inputs.tidy-checks }}"' +
' --repo-root=${{ inputs.repo-root }}' +
' --version=${{ inputs.version }}' +
' --verbosity=${{ inputs.verbosity }}' +
' --lines-changed-only=${{ inputs.lines-changed-only }}' +
' --files-changed-only=${{ inputs.files-changed-only }}' +
' --thread-comments=${{ inputs.thread-comments }}' +
' --no-lgtm=${{ inputs.no-lgtm }}' +
' --step-summary=${{ inputs.step-summary }}' +
' --ignore="${{ inputs.ignore }}"' +
' --database=${{ inputs.database }}' +
' --file-annotations=${{ inputs.file-annotations }}' +
' --extra-arg="${{ inputs.extra-args }}"'
Invoke-Expression -Command $app

1 comment on commit 10b0f10

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format reports: 2 file(s) not formatted
  • src/demo.cpp
  • src/demo.hpp
clang-tidy reports: 7 concern(s)
  • src/demo.cpp

    C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.38.33130/include/yvals_core.h:887:1: error: [clang-diagnostic-error]

    static_assert failed "Error in C++ Standard Library usage."

    _EMIT_STL_ERROR(STL1000, "Unexpected compiler version, expected Clang 16.0.0 or newer.");
    ^
    C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\yvals_core.h:514:5: note: expanded from macro '_EMIT_STL_ERROR'
        static_assert(false, "Error in C++ Standard Library usage.")
        ^

    /src/demo.cpp:7:8: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

    size_t dummyFunc(size_t i) { return i; }
    ~~~~~~ ^
    auto                       -> size_t

    /src/demo.cpp:9:5: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

    int main()
    ~~~ ^
    auto       -> int

    /src/demo.cpp:11:13: warning: [readability-braces-around-statements]

    statement should be inside braces

        for (;;)
                ^
                 {

    /src/demo.cpp:14:5: warning: [cppcoreguidelines-pro-type-vararg]

    do not call c-style vararg functions

        printf("Hello world!\n");
        ^
  • src/demo.hpp

    /src/demo.hpp:10:11: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

        void *not_usefull(char *str){
        ~~~~~~^
        auto                         -> void *

    /src/demo.hpp:12:16: warning: [modernize-use-nullptr]

    use nullptr

            return 0;
                   ^
                   nullptr

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.