diff --git a/.github/linters/.textlintrc b/.github/linters/.textlintrc deleted file mode 100644 index 50706968..00000000 --- a/.github/linters/.textlintrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "filters": { - "comments": true - }, - "rules": { - "terminology": true - } -} diff --git a/.gitignore b/.gitignore index f510b7bb..68cb10fa 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,4 @@ test/linters/rust_clippy/**/target/** # Super-linter ouputs super-linter-output/ custom-super-linter-output-directory-name/ +super-linter-github-actions-step-summary-output* diff --git a/Makefile b/Makefile index f1f6d96b..9866ccaf 100644 --- a/Makefile +++ b/Makefile @@ -353,7 +353,8 @@ test-custom-ssl-cert: ## Test the configuration of a custom SSL/TLS certificate test-non-default-home-directory: ## Test a non-default HOME directory $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_non_default_home" + "run_test_cases_non_default_home" \ + "$(IMAGE)" .PHONY: test-linters test-linters: test-linters-expect-success test-linters-expect-failure ## Run the linters test suite @@ -362,61 +363,71 @@ test-linters: test-linters-expect-success test-linters-expect-failure ## Run the test-linters-expect-success: ## Run the linters test suite expecting successes $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_expect_success" + "run_test_cases_expect_success" \ + "$(IMAGE)" .PHONY: test-linters-expect-failure test-linters-expect-failure: ## Run the linters test suite expecting failures $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_expect_failure" + "run_test_cases_expect_failure" \ + "$(IMAGE)" .PHONY: test-log-level test-log-level: ## Run a test to check if there are conflicts with the LOG_LEVEL variable $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_log_level" + "run_test_cases_log_level" \ + "$(IMAGE)" .PHONY: test-linters-expect-failure-log-level-notice test-linters-expect-failure-log-level-notice: ## Run the linters test suite expecting failures with a LOG_LEVEL set to NOTICE $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_expect_failure_notice_log" + "run_test_cases_expect_failure_notice_log" \ + "$(IMAGE)" .PHONY: test-bash-exec-library-expect-success test-bash-exec-library-expect-success: ## Run the linters test cases for BASH_EXEC expecting successes with BASH_EXEC_IGNORE_LIBRARIES set to true $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_case_bash_exec_library_expect_success" + "run_test_case_bash_exec_library_expect_success" \ + "$(IMAGE)" .PHONY: test-bash-exec-library-expect-failure test-bash-exec-library-expect-failure: ## Run the linters test cases for BASH_EXEC expecting failures with BASH_EXEC_IGNORE_LIBRARIES set to true $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_case_bash_exec_library_expect_failure" + "run_test_case_bash_exec_library_expect_failure" \ + "$(IMAGE)" .PHONY: test-git-initial-commit test-git-initial-commit: ## Run super-linter against a repository that only has one commit $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_case_git_initial_commit" + "run_test_case_git_initial_commit" \ + "$(IMAGE)" .PHONY: test-use-find-and-ignore-gitignored-files test-use-find-and-ignore-gitignored-files: ## Run super-linter with USE_FIND_ALGORITHM=true and IGNORE_GITIGNORED_FILES=true $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_case_use_find_and_ignore_gitignored_files" + "run_test_case_use_find_and_ignore_gitignored_files" \ + "$(IMAGE)" .PHONY: test-save-super-linter-output test-save-super-linter-output: ## Run super-linter with SAVE_SUPER_LINTER_OUTPUT=true $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_save_super_linter_output" + "run_test_cases_save_super_linter_output" \ + "$(IMAGE)" .PHONY: test-save-super-linter-output-custom-path test-save-super-linter-output-custom-path: ## Run super-linter with SAVE_SUPER_LINTER_OUTPUT=true and save output in a custom directory $(CURDIR)/test/run-super-linter-tests.sh \ $(SUPER_LINTER_TEST_CONTAINER_URL) \ - "run_test_cases_save_super_linter_output_custom_path" + "run_test_cases_save_super_linter_output_custom_path" \ + "$(IMAGE)" .PHONY: docker-dev-container-build-check ## Run Docker build checks against the dev-container image docker-dev-container-build-check: diff --git a/README.md b/README.md index 274c4d1f..95a10479 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ You can configure super-linter using the following environment variables: | **DOCKERFILE_HADOLINT_FILE_NAME** | `.hadolint.yaml` | Filename for [hadolint configuration](https://github.com/hadolint/hadolint) (ex: `.hadolintlintrc.yaml`) | | **EDITORCONFIG_FILE_NAME** | `.ecrc` | Filename for [editorconfig-checker configuration](https://github.com/editorconfig-checker/editorconfig-checker) | | **ENABLE_GITHUB_ACTIONS_GROUP_TITLE** | `false` if `RUN_LOCAL=true`, `true` otherwise | Flag to enable [GitHub Actions log grouping](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines). | +| **ENABLE_GITHUB_ACTIONS_STEP_SUMMARY** | `false` if `RUN_LOCAL=true`, `true` otherwise | Flag to enable [GitHub Actions job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary) for the Super-linter action. | | **FILTER_REGEX_EXCLUDE** | not set | Regular expression defining which files will be excluded from linting (ex: `.*src/test.*`). Not setting this variable means to process all files. | | **FILTER_REGEX_INCLUDE** | not set | Regular expression defining which files will be processed by linters (ex: `.*src/.*`). Not setting this variable means to process all files. `FILTER_REGEX_INCLUDE` is evaluated before `FILTER_REGEX_EXCLUDE`. | | **GITHUB_ACTIONS_CONFIG_FILE** | `actionlint.yml` | Filename for [Actionlint configuration](https://github.com/rhysd/actionlint/blob/main/docs/config.md) (ex: `actionlint.yml`) | diff --git a/lib/functions/validation.sh b/lib/functions/validation.sh index 268b61d3..e7ea98d1 100755 --- a/lib/functions/validation.sh +++ b/lib/functions/validation.sh @@ -6,6 +6,7 @@ function ValidateBooleanConfigurationVariables() { ValidateBooleanVariable "CREATE_LOG_FILE" "${CREATE_LOG_FILE}" ValidateBooleanVariable "DISABLE_ERRORS" "${DISABLE_ERRORS}" ValidateBooleanVariable "ENABLE_GITHUB_ACTIONS_GROUP_TITLE" "${ENABLE_GITHUB_ACTIONS_GROUP_TITLE}" + ValidateBooleanVariable "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY" "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" ValidateBooleanVariable "IGNORE_GENERATED_FILES" "${IGNORE_GENERATED_FILES}" ValidateBooleanVariable "IGNORE_GITIGNORED_FILES" "${IGNORE_GITIGNORED_FILES}" ValidateBooleanVariable "LOG_DEBUG" "${LOG_DEBUG}" @@ -293,6 +294,27 @@ function ValidateGitHubUrls() { fi } +function ValidateGitHubActionsStepSummary() { + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY:-}" == "true" ]]; then + debug "GitHub Actions step summary is enabled. ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: ${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" + if [[ -z "${GITHUB_STEP_SUMMARY:-}" ]]; then + error "GITHUB_STEP_SUMMARY is not set." + return 1 + fi + debug "GITHUB_STEP_SUMMARY is set to: ${GITHUB_STEP_SUMMARY}" + if [[ ! -e "${GITHUB_STEP_SUMMARY}" ]]; then + error "GITHUB_STEP_SUMMARY (${GITHUB_STEP_SUMMARY}) doesn't exist." + return 1 + fi + if [[ ! -f "${GITHUB_STEP_SUMMARY}" ]]; then + error "GITHUB_STEP_SUMMARY (${GITHUB_STEP_SUMMARY}) is not a file." + return 1 + fi + else + debug "GitHub Actions step summary is disabled because ENABLE_GITHUB_ACTIONS_STEP_SUMMARY is set to: ${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}). No need to validate its configuration." + fi +} + function WarnIfVariableIsSet() { local INPUT_VARIABLE="${1}" shift diff --git a/lib/linter.sh b/lib/linter.sh index 870a3556..87e4a01e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -47,8 +47,10 @@ RUN_LOCAL="${RUN_LOCAL:-"false"}" # configure it. if [[ "${RUN_LOCAL}" == "true" ]]; then DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE="false" + DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="false" else DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE="true" + DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true" fi # Let users configure GitHub Actions log markers regardless of running locally or not ENABLE_GITHUB_ACTIONS_GROUP_TITLE="${ENABLE_GITHUB_ACTIONS_GROUP_TITLE:-"${DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE}"}" @@ -56,6 +58,13 @@ export ENABLE_GITHUB_ACTIONS_GROUP_TITLE startGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}" +# Let users configure GitHub Actions step summary regardless of running locally or not +ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY:-"${DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}"}" +export ENABLE_GITHUB_ACTIONS_STEP_SUMMARY +if ! ValidateGitHubActionsStepSummary; then + fatal "GitHub Actions job summary configuration failed validation" +fi + # We want a lowercase value declare -l BASH_EXEC_IGNORE_LIBRARIES BASH_EXEC_IGNORE_LIBRARIES="${BASH_EXEC_IGNORE_LIBRARIES:-false}" @@ -591,6 +600,16 @@ Footer() { local SUPER_LINTER_EXIT_CODE SUPER_LINTER_EXIT_CODE=0 + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then + debug "Saving GitHub Actions step summary to ${GITHUB_STEP_SUMMARY}" + { + echo "# Super-linter summary" + echo "" + echo "| Language | Validation result |" + echo "| -----------------------|-------------------|" + } >>"${GITHUB_STEP_SUMMARY}" + fi + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do # This used to be the count of errors found for a given LANGUAGE, but since # after we switched to running linters against a batch of files, it may not @@ -607,6 +626,11 @@ Footer() { if [[ ${ERROR_COUNTER} -ne 0 ]]; then error "Errors found in ${LANGUAGE}" + + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then + echo "| ${LANGUAGE} | Fail ❌ |" >>"${GITHUB_STEP_SUMMARY}" + fi + # Print output as error in case users disabled the INFO level so they # get feedback if [[ "${LOG_VERBOSE}" != "true" ]]; then @@ -631,6 +655,9 @@ Footer() { debug "Setting super-linter exit code to ${SUPER_LINTER_EXIT_CODE} because there were errors for ${LANGUAGE}" elif [[ ${ERROR_COUNTER} -eq 0 ]]; then notice "Successfully linted ${LANGUAGE}" + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then + echo "| ${LANGUAGE} | Pass ✅ |" >>"${GITHUB_STEP_SUMMARY}" + fi CallStatusAPI "${LANGUAGE}" "success" ANY_LINTER_SUCCESS="true" debug "Set ANY_LINTER_SUCCESS to ${ANY_LINTER_SUCCESS} because ${LANGUAGE} reported a success" @@ -650,8 +677,24 @@ Footer() { if [[ ${SUPER_LINTER_EXIT_CODE} -eq 0 ]]; then notice "All files and directories linted successfully" + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then + { + echo "" + echo "All files and directories linted successfully" + } >>"${GITHUB_STEP_SUMMARY}" + fi else error "Super-linter detected linting errors" + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then + { + echo "" + echo "Super-linter detected linting errors" + } >>"${GITHUB_STEP_SUMMARY}" + fi + fi + + if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then + debug "GitHub Actions step summary file (${GITHUB_STEP_SUMMARY}) contents:\n$(cat "${GITHUB_STEP_SUMMARY}")" fi exit ${SUPER_LINTER_EXIT_CODE} diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md new file mode 100644 index 00000000..bd30bc89 --- /dev/null +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md @@ -0,0 +1,78 @@ +# Super-linter summary + + +| Language | Validation result | +| -----------------------|-------------------| +| ANSIBLE | Fail ❌ | +| BASH | Fail ❌ | +| BASH_EXEC | Fail ❌ | +| CHECKOV | Fail ❌ | +| CLANG_FORMAT | Fail ❌ | +| CLOUDFORMATION | Fail ❌ | +| CLOJURE | Fail ❌ | +| COFFEESCRIPT | Fail ❌ | +| CPP | Fail ❌ | +| CSS | Fail ❌ | +| DART | Fail ❌ | +| DOCKERFILE_HADOLINT | Fail ❌ | +| EDITORCONFIG | Fail ❌ | +| ENV | Fail ❌ | +| GITHUB_ACTIONS | Fail ❌ | +| GITLEAKS | Fail ❌ | +| GHERKIN | Fail ❌ | +| GO | Fail ❌ | +| GO_MODULES | Fail ❌ | +| GO_RELEASER | Fail ❌ | +| GOOGLE_JAVA_FORMAT | Fail ❌ | +| GROOVY | Fail ❌ | +| HTML | Fail ❌ | +| JAVA | Fail ❌ | +| JAVASCRIPT_ES | Fail ❌ | +| JAVASCRIPT_STANDARD | Fail ❌ | +| JSCPD | Fail ❌ | +| JSON | Fail ❌ | +| JSONC | Fail ❌ | +| JSX | Fail ❌ | +| KUBERNETES_KUBECONFORM | Fail ❌ | +| KOTLIN | Fail ❌ | +| LATEX | Fail ❌ | +| LUA | Fail ❌ | +| MARKDOWN | Fail ❌ | +| NATURAL_LANGUAGE | Fail ❌ | +| OPENAPI | Fail ❌ | +| PERL | Fail ❌ | +| PHP_BUILTIN | Fail ❌ | +| PHP_PHPCS | Fail ❌ | +| PHP_PHPSTAN | Fail ❌ | +| PHP_PSALM | Fail ❌ | +| PROTOBUF | Fail ❌ | +| PYTHON_BLACK | Fail ❌ | +| PYTHON_PYLINT | Fail ❌ | +| PYTHON_FLAKE8 | Fail ❌ | +| PYTHON_ISORT | Fail ❌ | +| PYTHON_MYPY | Fail ❌ | +| PYTHON_RUFF | Fail ❌ | +| R | Fail ❌ | +| RAKU | Fail ❌ | +| RENOVATE | Fail ❌ | +| RUBY | Fail ❌ | +| SCALAFMT | Fail ❌ | +| SHELL_SHFMT | Fail ❌ | +| SNAKEMAKE_LINT | Fail ❌ | +| SNAKEMAKE_SNAKEFMT | Fail ❌ | +| STATES | Fail ❌ | +| SQL | Fail ❌ | +| SQLFLUFF | Fail ❌ | +| TEKTON | Fail ❌ | +| TERRAFORM_FMT | Fail ❌ | +| TERRAFORM_TFLINT | Fail ❌ | +| TERRAFORM_TERRASCAN | Fail ❌ | +| TERRAGRUNT | Fail ❌ | +| TSX | Fail ❌ | +| TYPESCRIPT_ES | Fail ❌ | +| TYPESCRIPT_STANDARD | Fail ❌ | +| XML | Fail ❌ | +| YAML | Fail ❌ | + + +Super-linter detected linting errors diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md new file mode 100644 index 00000000..c10bbd4b --- /dev/null +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-standard.md @@ -0,0 +1,85 @@ +# Super-linter summary + + +| Language | Validation result | +| -----------------------|-------------------| +| ANSIBLE | Fail ❌ | +| ARM | Fail ❌ | +| BASH | Fail ❌ | +| BASH_EXEC | Fail ❌ | +| CHECKOV | Fail ❌ | +| CLANG_FORMAT | Fail ❌ | +| CLOUDFORMATION | Fail ❌ | +| CLOJURE | Fail ❌ | +| COFFEESCRIPT | Fail ❌ | +| CPP | Fail ❌ | +| CSHARP | Fail ❌ | +| CSS | Fail ❌ | +| DART | Fail ❌ | +| DOCKERFILE_HADOLINT | Fail ❌ | +| EDITORCONFIG | Fail ❌ | +| ENV | Fail ❌ | +| GITHUB_ACTIONS | Fail ❌ | +| GITLEAKS | Fail ❌ | +| GHERKIN | Fail ❌ | +| GO | Fail ❌ | +| GO_MODULES | Fail ❌ | +| GO_RELEASER | Fail ❌ | +| GOOGLE_JAVA_FORMAT | Fail ❌ | +| GROOVY | Fail ❌ | +| HTML | Fail ❌ | +| JAVA | Fail ❌ | +| JAVASCRIPT_ES | Fail ❌ | +| JAVASCRIPT_STANDARD | Fail ❌ | +| JSCPD | Fail ❌ | +| JSON | Fail ❌ | +| JSONC | Fail ❌ | +| JSX | Fail ❌ | +| KUBERNETES_KUBECONFORM | Fail ❌ | +| KOTLIN | Fail ❌ | +| LATEX | Fail ❌ | +| LUA | Fail ❌ | +| MARKDOWN | Fail ❌ | +| NATURAL_LANGUAGE | Fail ❌ | +| OPENAPI | Fail ❌ | +| PERL | Fail ❌ | +| PHP_BUILTIN | Fail ❌ | +| PHP_PHPCS | Fail ❌ | +| PHP_PHPSTAN | Fail ❌ | +| PHP_PSALM | Fail ❌ | +| POWERSHELL | Fail ❌ | +| PROTOBUF | Fail ❌ | +| PYTHON_BLACK | Fail ❌ | +| PYTHON_PYLINT | Fail ❌ | +| PYTHON_FLAKE8 | Fail ❌ | +| PYTHON_ISORT | Fail ❌ | +| PYTHON_MYPY | Fail ❌ | +| PYTHON_RUFF | Fail ❌ | +| R | Fail ❌ | +| RAKU | Fail ❌ | +| RENOVATE | Fail ❌ | +| RUBY | Fail ❌ | +| RUST_2015 | Fail ❌ | +| RUST_2018 | Fail ❌ | +| RUST_2021 | Fail ❌ | +| RUST_CLIPPY | Fail ❌ | +| SCALAFMT | Fail ❌ | +| SHELL_SHFMT | Fail ❌ | +| SNAKEMAKE_LINT | Fail ❌ | +| SNAKEMAKE_SNAKEFMT | Fail ❌ | +| STATES | Fail ❌ | +| SQL | Fail ❌ | +| SQLFLUFF | Fail ❌ | +| TEKTON | Fail ❌ | +| TERRAFORM_FMT | Fail ❌ | +| TERRAFORM_TFLINT | Fail ❌ | +| TERRAFORM_TERRASCAN | Fail ❌ | +| TERRAGRUNT | Fail ❌ | +| TSX | Fail ❌ | +| TYPESCRIPT_ES | Fail ❌ | +| TYPESCRIPT_STANDARD | Fail ❌ | +| XML | Fail ❌ | +| YAML | Fail ❌ | + + +Super-linter detected linting errors diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md new file mode 100644 index 00000000..2b0abd61 --- /dev/null +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-slim.md @@ -0,0 +1,78 @@ +# Super-linter summary + + +| Language | Validation result | +| -----------------------|-------------------| +| ANSIBLE | Pass ✅ | +| BASH | Pass ✅ | +| BASH_EXEC | Pass ✅ | +| CHECKOV | Pass ✅ | +| CLANG_FORMAT | Pass ✅ | +| CLOUDFORMATION | Pass ✅ | +| CLOJURE | Pass ✅ | +| COFFEESCRIPT | Pass ✅ | +| CPP | Pass ✅ | +| CSS | Pass ✅ | +| DART | Pass ✅ | +| DOCKERFILE_HADOLINT | Pass ✅ | +| EDITORCONFIG | Pass ✅ | +| ENV | Pass ✅ | +| GITHUB_ACTIONS | Pass ✅ | +| GITLEAKS | Pass ✅ | +| GHERKIN | Pass ✅ | +| GO | Pass ✅ | +| GO_MODULES | Pass ✅ | +| GO_RELEASER | Pass ✅ | +| GOOGLE_JAVA_FORMAT | Pass ✅ | +| GROOVY | Pass ✅ | +| HTML | Pass ✅ | +| JAVA | Pass ✅ | +| JAVASCRIPT_ES | Pass ✅ | +| JAVASCRIPT_STANDARD | Pass ✅ | +| JSCPD | Pass ✅ | +| JSON | Pass ✅ | +| JSONC | Pass ✅ | +| JSX | Pass ✅ | +| KUBERNETES_KUBECONFORM | Pass ✅ | +| KOTLIN | Pass ✅ | +| LATEX | Pass ✅ | +| LUA | Pass ✅ | +| MARKDOWN | Pass ✅ | +| NATURAL_LANGUAGE | Pass ✅ | +| OPENAPI | Pass ✅ | +| PERL | Pass ✅ | +| PHP_BUILTIN | Pass ✅ | +| PHP_PHPCS | Pass ✅ | +| PHP_PHPSTAN | Pass ✅ | +| PHP_PSALM | Pass ✅ | +| PROTOBUF | Pass ✅ | +| PYTHON_BLACK | Pass ✅ | +| PYTHON_PYLINT | Pass ✅ | +| PYTHON_FLAKE8 | Pass ✅ | +| PYTHON_ISORT | Pass ✅ | +| PYTHON_MYPY | Pass ✅ | +| PYTHON_RUFF | Pass ✅ | +| R | Pass ✅ | +| RAKU | Pass ✅ | +| RENOVATE | Pass ✅ | +| RUBY | Pass ✅ | +| SCALAFMT | Pass ✅ | +| SHELL_SHFMT | Pass ✅ | +| SNAKEMAKE_LINT | Pass ✅ | +| SNAKEMAKE_SNAKEFMT | Pass ✅ | +| STATES | Pass ✅ | +| SQL | Pass ✅ | +| SQLFLUFF | Pass ✅ | +| TEKTON | Pass ✅ | +| TERRAFORM_FMT | Pass ✅ | +| TERRAFORM_TFLINT | Pass ✅ | +| TERRAFORM_TERRASCAN | Pass ✅ | +| TERRAGRUNT | Pass ✅ | +| TSX | Pass ✅ | +| TYPESCRIPT_ES | Pass ✅ | +| TYPESCRIPT_STANDARD | Pass ✅ | +| XML | Pass ✅ | +| YAML | Pass ✅ | + + +All files and directories linted successfully diff --git a/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md new file mode 100644 index 00000000..2dabdd66 --- /dev/null +++ b/test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-standard.md @@ -0,0 +1,85 @@ +# Super-linter summary + + +| Language | Validation result | +| -----------------------|-------------------| +| ANSIBLE | Pass ✅ | +| ARM | Pass ✅ | +| BASH | Pass ✅ | +| BASH_EXEC | Pass ✅ | +| CHECKOV | Pass ✅ | +| CLANG_FORMAT | Pass ✅ | +| CLOUDFORMATION | Pass ✅ | +| CLOJURE | Pass ✅ | +| COFFEESCRIPT | Pass ✅ | +| CPP | Pass ✅ | +| CSHARP | Pass ✅ | +| CSS | Pass ✅ | +| DART | Pass ✅ | +| DOCKERFILE_HADOLINT | Pass ✅ | +| EDITORCONFIG | Pass ✅ | +| ENV | Pass ✅ | +| GITHUB_ACTIONS | Pass ✅ | +| GITLEAKS | Pass ✅ | +| GHERKIN | Pass ✅ | +| GO | Pass ✅ | +| GO_MODULES | Pass ✅ | +| GO_RELEASER | Pass ✅ | +| GOOGLE_JAVA_FORMAT | Pass ✅ | +| GROOVY | Pass ✅ | +| HTML | Pass ✅ | +| JAVA | Pass ✅ | +| JAVASCRIPT_ES | Pass ✅ | +| JAVASCRIPT_STANDARD | Pass ✅ | +| JSCPD | Pass ✅ | +| JSON | Pass ✅ | +| JSONC | Pass ✅ | +| JSX | Pass ✅ | +| KUBERNETES_KUBECONFORM | Pass ✅ | +| KOTLIN | Pass ✅ | +| LATEX | Pass ✅ | +| LUA | Pass ✅ | +| MARKDOWN | Pass ✅ | +| NATURAL_LANGUAGE | Pass ✅ | +| OPENAPI | Pass ✅ | +| PERL | Pass ✅ | +| PHP_BUILTIN | Pass ✅ | +| PHP_PHPCS | Pass ✅ | +| PHP_PHPSTAN | Pass ✅ | +| PHP_PSALM | Pass ✅ | +| POWERSHELL | Pass ✅ | +| PROTOBUF | Pass ✅ | +| PYTHON_BLACK | Pass ✅ | +| PYTHON_PYLINT | Pass ✅ | +| PYTHON_FLAKE8 | Pass ✅ | +| PYTHON_ISORT | Pass ✅ | +| PYTHON_MYPY | Pass ✅ | +| PYTHON_RUFF | Pass ✅ | +| R | Pass ✅ | +| RAKU | Pass ✅ | +| RENOVATE | Pass ✅ | +| RUBY | Pass ✅ | +| RUST_2015 | Pass ✅ | +| RUST_2018 | Pass ✅ | +| RUST_2021 | Pass ✅ | +| RUST_CLIPPY | Pass ✅ | +| SCALAFMT | Pass ✅ | +| SHELL_SHFMT | Pass ✅ | +| SNAKEMAKE_LINT | Pass ✅ | +| SNAKEMAKE_SNAKEFMT | Pass ✅ | +| STATES | Pass ✅ | +| SQL | Pass ✅ | +| SQLFLUFF | Pass ✅ | +| TEKTON | Pass ✅ | +| TERRAFORM_FMT | Pass ✅ | +| TERRAFORM_TFLINT | Pass ✅ | +| TERRAFORM_TERRASCAN | Pass ✅ | +| TERRAGRUNT | Pass ✅ | +| TSX | Pass ✅ | +| TYPESCRIPT_ES | Pass ✅ | +| TYPESCRIPT_STANDARD | Pass ✅ | +| XML | Pass ✅ | +| YAML | Pass ✅ | + + +All files and directories linted successfully diff --git a/test/lib/validationTest.sh b/test/lib/validationTest.sh index 5fc6f52c..3309a0df 100755 --- a/test/lib/validationTest.sh +++ b/test/lib/validationTest.sh @@ -148,7 +148,59 @@ function ValidateGitHubUrlsTest() { notice "${FUNCTION_NAME} PASS" } +function ValidateGitHubActionsStepSummaryTest() { + FUNCTION_NAME="${FUNCNAME[0]}" + + ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="false" + if ! ValidateGitHubActionsStepSummary; then + fatal "ValidateGitHubActionsStepSummary shouldn't fail when ENABLE_GITHUB_ACTIONS_STEP_SUMMARY is ${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" + else + info "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY} passed validation as expected" + fi + + ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true" + if ValidateGitHubActionsStepSummary; then + fatal "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY} should have failed validation when GITHUB_STEP_SUMMARY is not set" + else + info "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY} failed validation as expected" + fi + unset ENABLE_GITHUB_ACTIONS_STEP_SUMMARY + + ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true" + GITHUB_STEP_SUMMARY="/non/existing/file" + if ValidateGitHubActionsStepSummary; then + fatal "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}, GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY} should have failed validation when GITHUB_STEP_SUMMARY is set to a non-existing file" + else + info "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}, GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY} failed validation as expected" + fi + unset ENABLE_GITHUB_ACTIONS_STEP_SUMMARY + unset GITHUB_STEP_SUMMARY + + ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true" + GITHUB_STEP_SUMMARY="$(pwd)" + if ValidateGitHubActionsStepSummary; then + fatal "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}, GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY} should have failed validation when GITHUB_STEP_SUMMARY is set to a directory" + else + info "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}, GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY} failed validation as expected" + fi + unset ENABLE_GITHUB_ACTIONS_STEP_SUMMARY + unset GITHUB_STEP_SUMMARY + + ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true" + GITHUB_STEP_SUMMARY="${0}" + if ! ValidateGitHubActionsStepSummary; then + fatal "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}, GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY} should have passed validation when GITHUB_STEP_SUMMARY is set to a file" + else + info "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY=${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}, GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY} passed validation as expected" + fi + unset ENABLE_GITHUB_ACTIONS_STEP_SUMMARY + unset GITHUB_STEP_SUMMARY + + notice "${FUNCTION_NAME} PASS" +} + IsUnsignedIntegerSuccessTest IsUnsignedIntegerFailureTest ValidateDeprecatedVariablesTest ValidateGitHubUrlsTest +ValidateGitHubActionsStepSummaryTest diff --git a/test/run-super-linter-tests.sh b/test/run-super-linter-tests.sh index 541d46d1..b274a99d 100755 --- a/test/run-super-linter-tests.sh +++ b/test/run-super-linter-tests.sh @@ -6,6 +6,8 @@ set -o pipefail SUPER_LINTER_TEST_CONTAINER_URL="${1}" TEST_FUNCTION_NAME="${2}" +SUPER_LINTER_CONTAINER_IMAGE_TYPE="${3}" +echo "Super-linter container image type: ${SUPER_LINTER_CONTAINER_IMAGE_TYPE}" DEFAULT_BRANCH="main" @@ -23,11 +25,13 @@ run_test_cases_expect_failure() { configure_linters_for_test_cases COMMAND_TO_RUN+=(-e ANSIBLE_DIRECTORY="/test/linters/ansible/bad" -e CHECKOV_FILE_NAME=".checkov-test-linters-failure.yaml" -e FILTER_REGEX_INCLUDE=".*bad.*") EXPECTED_EXIT_CODE=1 + EXPECTED_SUPER_LINTER_STEP_SUMMARY_FILE_PATH="test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-${SUPER_LINTER_CONTAINER_IMAGE_TYPE}.md" } run_test_cases_expect_success() { configure_linters_for_test_cases COMMAND_TO_RUN+=(-e ANSIBLE_DIRECTORY="/test/linters/ansible/good" -e CHECKOV_FILE_NAME=".checkov-test-linters-success.yaml" -e FILTER_REGEX_INCLUDE=".*good.*") + EXPECTED_SUPER_LINTER_STEP_SUMMARY_FILE_PATH="test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-success-${SUPER_LINTER_CONTAINER_IMAGE_TYPE}.md" } run_test_cases_log_level() { @@ -114,6 +118,20 @@ COMMAND_TO_RUN+=(-e LOG_LEVEL="${LOG_LEVEL:-"DEBUG"}") COMMAND_TO_RUN+=(-e RUN_LOCAL="${RUN_LOCAL:-true}") COMMAND_TO_RUN+=(-e SAVE_SUPER_LINTER_OUTPUT="${SAVE_SUPER_LINTER_OUTPUT}") COMMAND_TO_RUN+=(-v "${SUPER_LINTER_WORKSPACE:-$(pwd)}:/tmp/lint") + +if [ -n "${EXPECTED_SUPER_LINTER_STEP_SUMMARY_FILE_PATH:-}" ]; then + echo "Expected Super-linter step summary file path: ${EXPECTED_SUPER_LINTER_STEP_SUMMARY_FILE_PATH}" + SUPER_LINTER_STEP_SUMMARY_FILE="$(pwd)/super-linter-github-actions-step-summary-output.md" + echo "Create Super-linter step summary file: ${SUPER_LINTER_STEP_SUMMARY_FILE}" + # Remove eventual leftovers from previous tests + rm --force "${SUPER_LINTER_STEP_SUMMARY_FILE}" + touch "${SUPER_LINTER_STEP_SUMMARY_FILE}" + SUPER_LINTER_STEP_SUMMARY_FILE_INSIDE_CONTAINER="/tmp/lint/$(basename "${SUPER_LINTER_STEP_SUMMARY_FILE}")" + COMMAND_TO_RUN+=(-e GITHUB_STEP_SUMMARY="${SUPER_LINTER_STEP_SUMMARY_FILE_INSIDE_CONTAINER}") + ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true" +fi +COMMAND_TO_RUN+=(-e ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY:-"false"}") + COMMAND_TO_RUN+=("${SUPER_LINTER_TEST_CONTAINER_URL}") declare -i EXPECTED_EXIT_CODE @@ -164,6 +182,18 @@ else echo "Super-linter output was not requested. SAVE_SUPER_LINTER_OUTPUT: ${SAVE_SUPER_LINTER_OUTPUT}" fi +if [ -n "${EXPECTED_SUPER_LINTER_STEP_SUMMARY_FILE_PATH:-}" ]; then + # Remove eventual HTML comments from the expected file because we use them to disable certain linter rules + if ! diff "${SUPER_LINTER_STEP_SUMMARY_FILE}" <(grep -vE '^\s*