From a7432c9b3f089aa9168b264d29b3b365719b4858 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 17 Oct 2024 20:16:31 -0700 Subject: [PATCH 1/4] add: opt in color log output resolves #275 --- README.md | 4 ++++ action.yml | 10 ++++++++++ color-requirements.txt | 1 + 3 files changed, 15 insertions(+) create mode 100644 color-requirements.txt diff --git a/README.md b/README.md index 8b608b8..58d39e4 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ workflow [`step-summary`][step-summary], and Pull Request reviews (with Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/cpp-linter.yml](https://github.com/cpp-linter/cpp-linter-action/blob/main/.github/workflows/cpp-linter.yml) +> [!TIP] +> To enable color output in the workflow logs, set the environment variable `CPP_LINTER_COLOR` to a value of `on` or `true` or `1`. + The content of the file should be in the following format. ```yaml @@ -56,6 +59,7 @@ The content of the file should be in the following format. id: linter env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CPP_LINTER_COLOR: on # off by default with: style: 'file' # Use .clang-format config file tidy-checks: '' # Use .clang-tidy config file diff --git a/action.yml b/action.yml index a676f41..156f160 100644 --- a/action.yml +++ b/action.yml @@ -269,6 +269,11 @@ runs: source "$GITHUB_ACTION_PATH/venv/bin/activate" pip install -r "$GITHUB_ACTION_PATH/requirements.txt" clang-tools -i ${{ inputs.version }} -b + case "${{ env.CPP_LINTER_COLOR }}" in + "true" | "on" | "1") + pip install -r "$GITHUB_ACTION_PATH/color-requirements.txt" + ;; + esac - name: Run cpp-linter (Unix) id: cpp-linter-unix @@ -308,6 +313,11 @@ runs: 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 + $colorEnabled = "true","on","1" + if ( $colorEnabled.contains("${{ env.CPP_LINTER_COLOR }}") ) + { + pip install -r "$GITHUB_ACTION_PATH/color-requirements.txt" + } - name: Run cpp-linter (Windows) id: cpp-linter-windows diff --git a/color-requirements.txt b/color-requirements.txt new file mode 100644 index 0000000..3bdf75a --- /dev/null +++ b/color-requirements.txt @@ -0,0 +1 @@ +rich==13.9.2 From 531483d8250f331344cf02546b13e77718631c00 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 17 Oct 2024 20:40:00 -0700 Subject: [PATCH 2/4] AI suggestions --- README.md | 4 +++- action.yml | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 58d39e4..c0a71bf 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,9 @@ workflow [`step-summary`][step-summary], and Pull Request reviews (with Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/cpp-linter.yml](https://github.com/cpp-linter/cpp-linter-action/blob/main/.github/workflows/cpp-linter.yml) > [!TIP] -> To enable color output in the workflow logs, set the environment variable `CPP_LINTER_COLOR` to a value of `on` or `true` or `1`. +> To enable color output in the workflow logs, +> set the environment variable `CPP_LINTER_COLOR` to a +> value of `on`, `true`, or `1`. The content of the file should be in the following format. diff --git a/action.yml b/action.yml index 156f160..4b67e92 100644 --- a/action.yml +++ b/action.yml @@ -269,6 +269,8 @@ runs: source "$GITHUB_ACTION_PATH/venv/bin/activate" pip install -r "$GITHUB_ACTION_PATH/requirements.txt" clang-tools -i ${{ inputs.version }} -b + + # Install color output requirements if enabled case "${{ env.CPP_LINTER_COLOR }}" in "true" | "on" | "1") pip install -r "$GITHUB_ACTION_PATH/color-requirements.txt" @@ -313,6 +315,8 @@ runs: 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 + + # Install color output requirements if enabled $colorEnabled = "true","on","1" if ( $colorEnabled.contains("${{ env.CPP_LINTER_COLOR }}") ) { From 4686680afe5f6bdecf24e952b3baa98a6edb7971 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 17 Oct 2024 23:36:37 -0700 Subject: [PATCH 3/4] fix env path on windows use native shells' env var syntax --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 4b67e92..2b6894e 100644 --- a/action.yml +++ b/action.yml @@ -271,7 +271,7 @@ runs: clang-tools -i ${{ inputs.version }} -b # Install color output requirements if enabled - case "${{ env.CPP_LINTER_COLOR }}" in + case "$CPP_LINTER_COLOR" in "true" | "on" | "1") pip install -r "$GITHUB_ACTION_PATH/color-requirements.txt" ;; @@ -318,9 +318,9 @@ runs: # Install color output requirements if enabled $colorEnabled = "true","on","1" - if ( $colorEnabled.contains("${{ env.CPP_LINTER_COLOR }}") ) + if ( $colorEnabled.contains("$env:CPP_LINTER_COLOR") ) { - pip install -r "$GITHUB_ACTION_PATH/color-requirements.txt" + pip install -r "$env:GITHUB_ACTION_PATH/color-requirements.txt" } - name: Run cpp-linter (Windows) From 17cbc5ca105f8bbd1c21b2b10cafd1818bc8b2a1 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 17 Oct 2024 23:51:20 -0700 Subject: [PATCH 4/4] set `FORCE_COLOR=1` when needed allows rich to force-enable coloring The env changes should only apply to the composite action's env --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 2b6894e..a329809 100644 --- a/action.yml +++ b/action.yml @@ -274,6 +274,7 @@ runs: case "$CPP_LINTER_COLOR" in "true" | "on" | "1") pip install -r "$GITHUB_ACTION_PATH/color-requirements.txt" + echo "FORCE_COLOR=1" >> $GITHUB_ENV ;; esac @@ -321,6 +322,7 @@ runs: if ( $colorEnabled.contains("$env:CPP_LINTER_COLOR") ) { pip install -r "$env:GITHUB_ACTION_PATH/color-requirements.txt" + echo "FORCE_COLOR=1" >> $env.GITHUB_ENV } - name: Run cpp-linter (Windows)