Skip to content

Commit 10b0f10

Browse files
authored
use a python venv (#173)
* 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
1 parent e163f22 commit 10b0f10

File tree

2 files changed

+88
-39
lines changed

2 files changed

+88
-39
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
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.
1212

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

1520
v2

action.yml

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -102,58 +102,102 @@ inputs:
102102
outputs:
103103
checks-failed:
104104
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy and clang-format.
105-
value: ${{ steps.cpp-linter.outputs.checks-failed }}
105+
value: ${{ steps.cpp-linter-unix.outputs.checks-failed || steps.cpp-linter-windows.outputs.checks-failed }}
106106
clang-tidy-checks-failed:
107107
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy only.
108-
value: ${{ steps.cpp-linter.outputs.clang-tidy-checks-failed }}
108+
value: ${{ steps.cpp-linter-unix.outputs.clang-tidy-checks-failed || steps.cpp-linter-windows.outputs.clang-tidy-checks-failed }}
109109
clang-format-checks-failed:
110110
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-format only.
111-
value: ${{ steps.cpp-linter.outputs.clang-format-checks-failed }}
111+
value: ${{ steps.cpp-linter-unix.outputs.clang-format-checks-failed || steps.cpp-linter-windows.outputs.clang-format-checks-failed }}
112112
runs:
113113
using: "composite"
114114
steps:
115-
- name: Install action dependencies
115+
- name: Install python
116+
uses: actions/setup-python@v4
117+
id: setup-python
118+
with:
119+
python-version: '3.11'
120+
update-environment: false
121+
122+
- name: Install Linux clang dependencies
123+
if: runner.os == 'Linux'
116124
shell: bash
117125
run: |
118-
if [[ "${{runner.os}}" == "Linux" ]]; then
119-
sudo apt-get update
120-
# First try installing from default Ubuntu repositories before trying LLVM script
121-
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
122-
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
123-
wget https://apt.llvm.org/llvm.sh -O $GITHUB_ACTION_PATH/llvm_install.sh
124-
chmod +x $GITHUB_ACTION_PATH/llvm_install.sh
125-
if sudo $GITHUB_ACTION_PATH/llvm_install.sh ${{ inputs.version }}; then
126-
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
127-
fi
126+
sudo apt-get update
127+
# First try installing from default Ubuntu repositories before trying LLVM script
128+
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
129+
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
130+
wget https://apt.llvm.org/llvm.sh -O $GITHUB_ACTION_PATH/llvm_install.sh
131+
chmod +x $GITHUB_ACTION_PATH/llvm_install.sh
132+
if sudo $GITHUB_ACTION_PATH/llvm_install.sh ${{ inputs.version }}; then
133+
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
128134
fi
129135
fi
130-
if [[ "${{runner.os}}" == "macOS" ]]; then
131-
python3 -m venv "$GITHUB_ACTION_PATH/venv"
132-
source "$GITHUB_ACTION_PATH/venv/bin/activate"
133-
fi
134-
python3 -m pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
136+
137+
- name: Setup python venv (Unix)
138+
if: runner.os == 'Linux' || runner.os == 'macOS'
139+
shell: bash
140+
run: |
141+
${{ steps.setup-python.outputs.python-path }} -m venv "$GITHUB_ACTION_PATH/venv"
142+
source "$GITHUB_ACTION_PATH/venv/bin/activate"
143+
pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
135144
clang-tools -i ${{ inputs.version }} -b
136145
137-
- name: Run cpp-linter
138-
id: cpp-linter
146+
- name: Run cpp-linter (Unix)
147+
id: cpp-linter-unix
148+
if: runner.os == 'Linux' || runner.os == 'macOS'
139149
shell: bash
140150
run: |
141-
if [[ "${{runner.os}}" == "macOS" ]]; then
142-
source "$GITHUB_ACTION_PATH/venv/bin/activate"
143-
fi
151+
source "$GITHUB_ACTION_PATH/venv/bin/activate"
152+
144153
cpp-linter \
145-
--style="${{ inputs.style }}" \
146-
--extensions=${{ inputs.extensions }} \
147-
--tidy-checks="${{ inputs.tidy-checks }}" \
148-
--repo-root=${{ inputs.repo-root }} \
149-
--version=${{ inputs.version }} \
150-
--verbosity=${{ inputs.verbosity }} \
151-
--lines-changed-only=${{ inputs.lines-changed-only }} \
152-
--files-changed-only=${{ inputs.files-changed-only }} \
153-
--thread-comments=${{ inputs.thread-comments }} \
154-
--no-lgtm=${{ inputs.no-lgtm }} \
155-
--step-summary=${{ inputs.step-summary }} \
156-
--ignore="${{ inputs.ignore }}" \
157-
--database=${{ inputs.database }} \
158-
--file-annotations=${{ inputs.file-annotations }} \
159-
--extra-arg="${{ inputs.extra-args }}"
154+
--style="${{ inputs.style }}" \
155+
--extensions=${{ inputs.extensions }} \
156+
--tidy-checks="${{ inputs.tidy-checks }}" \
157+
--repo-root=${{ inputs.repo-root }} \
158+
--version=${{ inputs.version }} \
159+
--verbosity=${{ inputs.verbosity }} \
160+
--lines-changed-only=${{ inputs.lines-changed-only }} \
161+
--files-changed-only=${{ inputs.files-changed-only }} \
162+
--thread-comments=${{ inputs.thread-comments }} \
163+
--no-lgtm=${{ inputs.no-lgtm }} \
164+
--step-summary=${{ inputs.step-summary }} \
165+
--ignore="${{ inputs.ignore }}" \
166+
--database=${{ inputs.database }} \
167+
--file-annotations=${{ inputs.file-annotations }} \
168+
--extra-arg="${{ inputs.extra-args }}"
169+
170+
- name: Setup python venv (Windows)
171+
if: runner.os == 'Windows'
172+
shell: pwsh
173+
run: |
174+
${{ steps.setup-python.outputs.python-path }} -m venv "$env:GITHUB_ACTION_PATH/venv"
175+
Invoke-Expression -Command "$env:GITHUB_ACTION_PATH/venv/Scripts/Activate.ps1"
176+
pip install -r "$env:GITHUB_ACTION_PATH/requirements.txt"
177+
clang-tools -i ${{ inputs.version }} -b
178+
179+
- name: Run cpp-linter (Windows)
180+
id: cpp-linter-windows
181+
if: runner.os == 'Windows'
182+
shell: pwsh
183+
run: |
184+
Invoke-Expression -Command "$env:GITHUB_ACTION_PATH/venv/Scripts/Activate.ps1"
185+
186+
$app = 'cpp-linter' +
187+
' --style="${{ inputs.style }}"' +
188+
' --extensions=${{ inputs.extensions }}' +
189+
' --tidy-checks="${{ inputs.tidy-checks }}"' +
190+
' --repo-root=${{ inputs.repo-root }}' +
191+
' --version=${{ inputs.version }}' +
192+
' --verbosity=${{ inputs.verbosity }}' +
193+
' --lines-changed-only=${{ inputs.lines-changed-only }}' +
194+
' --files-changed-only=${{ inputs.files-changed-only }}' +
195+
' --thread-comments=${{ inputs.thread-comments }}' +
196+
' --no-lgtm=${{ inputs.no-lgtm }}' +
197+
' --step-summary=${{ inputs.step-summary }}' +
198+
' --ignore="${{ inputs.ignore }}"' +
199+
' --database=${{ inputs.database }}' +
200+
' --file-annotations=${{ inputs.file-annotations }}' +
201+
' --extra-arg="${{ inputs.extra-args }}"'
202+
203+
Invoke-Expression -Command $app

0 commit comments

Comments
 (0)