Skip to content

Commit ef57e13

Browse files
authored
fix: avoid duplicated content in summary (#5939)
- Remove the previous summary file is present to avoid showing stale contents from old summaries. - Extract the logic to write summary heading and lines to dedicated functions in output.sh to make it easier adding new formats in the future.
1 parent 78ed3ef commit ef57e13

16 files changed

Lines changed: 193 additions & 19 deletions

‎Makefile‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ lint-codebase: ## Lint the entire codebase
238238
-e FILTER_REGEX_EXCLUDE=".*(/test/linters/|CHANGELOG.md).*" \
239239
-e GITLEAKS_CONFIG_FILE=".gitleaks-ignore-tests.toml" \
240240
-e RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES="default.json,hoge.json" \
241+
-e SAVE_SUPER_LINTER_SUMMARY=true \
241242
-e VALIDATE_ALL_CODEBASE=true \
242243
-v "$(CURDIR):/tmp/lint" \
243244
$(SUPER_LINTER_TEST_CONTAINER_URL)
@@ -280,7 +281,7 @@ lint-subset-files-enable-expensive-io-checks: ## Lint a small subset of files in
280281
$(SUPER_LINTER_TEST_CONTAINER_URL)
281282

282283
.PHONY: test-lib
283-
test-lib: test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation ## Test super-linter
284+
test-lib: test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output ## Test super-linter
284285

285286
.PHONY: test-build-file-list
286287
test-build-file-list: ## Test buildFileList
@@ -323,6 +324,14 @@ test-validation: ## Test validation
323324
--entrypoint /tmp/lint/test/lib/validationTest.sh \
324325
$(SUPER_LINTER_TEST_CONTAINER_URL)
325326

327+
.PHONY: test-output
328+
test-output: ## Test output
329+
docker run \
330+
-v "$(CURDIR):/tmp/lint" \
331+
-w /tmp/lint \
332+
--entrypoint /tmp/lint/test/lib/outputTest.sh \
333+
$(SUPER_LINTER_TEST_CONTAINER_URL)
334+
326335
# Run this test against a small directory because we're only interested in
327336
# loading default configuration files. The directory that we run super-linter
328337
# against should not be .github because that includes default linter rules.

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ The summary is in Markdown format. Super-linter supports the following formats:
476476

477477
- Table (default)
478478

479+
The summary output of previous Super-linter runs is not preserved.
480+
479481
### Super-linter outputs
480482

481483
If you set `SAVE_SUPER_LINTER_OUTPUT` to `true`, Super-linter saves its output

‎lib/functions/output.sh‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
WriteSummaryHeader() {
4+
local SUPER_LINTER_SUMMARY_OUTPUT_PATH="${1}"
5+
6+
{
7+
echo "# Super-linter summary"
8+
echo ""
9+
echo "| Language | Validation result |"
10+
echo "| -----------------------|-------------------|"
11+
} >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
12+
}
13+
14+
WriteSummaryLineSuccess() {
15+
local SUPER_LINTER_SUMMARY_OUTPUT_PATH="${1}"
16+
local LANGUAGE_NAME="${2}"
17+
echo "| ${LANGUAGE_NAME} | Pass ✅ |" >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
18+
}
19+
20+
WriteSummaryLineFailure() {
21+
local SUPER_LINTER_SUMMARY_OUTPUT_PATH="${1}"
22+
local LANGUAGE_NAME="${2}"
23+
echo "| ${LANGUAGE_NAME} | Fail ❌ |" >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
24+
}
25+
26+
WriteSummaryFooterSuccess() {
27+
local SUPER_LINTER_SUMMARY_OUTPUT_PATH="${1}"
28+
{
29+
echo ""
30+
echo "All files and directories linted successfully"
31+
} >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
32+
}
33+
34+
WriteSummaryFooterFailure() {
35+
local SUPER_LINTER_SUMMARY_OUTPUT_PATH="${1}"
36+
{
37+
echo ""
38+
echo "Super-linter detected linting errors"
39+
} >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
40+
}

‎lib/linter.sh‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ source /action/lib/functions/setupSSH.sh # Source the function script(s)
3131
source /action/lib/functions/githubEvent.sh
3232
# shellcheck source=/dev/null
3333
source /action/lib/functions/githubDomain.sh
34+
# shellcheck source=/dev/null
35+
source /action/lib/functions/output.sh
3436

3537
if ! ValidateGitHubUrls; then
3638
fatal "GitHub URLs failed validation"
@@ -565,12 +567,7 @@ Footer() {
565567

566568
if [[ "${SAVE_SUPER_LINTER_SUMMARY}" == "true" ]]; then
567569
debug "Saving Super-linter summary to ${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
568-
{
569-
echo "# Super-linter summary"
570-
echo ""
571-
echo "| Language | Validation result |"
572-
echo "| -----------------------|-------------------|"
573-
} >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
570+
WriteSummaryHeader "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
574571
fi
575572

576573
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
@@ -591,7 +588,7 @@ Footer() {
591588
error "Errors found in ${LANGUAGE}"
592589

593590
if [[ "${SAVE_SUPER_LINTER_SUMMARY}" == "true" ]]; then
594-
echo "| ${LANGUAGE} | Fail ❌ |" >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
591+
WriteSummaryLineFailure "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}" "${LANGUAGE}"
595592
fi
596593

597594
# Print output as error in case users disabled the INFO level so they
@@ -619,7 +616,7 @@ Footer() {
619616
elif [[ ${ERROR_COUNTER} -eq 0 ]]; then
620617
notice "Successfully linted ${LANGUAGE}"
621618
if [[ "${SAVE_SUPER_LINTER_SUMMARY}" == "true" ]]; then
622-
echo "| ${LANGUAGE} | Pass ✅ |" >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
619+
WriteSummaryLineSuccess "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}" "${LANGUAGE}"
623620
fi
624621
CallStatusAPI "${LANGUAGE}" "success"
625622
ANY_LINTER_SUCCESS="true"
@@ -641,18 +638,12 @@ Footer() {
641638
if [[ ${SUPER_LINTER_EXIT_CODE} -eq 0 ]]; then
642639
notice "All files and directories linted successfully"
643640
if [[ "${SAVE_SUPER_LINTER_SUMMARY}" == "true" ]]; then
644-
{
645-
echo ""
646-
echo "All files and directories linted successfully"
647-
} >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
641+
WriteSummaryFooterSuccess "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
648642
fi
649643
else
650644
error "Super-linter detected linting errors"
651645
if [[ "${SAVE_SUPER_LINTER_SUMMARY}" == "true" ]]; then
652-
{
653-
echo ""
654-
echo "Super-linter detected linting errors"
655-
} >>"${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
646+
WriteSummaryFooterFailure "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
656647
fi
657648
fi
658649

@@ -820,6 +811,9 @@ if [[ "${SAVE_SUPER_LINTER_OUTPUT}" = "true" ]] ||
820811
fi
821812

822813
if [[ "${SAVE_SUPER_LINTER_SUMMARY}" == "true" ]]; then
814+
debug "Remove eventual ${SUPER_LINTER_SUMMARY_OUTPUT_PATH} leftover"
815+
rm -f "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
816+
823817
debug "Ensuring that ${SUPER_LINTER_SUMMARY_OUTPUT_PATH} exists."
824818
if ! touch "${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"; then
825819
fatal "Cannot create Super-linter summary file: ${SUPER_LINTER_SUMMARY_OUTPUT_PATH}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- markdownlint-disable -->
2+
3+
Super-linter detected linting errors
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- markdownlint-disable -->
2+
3+
All files and directories linted successfully
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Super-linter summary
2+
3+
| Language | Validation result |
4+
| -----------------------|-------------------|
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable -->
2+
| Test Language | Fail ❌ |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- markdownlint-disable -->
2+
| Test Language | Pass ✅ |

test/data/github-actions-step-summary/expected-step-summary-test-linters-expect-failure-slim.md renamed to test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure-slim.md

File renamed without changes.

0 commit comments

Comments
 (0)