Conditionally create log file

This commit is contained in:
Marco Ferrari 2023-01-05 13:32:46 +00:00 committed by Brett Logan
parent 885744f3f4
commit f0fe1c900b
2 changed files with 16 additions and 7 deletions

View file

@ -93,7 +93,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their codebase w
| **Rust** | [Rustfmt](https://github.com/rust-lang/rustfmt) / [Clippy](https://github.com/rust-lang/rust-clippy) | | **Rust** | [Rustfmt](https://github.com/rust-lang/rustfmt) / [Clippy](https://github.com/rust-lang/rust-clippy) |
| **Scala** | [scalafmt](https://github.com/scalameta/scalafmt) | | **Scala** | [scalafmt](https://github.com/scalameta/scalafmt) |
| **Secrets** | [GitLeaks](https://github.com/zricethezav/gitleaks) | | **Secrets** | [GitLeaks](https://github.com/zricethezav/gitleaks) |
| **Shell** | [ShellCheck](https://github.com/koalaman/shellcheck) / [executable bit check] / [shfmt](https://github.com/mvdan/sh) | | **Shell** | [ShellCheck](https://github.com/koalaman/shellcheck) / `executable bit check` / [shfmt](https://github.com/mvdan/sh) |
| **Snakemake** | [snakefmt](https://github.com/snakemake/snakefmt/) / [snakemake --lint](https://snakemake.readthedocs.io/en/stable/snakefiles/writing_snakefiles.html#best-practices) | | **Snakemake** | [snakefmt](https://github.com/snakemake/snakefmt/) / [snakemake --lint](https://snakemake.readthedocs.io/en/stable/snakefiles/writing_snakefiles.html#best-practices) |
| **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) / [sqlfluff](https://github.com/sqlfluff/sqlfluff) | | **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) / [sqlfluff](https://github.com/sqlfluff/sqlfluff) |
| **Tekton** | [tekton-lint](https://github.com/IBM/tekton-lint) | | **Tekton** | [tekton-lint](https://github.com/IBM/tekton-lint) |
@ -123,7 +123,7 @@ To use this **GitHub** Action you will need to complete the following:
In your repository you should have a `.github/workflows` folder with **GitHub** Action similar to below: In your repository you should have a `.github/workflows` folder with **GitHub** Action similar to below:
- `.github/workflows/linter.yml` - `.github/workflows/linter.yml`
- Example file can be found at [`TEMPLATES/linter.yml`](/TEMPLATES/linter.yml) - Example file can be found at [`TEMPLATES/linter.yml`](TEMPLATES/linter.yml)
This file should have the following code: This file should have the following code:
@ -273,6 +273,7 @@ But if you wish to select or exclude specific linters, we give you full control
| **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. | | **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. |
| **ANSIBLE_CONFIG_FILE** | `.ansible-lint.yml` | Filename for [Ansible-lint configuration](https://ansible-lint.readthedocs.io/en/latest/configuring.html#configuration-file) (ex: `.ansible-lint`, `.ansible-lint.yml`) | | **ANSIBLE_CONFIG_FILE** | `.ansible-lint.yml` | Filename for [Ansible-lint configuration](https://ansible-lint.readthedocs.io/en/latest/configuring.html#configuration-file) (ex: `.ansible-lint`, `.ansible-lint.yml`) |
| **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s), relative to `DEFAULT_WORKSPACE`. Set to `.` to use the top-level of the `DEFAULT_WORKSPACE`. | | **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s), relative to `DEFAULT_WORKSPACE`. Set to `.` to use the top-level of the `DEFAULT_WORKSPACE`. |
| **CREATE_LOG_FILE** | `false` | If set to `true`, it creates the log file. You can set the log file name using the `LOG_FILE` environment variable. |
| **CSS_FILE_NAME** | `.stylelintrc.json` | Filename for [Stylelint configuration](https://github.com/stylelint/stylelint) (ex: `.stylelintrc.yml`, `.stylelintrc.yaml`) | | **CSS_FILE_NAME** | `.stylelintrc.json` | Filename for [Stylelint configuration](https://github.com/stylelint/stylelint) (ex: `.stylelintrc.yml`, `.stylelintrc.yaml`) |
| **DEFAULT_BRANCH** | `master` | The name of the repository default branch. | | **DEFAULT_BRANCH** | `master` | The name of the repository default branch. |
| **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. | | **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. |

View file

@ -20,6 +20,8 @@ IMAGE="${IMAGE:-standard}" # Version of the Super-lin
################################################################## ##################################################################
LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder) LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder)
LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE) LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE)
CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}"
export CREATE_LOG_FILE
if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi
# Boolean to see trace logs # Boolean to see trace logs
@ -800,18 +802,24 @@ UpdateLoopsForImage() {
done done
fi fi
} }
################################################################################
#### Function Cleanup ##########################################################
# shellcheck disable=SC2317 # shellcheck disable=SC2317
cleanup() { cleanup() {
local -ri EXIT_CODE=$? local -ri EXIT_CODE=$?
local LOG_FILE_PATH="${GITHUB_WORKSPACE}/${LOG_FILE}"
sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true debug "CREATE_LOG_FILE: ${CREATE_LOG_FILE}, LOG_FILE_PATH: ${LOG_FILE_PATH}"
if [ "${CREATE_LOG_FILE}" = "true" ]; then
debug "Creating log file: ${LOG_FILE_PATH}"
sh -c "cat ${LOG_TEMP} >> ${LOG_FILE_PATH}" || true
else
debug "Skipping the log file creation"
fi
exit "${EXIT_CODE}" exit "${EXIT_CODE}"
trap - 0 1 2 3 6 14 15 trap - 0 1 2 3 6 14 15
} }
trap 'cleanup' 0 1 2 3 6 14 15 trap 'cleanup' 0 1 2 3 6 14 15
################################################################################ ################################################################################
############################### MAIN ########################################### ############################### MAIN ###########################################
################################################################################ ################################################################################