Skip to content

Commit 57c8658

Browse files
authored
feat: write github actions step summary (#5867)
This also removes an unneeded textlint configuration file because it matches with the default one. Close #5650
1 parent dd4313c commit 57c8658

12 files changed

Lines changed: 497 additions & 19 deletions

‎.github/linters/.textlintrc‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ test/linters/rust_clippy/**/target/**
9494
# Super-linter ouputs
9595
super-linter-output/
9696
custom-super-linter-output-directory-name/
97+
super-linter-github-actions-step-summary-output*

‎Makefile‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ test-custom-ssl-cert: ## Test the configuration of a custom SSL/TLS certificate
353353
test-non-default-home-directory: ## Test a non-default HOME directory
354354
$(CURDIR)/test/run-super-linter-tests.sh \
355355
$(SUPER_LINTER_TEST_CONTAINER_URL) \
356-
"run_test_cases_non_default_home"
356+
"run_test_cases_non_default_home" \
357+
"$(IMAGE)"
357358

358359
.PHONY: test-linters
359360
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
362363
test-linters-expect-success: ## Run the linters test suite expecting successes
363364
$(CURDIR)/test/run-super-linter-tests.sh \
364365
$(SUPER_LINTER_TEST_CONTAINER_URL) \
365-
"run_test_cases_expect_success"
366+
"run_test_cases_expect_success" \
367+
"$(IMAGE)"
366368

367369
.PHONY: test-linters-expect-failure
368370
test-linters-expect-failure: ## Run the linters test suite expecting failures
369371
$(CURDIR)/test/run-super-linter-tests.sh \
370372
$(SUPER_LINTER_TEST_CONTAINER_URL) \
371-
"run_test_cases_expect_failure"
373+
"run_test_cases_expect_failure" \
374+
"$(IMAGE)"
372375

373376
.PHONY: test-log-level
374377
test-log-level: ## Run a test to check if there are conflicts with the LOG_LEVEL variable
375378
$(CURDIR)/test/run-super-linter-tests.sh \
376379
$(SUPER_LINTER_TEST_CONTAINER_URL) \
377-
"run_test_cases_log_level"
380+
"run_test_cases_log_level" \
381+
"$(IMAGE)"
378382

379383
.PHONY: test-linters-expect-failure-log-level-notice
380384
test-linters-expect-failure-log-level-notice: ## Run the linters test suite expecting failures with a LOG_LEVEL set to NOTICE
381385
$(CURDIR)/test/run-super-linter-tests.sh \
382386
$(SUPER_LINTER_TEST_CONTAINER_URL) \
383-
"run_test_cases_expect_failure_notice_log"
387+
"run_test_cases_expect_failure_notice_log" \
388+
"$(IMAGE)"
384389

385390
.PHONY: test-bash-exec-library-expect-success
386391
test-bash-exec-library-expect-success: ## Run the linters test cases for BASH_EXEC expecting successes with BASH_EXEC_IGNORE_LIBRARIES set to true
387392
$(CURDIR)/test/run-super-linter-tests.sh \
388393
$(SUPER_LINTER_TEST_CONTAINER_URL) \
389-
"run_test_case_bash_exec_library_expect_success"
394+
"run_test_case_bash_exec_library_expect_success" \
395+
"$(IMAGE)"
390396

391397
.PHONY: test-bash-exec-library-expect-failure
392398
test-bash-exec-library-expect-failure: ## Run the linters test cases for BASH_EXEC expecting failures with BASH_EXEC_IGNORE_LIBRARIES set to true
393399
$(CURDIR)/test/run-super-linter-tests.sh \
394400
$(SUPER_LINTER_TEST_CONTAINER_URL) \
395-
"run_test_case_bash_exec_library_expect_failure"
401+
"run_test_case_bash_exec_library_expect_failure" \
402+
"$(IMAGE)"
396403

397404
.PHONY: test-git-initial-commit
398405
test-git-initial-commit: ## Run super-linter against a repository that only has one commit
399406
$(CURDIR)/test/run-super-linter-tests.sh \
400407
$(SUPER_LINTER_TEST_CONTAINER_URL) \
401-
"run_test_case_git_initial_commit"
408+
"run_test_case_git_initial_commit" \
409+
"$(IMAGE)"
402410

403411
.PHONY: test-use-find-and-ignore-gitignored-files
404412
test-use-find-and-ignore-gitignored-files: ## Run super-linter with USE_FIND_ALGORITHM=true and IGNORE_GITIGNORED_FILES=true
405413
$(CURDIR)/test/run-super-linter-tests.sh \
406414
$(SUPER_LINTER_TEST_CONTAINER_URL) \
407-
"run_test_case_use_find_and_ignore_gitignored_files"
415+
"run_test_case_use_find_and_ignore_gitignored_files" \
416+
"$(IMAGE)"
408417

409418
.PHONY: test-save-super-linter-output
410419
test-save-super-linter-output: ## Run super-linter with SAVE_SUPER_LINTER_OUTPUT=true
411420
$(CURDIR)/test/run-super-linter-tests.sh \
412421
$(SUPER_LINTER_TEST_CONTAINER_URL) \
413-
"run_test_cases_save_super_linter_output"
422+
"run_test_cases_save_super_linter_output" \
423+
"$(IMAGE)"
414424

415425
.PHONY: test-save-super-linter-output-custom-path
416426
test-save-super-linter-output-custom-path: ## Run super-linter with SAVE_SUPER_LINTER_OUTPUT=true and save output in a custom directory
417427
$(CURDIR)/test/run-super-linter-tests.sh \
418428
$(SUPER_LINTER_TEST_CONTAINER_URL) \
419-
"run_test_cases_save_super_linter_output_custom_path"
429+
"run_test_cases_save_super_linter_output_custom_path" \
430+
"$(IMAGE)"
420431

421432
.PHONY: docker-dev-container-build-check ## Run Docker build checks against the dev-container image
422433
docker-dev-container-build-check:

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ You can configure super-linter using the following environment variables:
204204
| **DOCKERFILE_HADOLINT_FILE_NAME** | `.hadolint.yaml` | Filename for [hadolint configuration](https://github.com/hadolint/hadolint) (ex: `.hadolintlintrc.yaml`) |
205205
| **EDITORCONFIG_FILE_NAME** | `.ecrc` | Filename for [editorconfig-checker configuration](https://github.com/editorconfig-checker/editorconfig-checker) |
206206
| **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). |
207+
| **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. |
207208
| **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. |
208209
| **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`. |
209210
| **GITHUB_ACTIONS_CONFIG_FILE** | `actionlint.yml` | Filename for [Actionlint configuration](https://github.com/rhysd/actionlint/blob/main/docs/config.md) (ex: `actionlint.yml`) |

‎lib/functions/validation.sh‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function ValidateBooleanConfigurationVariables() {
66
ValidateBooleanVariable "CREATE_LOG_FILE" "${CREATE_LOG_FILE}"
77
ValidateBooleanVariable "DISABLE_ERRORS" "${DISABLE_ERRORS}"
88
ValidateBooleanVariable "ENABLE_GITHUB_ACTIONS_GROUP_TITLE" "${ENABLE_GITHUB_ACTIONS_GROUP_TITLE}"
9+
ValidateBooleanVariable "ENABLE_GITHUB_ACTIONS_STEP_SUMMARY" "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}"
910
ValidateBooleanVariable "IGNORE_GENERATED_FILES" "${IGNORE_GENERATED_FILES}"
1011
ValidateBooleanVariable "IGNORE_GITIGNORED_FILES" "${IGNORE_GITIGNORED_FILES}"
1112
ValidateBooleanVariable "LOG_DEBUG" "${LOG_DEBUG}"
@@ -293,6 +294,27 @@ function ValidateGitHubUrls() {
293294
fi
294295
}
295296

297+
function ValidateGitHubActionsStepSummary() {
298+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY:-}" == "true" ]]; then
299+
debug "GitHub Actions step summary is enabled. ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: ${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}"
300+
if [[ -z "${GITHUB_STEP_SUMMARY:-}" ]]; then
301+
error "GITHUB_STEP_SUMMARY is not set."
302+
return 1
303+
fi
304+
debug "GITHUB_STEP_SUMMARY is set to: ${GITHUB_STEP_SUMMARY}"
305+
if [[ ! -e "${GITHUB_STEP_SUMMARY}" ]]; then
306+
error "GITHUB_STEP_SUMMARY (${GITHUB_STEP_SUMMARY}) doesn't exist."
307+
return 1
308+
fi
309+
if [[ ! -f "${GITHUB_STEP_SUMMARY}" ]]; then
310+
error "GITHUB_STEP_SUMMARY (${GITHUB_STEP_SUMMARY}) is not a file."
311+
return 1
312+
fi
313+
else
314+
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."
315+
fi
316+
}
317+
296318
function WarnIfVariableIsSet() {
297319
local INPUT_VARIABLE="${1}"
298320
shift

‎lib/linter.sh‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,24 @@ RUN_LOCAL="${RUN_LOCAL:-"false"}"
4747
# configure it.
4848
if [[ "${RUN_LOCAL}" == "true" ]]; then
4949
DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE="false"
50+
DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="false"
5051
else
5152
DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE="true"
53+
DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="true"
5254
fi
5355
# Let users configure GitHub Actions log markers regardless of running locally or not
5456
ENABLE_GITHUB_ACTIONS_GROUP_TITLE="${ENABLE_GITHUB_ACTIONS_GROUP_TITLE:-"${DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE}"}"
5557
export ENABLE_GITHUB_ACTIONS_GROUP_TITLE
5658

5759
startGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}"
5860

61+
# Let users configure GitHub Actions step summary regardless of running locally or not
62+
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY:-"${DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}"}"
63+
export ENABLE_GITHUB_ACTIONS_STEP_SUMMARY
64+
if ! ValidateGitHubActionsStepSummary; then
65+
fatal "GitHub Actions job summary configuration failed validation"
66+
fi
67+
5968
# We want a lowercase value
6069
declare -l BASH_EXEC_IGNORE_LIBRARIES
6170
BASH_EXEC_IGNORE_LIBRARIES="${BASH_EXEC_IGNORE_LIBRARIES:-false}"
@@ -591,6 +600,16 @@ Footer() {
591600
local SUPER_LINTER_EXIT_CODE
592601
SUPER_LINTER_EXIT_CODE=0
593602

603+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then
604+
debug "Saving GitHub Actions step summary to ${GITHUB_STEP_SUMMARY}"
605+
{
606+
echo "# Super-linter summary"
607+
echo ""
608+
echo "| Language | Validation result |"
609+
echo "| -----------------------|-------------------|"
610+
} >>"${GITHUB_STEP_SUMMARY}"
611+
fi
612+
594613
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
595614
# This used to be the count of errors found for a given LANGUAGE, but since
596615
# after we switched to running linters against a batch of files, it may not
@@ -607,6 +626,11 @@ Footer() {
607626

608627
if [[ ${ERROR_COUNTER} -ne 0 ]]; then
609628
error "Errors found in ${LANGUAGE}"
629+
630+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then
631+
echo "| ${LANGUAGE} | Fail ❌ |" >>"${GITHUB_STEP_SUMMARY}"
632+
fi
633+
610634
# Print output as error in case users disabled the INFO level so they
611635
# get feedback
612636
if [[ "${LOG_VERBOSE}" != "true" ]]; then
@@ -631,6 +655,9 @@ Footer() {
631655
debug "Setting super-linter exit code to ${SUPER_LINTER_EXIT_CODE} because there were errors for ${LANGUAGE}"
632656
elif [[ ${ERROR_COUNTER} -eq 0 ]]; then
633657
notice "Successfully linted ${LANGUAGE}"
658+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then
659+
echo "| ${LANGUAGE} | Pass ✅ |" >>"${GITHUB_STEP_SUMMARY}"
660+
fi
634661
CallStatusAPI "${LANGUAGE}" "success"
635662
ANY_LINTER_SUCCESS="true"
636663
debug "Set ANY_LINTER_SUCCESS to ${ANY_LINTER_SUCCESS} because ${LANGUAGE} reported a success"
@@ -650,8 +677,24 @@ Footer() {
650677

651678
if [[ ${SUPER_LINTER_EXIT_CODE} -eq 0 ]]; then
652679
notice "All files and directories linted successfully"
680+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then
681+
{
682+
echo ""
683+
echo "All files and directories linted successfully"
684+
} >>"${GITHUB_STEP_SUMMARY}"
685+
fi
653686
else
654687
error "Super-linter detected linting errors"
688+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then
689+
{
690+
echo ""
691+
echo "Super-linter detected linting errors"
692+
} >>"${GITHUB_STEP_SUMMARY}"
693+
fi
694+
fi
695+
696+
if [[ "${ENABLE_GITHUB_ACTIONS_STEP_SUMMARY}" == "true" ]]; then
697+
debug "GitHub Actions step summary file (${GITHUB_STEP_SUMMARY}) contents:\n$(cat "${GITHUB_STEP_SUMMARY}")"
655698
fi
656699

657700
exit ${SUPER_LINTER_EXIT_CODE}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Super-linter summary
2+
3+
<!-- textlint-disable terminology -->
4+
| Language | Validation result |
5+
| -----------------------|-------------------|
6+
| ANSIBLE | Fail ❌ |
7+
| BASH | Fail ❌ |
8+
| BASH_EXEC | Fail ❌ |
9+
| CHECKOV | Fail ❌ |
10+
| CLANG_FORMAT | Fail ❌ |
11+
| CLOUDFORMATION | Fail ❌ |
12+
| CLOJURE | Fail ❌ |
13+
| COFFEESCRIPT | Fail ❌ |
14+
| CPP | Fail ❌ |
15+
| CSS | Fail ❌ |
16+
| DART | Fail ❌ |
17+
| DOCKERFILE_HADOLINT | Fail ❌ |
18+
| EDITORCONFIG | Fail ❌ |
19+
| ENV | Fail ❌ |
20+
| GITHUB_ACTIONS | Fail ❌ |
21+
| GITLEAKS | Fail ❌ |
22+
| GHERKIN | Fail ❌ |
23+
| GO | Fail ❌ |
24+
| GO_MODULES | Fail ❌ |
25+
| GO_RELEASER | Fail ❌ |
26+
| GOOGLE_JAVA_FORMAT | Fail ❌ |
27+
| GROOVY | Fail ❌ |
28+
| HTML | Fail ❌ |
29+
| JAVA | Fail ❌ |
30+
| JAVASCRIPT_ES | Fail ❌ |
31+
| JAVASCRIPT_STANDARD | Fail ❌ |
32+
| JSCPD | Fail ❌ |
33+
| JSON | Fail ❌ |
34+
| JSONC | Fail ❌ |
35+
| JSX | Fail ❌ |
36+
| KUBERNETES_KUBECONFORM | Fail ❌ |
37+
| KOTLIN | Fail ❌ |
38+
| LATEX | Fail ❌ |
39+
| LUA | Fail ❌ |
40+
| MARKDOWN | Fail ❌ |
41+
| NATURAL_LANGUAGE | Fail ❌ |
42+
| OPENAPI | Fail ❌ |
43+
| PERL | Fail ❌ |
44+
| PHP_BUILTIN | Fail ❌ |
45+
| PHP_PHPCS | Fail ❌ |
46+
| PHP_PHPSTAN | Fail ❌ |
47+
| PHP_PSALM | Fail ❌ |
48+
| PROTOBUF | Fail ❌ |
49+
| PYTHON_BLACK | Fail ❌ |
50+
| PYTHON_PYLINT | Fail ❌ |
51+
| PYTHON_FLAKE8 | Fail ❌ |
52+
| PYTHON_ISORT | Fail ❌ |
53+
| PYTHON_MYPY | Fail ❌ |
54+
| PYTHON_RUFF | Fail ❌ |
55+
| R | Fail ❌ |
56+
| RAKU | Fail ❌ |
57+
| RENOVATE | Fail ❌ |
58+
| RUBY | Fail ❌ |
59+
| SCALAFMT | Fail ❌ |
60+
| SHELL_SHFMT | Fail ❌ |
61+
| SNAKEMAKE_LINT | Fail ❌ |
62+
| SNAKEMAKE_SNAKEFMT | Fail ❌ |
63+
| STATES | Fail ❌ |
64+
| SQL | Fail ❌ |
65+
| SQLFLUFF | Fail ❌ |
66+
| TEKTON | Fail ❌ |
67+
| TERRAFORM_FMT | Fail ❌ |
68+
| TERRAFORM_TFLINT | Fail ❌ |
69+
| TERRAFORM_TERRASCAN | Fail ❌ |
70+
| TERRAGRUNT | Fail ❌ |
71+
| TSX | Fail ❌ |
72+
| TYPESCRIPT_ES | Fail ❌ |
73+
| TYPESCRIPT_STANDARD | Fail ❌ |
74+
| XML | Fail ❌ |
75+
| YAML | Fail ❌ |
76+
<!-- textlint-enable terminology -->
77+
78+
Super-linter detected linting errors

0 commit comments

Comments
 (0)