From 581b93fb9c63e3c49a5472ba3d6f2fe5b8a0b333 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 17:11:08 +0800 Subject: [PATCH 01/47] add markdown link check Signed-off-by: Yanxuan Liu --- .github/workflows/markdown-link-check.yml | 30 +++++++++ markdown-link-check/action.yml | 74 +++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 .github/workflows/markdown-link-check.yml create mode 100644 markdown-link-check/action.yml diff --git a/.github/workflows/markdown-link-check.yml b/.github/workflows/markdown-link-check.yml new file mode 100644 index 0000000..2dedb7c --- /dev/null +++ b/.github/workflows/markdown-link-check.yml @@ -0,0 +1,30 @@ +# Copyright (c) 2025, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A workflow to check markdown links +name: markdown link check + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + markdown-link-check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: NVIDIA/spark-rapids-common/checkout@main + + - name: Run Markdown Link Check + uses: NVIDIA/spark-rapids-common/markdown-link-check@main diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml new file mode 100644 index 0000000..f414f1d --- /dev/null +++ b/markdown-link-check/action.yml @@ -0,0 +1,74 @@ +# Copyright (c) 2025, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: 'Markdown Link Check' +description: 'Check markdown links' + +runs: + using: "composite" + steps: + - name: Run markdown link check + uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + max-depth: -1 + use-verbose-mode: 'yes' + base-branch: 'gh-pages' + + - name: Summarize failed links + shell: bash + run: | + # Function to summarize failed links from the previous step output + summarize_failures() { + echo "" + echo "==========================================" + echo "FAILED LINKS SUMMARY" + echo "==========================================" + + # Get the output from the previous step (markdown link check) + # We'll parse the logs to find failed links + local failed_links=() + local failed_files=() + local total_failures=0 + + # Look for common failure patterns in the logs + # This will capture the output from the markdown-link-check action + if [ -f "$GITHUB_STEP_SUMMARY" ]; then + # Try to read from step summary if available + while IFS= read -r line; do + if [[ "$line" =~ โœ— ]] || [[ "$line" =~ ERROR ]] || [[ "$line" =~ FAIL ]] || [[ "$line" =~ "HTTP [^2]" ]]; then + failed_links+=("$line") + ((total_failures++)) + fi + done < "$GITHUB_STEP_SUMMARY" + fi + + # Also check for failures in the action output + # The markdown-link-check action typically outputs failures to stderr + if [ $total_failures -eq 0 ]; then + echo "Note: Detailed failure information should be visible in the markdown link check step above." + echo "Look for lines marked with โœ—, ERROR, FAIL, or non-200 HTTP status codes." + else + echo "Total failures found: $total_failures" + echo "" + echo "Failed links:" + printf ' %s\n' "${failed_links[@]}" + fi + + echo "" + echo "For detailed failure information, check the 'Run markdown link check' step above." + } + + # Run the summary + summarize_failures + \ No newline at end of file From 770c6f4a116cd65993cb38b16da679ecf5c11240 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 18:05:30 +0800 Subject: [PATCH 02/47] add step to analyze Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 73 +++++++++++++--------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index f414f1d..e85717e 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -24,51 +24,32 @@ runs: max-depth: -1 use-verbose-mode: 'yes' base-branch: 'gh-pages' - - - name: Summarize failed links - shell: bash + output-format: json + output-file: link-results.json + + - name: Show error links summary + if: always() run: | - # Function to summarize failed links from the previous step output - summarize_failures() { - echo "" - echo "==========================================" - echo "FAILED LINKS SUMMARY" - echo "==========================================" - - # Get the output from the previous step (markdown link check) - # We'll parse the logs to find failed links - local failed_links=() - local failed_files=() - local total_failures=0 - - # Look for common failure patterns in the logs - # This will capture the output from the markdown-link-check action - if [ -f "$GITHUB_STEP_SUMMARY" ]; then - # Try to read from step summary if available - while IFS= read -r line; do - if [[ "$line" =~ โœ— ]] || [[ "$line" =~ ERROR ]] || [[ "$line" =~ FAIL ]] || [[ "$line" =~ "HTTP [^2]" ]]; then - failed_links+=("$line") - ((total_failures++)) - fi - done < "$GITHUB_STEP_SUMMARY" - fi - - # Also check for failures in the action output - # The markdown-link-check action typically outputs failures to stderr - if [ $total_failures -eq 0 ]; then - echo "Note: Detailed failure information should be visible in the markdown link check step above." - echo "Look for lines marked with โœ—, ERROR, FAIL, or non-200 HTTP status codes." - else - echo "Total failures found: $total_failures" - echo "" - echo "Failed links:" - printf ' %s\n' "${failed_links[@]}" - fi - - echo "" - echo "For detailed failure information, check the 'Run markdown link check' step above." - } + echo -e "\n\n### Error Links Summary ###" + grep -B 1 '"status": [^2]' link-results.json | \ + awk ' + /"link":/ { + gsub(/^[ \t]+"link": "/, "", $0); + gsub(/",?$/, "", $0); + link = $0 + } + /"status":/ { + status = $2 + sub(/,/, "", status); + } + /"filename":/ { + gsub(/^[ \t]+"filename": "/, "", $0); + gsub(/",?$/, "", $0); + if (link != "" && status != "" && $0 != "") { + printf "[%s] %-60s => %s\n", status, link, $0 + link = ""; status = "" + } + } + ' | sort -u - # Run the summary - summarize_failures - \ No newline at end of file + echo "### Total broken links: $(grep -c '"status": [^2]' link-results.json)" \ No newline at end of file From b4a5fe4b7b49dc96198bf209a747f7257edabbe7 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 18:10:49 +0800 Subject: [PATCH 03/47] add shell Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index e85717e..1419d6a 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -29,6 +29,7 @@ runs: - name: Show error links summary if: always() + shell: bash run: | echo -e "\n\n### Error Links Summary ###" grep -B 1 '"status": [^2]' link-results.json | \ From 931304aca367a44f992b2a370d22ca98bfe8adfd Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 21:18:23 +0800 Subject: [PATCH 04/47] analyze Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 1419d6a..906dbab 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -19,38 +19,38 @@ runs: using: "composite" steps: - name: Run markdown link check + id: markdown-link-check uses: gaurav-nelson/github-action-markdown-link-check@v1 with: max-depth: -1 use-verbose-mode: 'yes' base-branch: 'gh-pages' - output-format: json - output-file: link-results.json - name: Show error links summary if: always() shell: bash run: | - echo -e "\n\n### Error Links Summary ###" - grep -B 1 '"status": [^2]' link-results.json | \ - awk ' - /"link":/ { - gsub(/^[ \t]+"link": "/, "", $0); - gsub(/",?$/, "", $0); - link = $0 + echo "${{ steps.markdown-link-check.outputs.result }}" > markdown-link-check.log + echo -e "\n\n### ๐Ÿ”ด Broken Links Summary ###" + grep -A 2 "ERROR:" link-check.log | awk ' + /FILE:/ { + filename = substr($0, 7) + next } - /"status":/ { - status = $2 - sub(/,/, "", status); + /\[โœ–\]/ { + link = $2 + next } - /"filename":/ { - gsub(/^[ \t]+"filename": "/, "", $0); - gsub(/",?$/, "", $0); - if (link != "" && status != "" && $0 != "") { - printf "[%s] %-60s => %s\n", status, link, $0 - link = ""; status = "" + /STATUS:/ { + status = $2 + if (link != "" && status != "" && filename != "") { + printf "[%s] %-50s => %s\n", status, link, filename } + link = ""; status = ""; filename = "" } ' | sort -u - echo "### Total broken links: $(grep -c '"status": [^2]' link-results.json)" \ No newline at end of file + count=$(grep -c "\[โœ–\]" link-check.log) + echo "### ๐Ÿ” Total broken links: ${count:-0}" + + rm -f link-check.log From f6f64488255af1a850cd70ba0e43519b35322e47 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 21:21:08 +0800 Subject: [PATCH 05/47] fix bug Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 906dbab..36afda1 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -32,7 +32,7 @@ runs: run: | echo "${{ steps.markdown-link-check.outputs.result }}" > markdown-link-check.log echo -e "\n\n### ๐Ÿ”ด Broken Links Summary ###" - grep -A 2 "ERROR:" link-check.log | awk ' + grep -A 2 "ERROR:" markdown-link-check.log | awk ' /FILE:/ { filename = substr($0, 7) next @@ -50,7 +50,7 @@ runs: } ' | sort -u - count=$(grep -c "\[โœ–\]" link-check.log) + count=$(grep -c "\[โœ–\]" markdown-link-check.log) echo "### ๐Ÿ” Total broken links: ${count:-0}" - rm -f link-check.log + rm -f markdown-link-check.log From f7a4f0dd5926c37816d8f489b6ba1e137d13c75b Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 21:33:34 +0800 Subject: [PATCH 06/47] fix issue Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 36afda1..0d030ca 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,7 +30,7 @@ runs: if: always() shell: bash run: | - echo "${{ steps.markdown-link-check.outputs.result }}" > markdown-link-check.log + echo "${{ steps.markdown-link-check.outputs.stdout }}" > markdown-link-check.log echo -e "\n\n### ๐Ÿ”ด Broken Links Summary ###" grep -A 2 "ERROR:" markdown-link-check.log | awk ' /FILE:/ { From 42a54d021294066e27c9602ed7c50906eff4e43d Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 21:46:53 +0800 Subject: [PATCH 07/47] fix issue Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 0d030ca..b3dabca 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,27 +30,33 @@ runs: if: always() shell: bash run: | - echo "${{ steps.markdown-link-check.outputs.stdout }}" > markdown-link-check.log + OUTPUT=$(grep -A 3 "ERROR:" "$GITHUB_STEP_SUMMARY" || true) + + if [ -z "$OUTPUT" ]; then + echo "โœ… All links are working" + exit 0 + fi + echo -e "\n\n### ๐Ÿ”ด Broken Links Summary ###" - grep -A 2 "ERROR:" markdown-link-check.log | awk ' - /FILE:/ { - filename = substr($0, 7) - next + echo "$OUTPUT" | awk ' + BEGIN { + link = ""; status = ""; file = "" } /\[โœ–\]/ { - link = $2 - next + gsub("\\[โœ–\\] ", "", $0) + link = $0 } /STATUS:/ { status = $2 - if (link != "" && status != "" && filename != "") { - printf "[%s] %-50s => %s\n", status, link, filename + } + /FILE:/ { + file = substr($0, 7) + if (link != "" && status != "" && file != "") { + printf "[%s] %-50s => %s\n", status, link, file + link = ""; status = ""; file = "" } - link = ""; status = ""; filename = "" } ' | sort -u - count=$(grep -c "\[โœ–\]" markdown-link-check.log) - echo "### ๐Ÿ” Total broken links: ${count:-0}" - - rm -f markdown-link-check.log + count=$(echo "$OUTPUT" | grep -c "\[โœ–\]") + echo "### ๐Ÿ” Total broken links: $count" \ No newline at end of file From 9960cf87e79b22a392db6b0d592718e9ef127072 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 22:38:15 +0800 Subject: [PATCH 08/47] fix Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 43 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index b3dabca..4e48c97 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -26,37 +26,26 @@ runs: use-verbose-mode: 'yes' base-branch: 'gh-pages' - - name: Show error links summary - if: always() + - name: Extract broken links + id: error-extractor shell: bash run: | - OUTPUT=$(grep -A 3 "ERROR:" "$GITHUB_STEP_SUMMARY" || true) - - if [ -z "$OUTPUT" ]; then - echo "โœ… All links are working" - exit 0 - fi + LOG=$(grep -A 1 -E 'FILE: |\[โœ–\]' "$GITHUB_STEP_SUMMARY" | grep -v '^--$') - echo -e "\n\n### ๐Ÿ”ด Broken Links Summary ###" - echo "$OUTPUT" | awk ' - BEGIN { - link = ""; status = ""; file = "" + echo "$LOG" | awk ' + /FILE: / { + file = $2 + next } /\[โœ–\]/ { - gsub("\\[โœ–\\] ", "", $0) - link = $0 + print file ": " $0 } - /STATUS:/ { - status = $2 - } - /FILE:/ { - file = substr($0, 7) - if (link != "" && status != "" && file != "") { - printf "[%s] %-50s => %s\n", status, link, file - link = ""; status = ""; file = "" - } - } - ' | sort -u + ' > broken_links.log + + echo "## ๐Ÿ“› Broken Links Report" >> $GITHUB_STEP_SUMMARY + echo "```" >> $GITHUB_STEP_SUMMARY + cat broken_links.log >> $GITHUB_STEP_SUMMARY + echo "```" >> $GITHUB_STEP_SUMMARY - count=$(echo "$OUTPUT" | grep -c "\[โœ–\]") - echo "### ๐Ÿ” Total broken links: $count" \ No newline at end of file + env: + GITHUB_STEP_SUMMARY: ${{ github.step_summary }} \ No newline at end of file From ac29eeb84eddcc28e9f6df877ee11b9bc7d15354 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 22:49:19 +0800 Subject: [PATCH 09/47] fix bug Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 4e48c97..029a629 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,9 +30,8 @@ runs: id: error-extractor shell: bash run: | - LOG=$(grep -A 1 -E 'FILE: |\[โœ–\]' "$GITHUB_STEP_SUMMARY" | grep -v '^--$') - - echo "$LOG" | awk ' + grep -A 1 'FILE: ' $GITHUB_STEP_SUMMARY | + awk ' /FILE: / { file = $2 next @@ -40,12 +39,14 @@ runs: /\[โœ–\]/ { print file ": " $0 } - ' > broken_links.log + ' | tee >(sed -e 's/^/ /' >> $GITHUB_STEP_SUMMARY) - echo "## ๐Ÿ“› Broken Links Report" >> $GITHUB_STEP_SUMMARY - echo "```" >> $GITHUB_STEP_SUMMARY - cat broken_links.log >> $GITHUB_STEP_SUMMARY - echo "```" >> $GITHUB_STEP_SUMMARY + if grep -q '\[โœ–\]' $GITHUB_STEP_SUMMARY; then + echo "## โŒ Broken Links Detected" | tee -a $GITHUB_STEP_SUMMARY + exit 1 + else + echo "## โœ… All Links Validated Successfully" | tee -a $GITHUB_STEP_SUMMARY + fi env: GITHUB_STEP_SUMMARY: ${{ github.step_summary }} \ No newline at end of file From 3bb1a08dd25d2296527773bf1d513925385dadcc Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 22:57:02 +0800 Subject: [PATCH 10/47] add if Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 029a629..e7c3369 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -28,6 +28,7 @@ runs: - name: Extract broken links id: error-extractor + if: ${{ always() }} shell: bash run: | grep -A 1 'FILE: ' $GITHUB_STEP_SUMMARY | From 6dcaa564bbefea16ed4fd357ea9803cdfd5d18dd Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 23:05:51 +0800 Subject: [PATCH 11/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index e7c3369..f0051da 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -31,23 +31,27 @@ runs: if: ${{ always() }} shell: bash run: | - grep -A 1 'FILE: ' $GITHUB_STEP_SUMMARY | - awk ' - /FILE: / { - file = $2 - next - } - /\[โœ–\]/ { - print file ": " $0 - } - ' | tee >(sed -e 's/^/ /' >> $GITHUB_STEP_SUMMARY) - - if grep -q '\[โœ–\]' $GITHUB_STEP_SUMMARY; then - echo "## โŒ Broken Links Detected" | tee -a $GITHUB_STEP_SUMMARY + if grep -q '\[โœ–\]' "$GITHUB_STEP_SUMMARY"; then + echo "## โŒ Broken Links Detected" + + awk ' + BEGIN { file = "unknown" } + /^FILE: / { + file = $2 + next + } + /\[โœ–\]/ { + print file ": " $0 + } + ' "$GITHUB_STEP_SUMMARY" | while IFS= read -r line; do + echo " $line" + done + + echo "Total broken links: $(grep -c '\[โœ–\]' "$GITHUB_STEP_SUMMARY")" exit 1 else - echo "## โœ… All Links Validated Successfully" | tee -a $GITHUB_STEP_SUMMARY + echo "## โœ… All Links Validated Successfully" + exit 0 fi - env: GITHUB_STEP_SUMMARY: ${{ github.step_summary }} \ No newline at end of file From a9cbb78b2db8c337a96570dfbef657bd8e976e45 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Fri, 15 Aug 2025 23:21:55 +0800 Subject: [PATCH 12/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index f0051da..0d02ec7 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -31,6 +31,10 @@ runs: if: ${{ always() }} shell: bash run: | + echo "GITHUB_STEP_SUMMARY path: $GITHUB_STEP_SUMMARY" + echo "--- START OF STEP SUMMARY CONTENT ---" + cat "$GITHUB_STEP_SUMMARY" + echo "--- END OF STEP SUMMARY CONTENT ---" if grep -q '\[โœ–\]' "$GITHUB_STEP_SUMMARY"; then echo "## โŒ Broken Links Detected" From dc4f61581aabc7bb78484d4b7af18b6de6b26f00 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 00:18:29 +0800 Subject: [PATCH 13/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 0d02ec7..e98fca0 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -31,10 +31,16 @@ runs: if: ${{ always() }} shell: bash run: | - echo "GITHUB_STEP_SUMMARY path: $GITHUB_STEP_SUMMARY" - echo "--- START OF STEP SUMMARY CONTENT ---" - cat "$GITHUB_STEP_SUMMARY" - echo "--- END OF STEP SUMMARY CONTENT ---" + LOG_URL="https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" + JOB_ID=$(curl -s -H "Authorization: Bearer ${{ github.token }}" "$LOG_URL" | jq -r '.jobs[] | select(.name == "${{ github.job }}") | .id') + LOG_URL="https://api.github.com/repos/${{ github.repository }}/actions/jobs/$JOB_ID/logs" + + curl -s -H "Authorization: Bearer ${{ github.token }}" -H "Accept: application/vnd.github.v3+json" "$LOG_URL" > full_log.txt + + sed -n '/> Run gaurav-nelson\/github-action-markdown-link-check@v1/,/^##\[endgroup\]/p' full_log.txt > mlc_output.log + + cat mlc_output.log + if grep -q '\[โœ–\]' "$GITHUB_STEP_SUMMARY"; then echo "## โŒ Broken Links Detected" From a09baa0959af3746a5614b658477739033895643 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 00:40:42 +0800 Subject: [PATCH 14/47] test Signed-off-by: Yanxuan Liu --- .github/workflows/markdown-link-check.yml | 2 + markdown-link-check/action.yml | 50 +++++++---------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/.github/workflows/markdown-link-check.yml b/.github/workflows/markdown-link-check.yml index 2dedb7c..1084d7e 100644 --- a/.github/workflows/markdown-link-check.yml +++ b/.github/workflows/markdown-link-check.yml @@ -21,6 +21,8 @@ on: jobs: markdown-link-check: + permissions: + actions: read runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index e98fca0..4e3e70b 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -26,42 +26,22 @@ runs: use-verbose-mode: 'yes' base-branch: 'gh-pages' - - name: Extract broken links - id: error-extractor - if: ${{ always() }} + - name: Capture and debug action logs shell: bash run: | - LOG_URL="https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" - JOB_ID=$(curl -s -H "Authorization: Bearer ${{ github.token }}" "$LOG_URL" | jq -r '.jobs[] | select(.name == "${{ github.job }}") | .id') - LOG_URL="https://api.github.com/repos/${{ github.repository }}/actions/jobs/$JOB_ID/logs" + LOG_CONTENT=$(curl -s -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token ${{ github.token }}" \ + "${{ github.server_url }}/repos/${{ github.repository }}/actions/jobs/${{ github.job }}/logs" \ + | awk '/^##\[group\]Run gaurav-nelson\/github-action-markdown-link-check/{flag=1;next}/##\[endgroup\]/{flag=0}flag') - curl -s -H "Authorization: Bearer ${{ github.token }}" -H "Accept: application/vnd.github.v3+json" "$LOG_URL" > full_log.txt + echo "### START OF CAPTURED LOG ###" + echo "$LOG_CONTENT" + echo "### END OF CAPTURED LOG ###" - sed -n '/> Run gaurav-nelson\/github-action-markdown-link-check@v1/,/^##\[endgroup\]/p' full_log.txt > mlc_output.log - - cat mlc_output.log - - if grep -q '\[โœ–\]' "$GITHUB_STEP_SUMMARY"; then - echo "## โŒ Broken Links Detected" - - awk ' - BEGIN { file = "unknown" } - /^FILE: / { - file = $2 - next - } - /\[โœ–\]/ { - print file ": " $0 - } - ' "$GITHUB_STEP_SUMMARY" | while IFS= read -r line; do - echo " $line" - done - - echo "Total broken links: $(grep -c '\[โœ–\]' "$GITHUB_STEP_SUMMARY")" - exit 1 - else - echo "## โœ… All Links Validated Successfully" - exit 0 - fi - env: - GITHUB_STEP_SUMMARY: ${{ github.step_summary }} \ No newline at end of file + LOG_LENGTH=${#LOG_CONTENT} + echo "Captured log length: $LOG_LENGTH characters" + + echo "LINK_CHECK_LOG<> $GITHUB_ENV + echo "$LOG_CONTENT" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + \ No newline at end of file From 67d121dfc1eb6a11ff107a138d81eec9e98f2bc9 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 00:42:52 +0800 Subject: [PATCH 15/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 4e3e70b..fb96c84 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -27,6 +27,7 @@ runs: base-branch: 'gh-pages' - name: Capture and debug action logs + if: always() shell: bash run: | LOG_CONTENT=$(curl -s -H "Accept: application/vnd.github.v3+json" \ From 2a0370b3435ec69ae4dea621adf8633ae804536a Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:02:50 +0800 Subject: [PATCH 16/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index fb96c84..16ff673 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -26,23 +26,25 @@ runs: use-verbose-mode: 'yes' base-branch: 'gh-pages' - - name: Capture and debug action logs - if: always() + - name: Capture logs via tee shell: bash run: | - LOG_CONTENT=$(curl -s -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${{ github.token }}" \ - "${{ github.server_url }}/repos/${{ github.repository }}/actions/jobs/${{ github.job }}/logs" \ - | awk '/^##\[group\]Run gaurav-nelson\/github-action-markdown-link-check/{flag=1;next}/##\[endgroup\]/{flag=0}flag') - - echo "### START OF CAPTURED LOG ###" - echo "$LOG_CONTENT" - echo "### END OF CAPTURED LOG ###" - - LOG_LENGTH=${#LOG_CONTENT} - echo "Captured log length: $LOG_LENGTH characters" + # ่ฟ่กŒๅŽŸๅง‹actionไฝ†้€š่ฟ‡teeๆ•่Žท่พ“ๅ‡บ + echo "::group::Markdown Link Check" + npx markdown-link-check@https://github.com/gaurav-nelson/github-action-markdown-link-check \ + --max-depth=${{ inputs.max-depth }} \ + --verbose=${{ inputs.use-verbose-mode }} \ + --base-branch=${{ inputs.base-branch }} \ + . 2>&1 | tee mlc.log + echo "::endgroup::" + # ไฟๅญ˜ๆ—ฅๅฟ— + LOG_CONTENT=$(cat mlc.log) echo "LINK_CHECK_LOG<> $GITHUB_ENV echo "$LOG_CONTENT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - \ No newline at end of file + + # ่ฐƒ่ฏ•่พ“ๅ‡บ + echo "### CAPTURED LOG (first 500 chars) ###" + echo "${LOG_CONTENT:0:500}" + echo "### END LOG PREVIEW ###" \ No newline at end of file From 3a6069fc97415336d136d2e33bbc1b8749cf888f Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:03:58 +0800 Subject: [PATCH 17/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 16ff673..5a3248c 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -27,6 +27,7 @@ runs: base-branch: 'gh-pages' - name: Capture logs via tee + if: always() shell: bash run: | # ่ฟ่กŒๅŽŸๅง‹actionไฝ†้€š่ฟ‡teeๆ•่Žท่พ“ๅ‡บ From 8e5e592324656f7f98097775ce70333c7b7a1912 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:09:02 +0800 Subject: [PATCH 18/47] change action Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 5a3248c..8e1d270 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -20,32 +20,8 @@ runs: steps: - name: Run markdown link check id: markdown-link-check - uses: gaurav-nelson/github-action-markdown-link-check@v1 + uses: tcort/github-action-markdown-link-check@v1 with: max-depth: -1 use-verbose-mode: 'yes' - base-branch: 'gh-pages' - - - name: Capture logs via tee - if: always() - shell: bash - run: | - # ่ฟ่กŒๅŽŸๅง‹actionไฝ†้€š่ฟ‡teeๆ•่Žท่พ“ๅ‡บ - echo "::group::Markdown Link Check" - npx markdown-link-check@https://github.com/gaurav-nelson/github-action-markdown-link-check \ - --max-depth=${{ inputs.max-depth }} \ - --verbose=${{ inputs.use-verbose-mode }} \ - --base-branch=${{ inputs.base-branch }} \ - . 2>&1 | tee mlc.log - echo "::endgroup::" - - # ไฟๅญ˜ๆ—ฅๅฟ— - LOG_CONTENT=$(cat mlc.log) - echo "LINK_CHECK_LOG<> $GITHUB_ENV - echo "$LOG_CONTENT" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - # ่ฐƒ่ฏ•่พ“ๅ‡บ - echo "### CAPTURED LOG (first 500 chars) ###" - echo "${LOG_CONTENT:0:500}" - echo "### END LOG PREVIEW ###" \ No newline at end of file + base-branch: 'gh-pages' \ No newline at end of file From 275d18888c16debc159dd9dfa9221277dbb07607 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:17:11 +0800 Subject: [PATCH 19/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 8e1d270..4523526 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -24,4 +24,21 @@ runs: with: max-depth: -1 use-verbose-mode: 'yes' - base-branch: 'gh-pages' \ No newline at end of file + base-branch: 'gh-pages' + + - name: Extract and print broken links + if: always() + shell: bash + run: | + OUTPUT="${{ steps.markdown-link-check.outputs.output }}" + echo "OUTPUT: $OUTPUT" + + if [ -z "$OUTPUT" ]; then + OUTPUT=$(grep -E '^::|^\s*\[' "$GITHUB_STEP_SUMMARY" || true) + fi + + echo "### Broken Links Found" >> $GITHUB_STEP_SUMMARY + echo "$OUTPUT" | grep -E '\[โœ–\]|ERROR:' >> $GITHUB_STEP_SUMMARY || echo "No broken links found" + + echo "Extracted broken links:" + echo "$OUTPUT" | grep -E '\[โœ–\]|ERROR:' || echo "No broken links found" \ No newline at end of file From 6065396d32ae44f80798afd5e3a72a9e8fda7645 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:36:00 +0800 Subject: [PATCH 20/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 41 +++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 4523526..7cf6e69 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -25,20 +25,35 @@ runs: max-depth: -1 use-verbose-mode: 'yes' base-branch: 'gh-pages' - + shell: bash + run: | + echo "::group::Markdown Link Check Output" + npx markdown-link-check@latest **/*.md --verbose 2>&1 | tee link-check.log + echo "::endgroup::" + echo "exit_code=$?" >> $GITHUB_OUTPUT + - name: Extract and print broken links if: always() shell: bash run: | - OUTPUT="${{ steps.markdown-link-check.outputs.output }}" - echo "OUTPUT: $OUTPUT" - - if [ -z "$OUTPUT" ]; then - OUTPUT=$(grep -E '^::|^\s*\[' "$GITHUB_STEP_SUMMARY" || true) - fi - - echo "### Broken Links Found" >> $GITHUB_STEP_SUMMARY - echo "$OUTPUT" | grep -E '\[โœ–\]|ERROR:' >> $GITHUB_STEP_SUMMARY || echo "No broken links found" - - echo "Extracted broken links:" - echo "$OUTPUT" | grep -E '\[โœ–\]|ERROR:' || echo "No broken links found" \ No newline at end of file + cat link-check.log + if [ "${{ steps.markdown-link-check.outputs.exit_code }}" != "0" ]; then + echo "Link check found errors. Parsing log..." + ERRORS=$(grep -E '\[โœ–\]|ERROR:' link-check.log || true) + + if [ -n "$ERRORS" ]; then + echo "### โŒ Broken Links Found" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + echo "$ERRORS" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + echo "Found broken links:" + echo "$ERRORS" + exit 1 # ไฝฟๆญฅ้ชคๅคฑ่ดฅ + else + echo "Link check failed but no broken links detected." + echo "Check full log for network issues." + fi + else + echo "### โœ… All links are valid" >> $GITHUB_STEP_SUMMARY + echo "No broken links found" + fi \ No newline at end of file From 5e5e94f1eb905ead35b8982b9098ec622a89e987 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:37:36 +0800 Subject: [PATCH 21/47] fix bug Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 7cf6e69..c1b83a2 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -25,7 +25,7 @@ runs: max-depth: -1 use-verbose-mode: 'yes' base-branch: 'gh-pages' - shell: bash + shell: bash run: | echo "::group::Markdown Link Check Output" npx markdown-link-check@latest **/*.md --verbose 2>&1 | tee link-check.log From 2b4999d8e6e81552386657bb992e2f4d97c17713 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:45:08 +0800 Subject: [PATCH 22/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 35 ++++------------------------------ 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index c1b83a2..cb3f05a 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -25,35 +25,8 @@ runs: max-depth: -1 use-verbose-mode: 'yes' base-branch: 'gh-pages' - shell: bash + + - name: Save output run: | - echo "::group::Markdown Link Check Output" - npx markdown-link-check@latest **/*.md --verbose 2>&1 | tee link-check.log - echo "::endgroup::" - echo "exit_code=$?" >> $GITHUB_OUTPUT - - - name: Extract and print broken links - if: always() - shell: bash - run: | - cat link-check.log - if [ "${{ steps.markdown-link-check.outputs.exit_code }}" != "0" ]; then - echo "Link check found errors. Parsing log..." - ERRORS=$(grep -E '\[โœ–\]|ERROR:' link-check.log || true) - - if [ -n "$ERRORS" ]; then - echo "### โŒ Broken Links Found" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - echo "$ERRORS" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - echo "Found broken links:" - echo "$ERRORS" - exit 1 # ไฝฟๆญฅ้ชคๅคฑ่ดฅ - else - echo "Link check failed but no broken links detected." - echo "Check full log for network issues." - fi - else - echo "### โœ… All links are valid" >> $GITHUB_STEP_SUMMARY - echo "No broken links found" - fi \ No newline at end of file + echo "LINK_CHECK_OUTPUT=${{ steps.markdown-link-check.outputs.log }}" >> $GITHUB_ENV + shell: bash \ No newline at end of file From 783ba8cc8786f87a35b05af0d932596a0919ed56 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:47:25 +0800 Subject: [PATCH 23/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index cb3f05a..56b17ba 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -27,6 +27,7 @@ runs: base-branch: 'gh-pages' - name: Save output + shell: bash + if: always() run: | echo "LINK_CHECK_OUTPUT=${{ steps.markdown-link-check.outputs.log }}" >> $GITHUB_ENV - shell: bash \ No newline at end of file From 7f373c168ae586e4315e8a2c5aa056a49541f12b Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 01:50:32 +0800 Subject: [PATCH 24/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 56b17ba..57e0257 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,4 +30,6 @@ runs: shell: bash if: always() run: | - echo "LINK_CHECK_OUTPUT=${{ steps.markdown-link-check.outputs.log }}" >> $GITHUB_ENV + echo "========= test start ==========" + echo "$MLC_OUTPUT" + echo "========= test end ==========" \ No newline at end of file From e7ea568f101bf5317a5876f8553910a844895c42 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Sat, 16 Aug 2025 02:03:44 +0800 Subject: [PATCH 25/47] add step Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 57e0257..7b0e122 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -26,10 +26,30 @@ runs: use-verbose-mode: 'yes' base-branch: 'gh-pages' - - name: Save output + - name: Summarize results shell: bash if: always() run: | - echo "========= test start ==========" - echo "$MLC_OUTPUT" - echo "========= test end ==========" \ No newline at end of file + if grep -q 'ERROR:' <<< "$MLC_OUTPUT"; then + echo "Found broken links:" + echo "-------------------------------" + + echo "$MLC_OUTPUT" | grep -E '(FILE:|ERROR:)' | while read -r line; do + if [[ $line == FILE:* ]]; then + current_file="${line#FILE: }" + elif [[ $line == *ERROR:* ]]; then + link=$(echo "$line" | sed -E 's/.*https?:\/\/[^ ]+//; s/ .*//') + status=$(echo "$line" | grep -oE 'status: [0-9]+' | cut -d' ' -f2) + + printf "%s\n%s\n%s\n\n" \ + "$current_file" \ + "$link" \ + "Status: $status" + fi + done + + echo "-------------------------------" + exit 1 + else + echo "All links are valid" + fi \ No newline at end of file From fa63b89c31cb619d48644aa46dae07277b0b4e6a Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 00:18:16 +0800 Subject: [PATCH 26/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 7b0e122..6fbd9a7 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,26 +30,28 @@ runs: shell: bash if: always() run: | - if grep -q 'ERROR:' <<< "$MLC_OUTPUT"; then - echo "Found broken links:" - echo "-------------------------------" + if grep -q '\[โœ–\]' <<< "$MLC_OUTPUT"; then + echo "##Error found:" + echo "========================================" - echo "$MLC_OUTPUT" | grep -E '(FILE:|ERROR:)' | while read -r line; do - if [[ $line == FILE:* ]]; then + current_file="" + + echo "$MLC_OUTPUT" | while IFS= read -r line; do + if [[ "$line" == FILE:* ]]; then current_file="${line#FILE: }" - elif [[ $line == *ERROR:* ]]; then - link=$(echo "$line" | sed -E 's/.*https?:\/\/[^ ]+//; s/ .*//') - status=$(echo "$line" | grep -oE 'status: [0-9]+' | cut -d' ' -f2) + elif [[ "$line" == *'[โœ–]'* ]]; then + link=$(echo "$line" | grep -o 'https\?://[^ ]*' | head -1) + status=$(echo "$line" | grep -o 'Status: [0-9]\+' | cut -d' ' -f2) - printf "%s\n%s\n%s\n\n" \ - "$current_file" \ - "$link" \ - "Status: $status" + echo "๐Ÿ“„ File: $current_file" + echo "๐Ÿ”— Link: $link" + echo "๐Ÿ›‘ Status: $status" + echo "----------------------------------------" fi done - echo "-------------------------------" + echo "========================================" exit 1 else - echo "All links are valid" + echo "โœ… All links are valid" fi \ No newline at end of file From f7920c7e99f20523b0b5aafa59e13fbabb035704 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 00:27:37 +0800 Subject: [PATCH 27/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 6fbd9a7..919cef2 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,27 +30,33 @@ runs: shell: bash if: always() run: | - if grep -q '\[โœ–\]' <<< "$MLC_OUTPUT"; then - echo "##Error found:" + output=$(cat "$GITHUB_STEP_SUMMARY" 2>/dev/null || echo "$MLC_OUTPUT") + + if grep -q '\[โœ–\]' <<< "$output"; then + echo "##[error]Found broken links:" echo "========================================" current_file="" + error_count=0 - echo "$MLC_OUTPUT" | while IFS= read -r line; do - if [[ "$line" == FILE:* ]]; then - current_file="${line#FILE: }" - elif [[ "$line" == *'[โœ–]'* ]]; then - link=$(echo "$line" | grep -o 'https\?://[^ ]*' | head -1) - status=$(echo "$line" | grep -o 'Status: [0-9]\+' | cut -d' ' -f2) + while IFS= read -r line; do + if [[ "$line" =~ ^FILE:\ (.+) ]]; then + current_file="${BASH_REMATCH[1]}" + elif [[ "$line" =~ \[โœ–\]\ (.+)\ โ†’\ Status:\ ([0-9]+) ]]; then + ((error_count++)) + link="${BASH_REMATCH[1]}" + status="${BASH_REMATCH[2]}" echo "๐Ÿ“„ File: $current_file" echo "๐Ÿ”— Link: $link" echo "๐Ÿ›‘ Status: $status" echo "----------------------------------------" fi - done + done <<< "$output" echo "========================================" + echo "##[error]Found $error_count broken links" + exit 1 else echo "โœ… All links are valid" From ebef3e9bc9446c4352d3f841e6b3f671c3f419a5 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 00:32:31 +0800 Subject: [PATCH 28/47] fix bug Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 919cef2..785a657 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,7 +30,7 @@ runs: shell: bash if: always() run: | - output=$(cat "$GITHUB_STEP_SUMMARY" 2>/dev/null || echo "$MLC_OUTPUT") + output=$(echo "$MLC_OUTPUT") if grep -q '\[โœ–\]' <<< "$output"; then echo "##[error]Found broken links:" From b9a035a5032af85c03c94c6b675bb3b58dd5a2f0 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 00:50:04 +0800 Subject: [PATCH 29/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 785a657..0cb5489 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -32,28 +32,41 @@ runs: run: | output=$(echo "$MLC_OUTPUT") - if grep -q '\[โœ–\]' <<< "$output"; then + if echo "$output" | grep -q '\[โœ–\]'; then echo "##[error]Found broken links:" echo "========================================" current_file="" error_count=0 + in_error_block=false + error_description="" while IFS= read -r line; do if [[ "$line" =~ ^FILE:\ (.+) ]]; then current_file="${BASH_REMATCH[1]}" + in_error_block=false elif [[ "$line" =~ \[โœ–\]\ (.+)\ โ†’\ Status:\ ([0-9]+) ]]; then ((error_count++)) link="${BASH_REMATCH[1]}" status="${BASH_REMATCH[2]}" + in_error_block=true + + error_description=$(echo "$line" | sed -E 's/.*Status: [0-9]+ //') echo "๐Ÿ“„ File: $current_file" echo "๐Ÿ”— Link: $link" echo "๐Ÿ›‘ Status: $status" - echo "----------------------------------------" + echo "๐Ÿ“ Error description:" + elif $in_error_block; then + if [[ "$line" =~ ^\ *$ ]] || [[ "$line" =~ ^[^\ ] ]]; then + in_error_block=false + else + echo " $line" + fi fi done <<< "$output" + echo "----------------------------------------" echo "========================================" echo "##[error]Found $error_count broken links" From 8fb4f6f6fa9cd2bd3ad5da0c54c7cc5d9f816c45 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 01:03:54 +0800 Subject: [PATCH 30/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 46 ++-------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 0cb5489..144526b 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,47 +30,5 @@ runs: shell: bash if: always() run: | - output=$(echo "$MLC_OUTPUT") - - if echo "$output" | grep -q '\[โœ–\]'; then - echo "##[error]Found broken links:" - echo "========================================" - - current_file="" - error_count=0 - in_error_block=false - error_description="" - - while IFS= read -r line; do - if [[ "$line" =~ ^FILE:\ (.+) ]]; then - current_file="${BASH_REMATCH[1]}" - in_error_block=false - elif [[ "$line" =~ \[โœ–\]\ (.+)\ โ†’\ Status:\ ([0-9]+) ]]; then - ((error_count++)) - link="${BASH_REMATCH[1]}" - status="${BASH_REMATCH[2]}" - in_error_block=true - - error_description=$(echo "$line" | sed -E 's/.*Status: [0-9]+ //') - - echo "๐Ÿ“„ File: $current_file" - echo "๐Ÿ”— Link: $link" - echo "๐Ÿ›‘ Status: $status" - echo "๐Ÿ“ Error description:" - elif $in_error_block; then - if [[ "$line" =~ ^\ *$ ]] || [[ "$line" =~ ^[^\ ] ]]; then - in_error_block=false - else - echo " $line" - fi - fi - done <<< "$output" - - echo "----------------------------------------" - echo "========================================" - echo "##[error]Found $error_count broken links" - - exit 1 - else - echo "โœ… All links are valid" - fi \ No newline at end of file + output="$MLC_OUTPUT" + echo "$output" \ No newline at end of file From ea4d94e929f999693648479413ae49bcdfce0697 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 01:20:14 +0800 Subject: [PATCH 31/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 144526b..bc3c9c8 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,5 +30,44 @@ runs: shell: bash if: always() run: | - output="$MLC_OUTPUT" - echo "$output" \ No newline at end of file + { + has_error=0 + current_file="" + broken_links=() + + function output_broken_links() { + if [ ${#broken_links[@]} -gt 0 ]; then + has_error=1 + echo "File: $current_file" + for link_info in "${broken_links[@]}"; do + echo " Broken link: $link_info" + done + echo "" + fi + } + + while IFS= read -r line; do + if [[ $line =~ ^[[:space:]]*FILE:[[:space:]]*(.+) ]]; then + filename="${BASH_REMATCH[1]}" + if [ -n "$current_file" ]; then + output_broken_links + fi + current_file="$filename" + broken_links=() + elif [[ $line =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then + url="${BASH_REMATCH[1]}" + status="${BASH_REMATCH[2]}" + broken_links+=("$url (Status: $status)") + fi + done <<< "$MLC_OUTPUT" + + if [ -n "$current_file" ]; then + output_broken_links + fi + + if [ $has_error -eq 0 ]; then + echo "All links are good!" + else + echo "Found broken links in the above files" + fi + } || true From 53084eae34a3848ab3fe8c36d5224370844076d8 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 01:26:32 +0800 Subject: [PATCH 32/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 74 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index bc3c9c8..3839eb7 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,44 +30,42 @@ runs: shell: bash if: always() run: | - { - has_error=0 - current_file="" - broken_links=() - - function output_broken_links() { - if [ ${#broken_links[@]} -gt 0 ]; then - has_error=1 - echo "File: $current_file" - for link_info in "${broken_links[@]}"; do - echo " Broken link: $link_info" - done - echo "" - fi - } - - while IFS= read -r line; do - if [[ $line =~ ^[[:space:]]*FILE:[[:space:]]*(.+) ]]; then - filename="${BASH_REMATCH[1]}" - if [ -n "$current_file" ]; then - output_broken_links - fi - current_file="$filename" - broken_links=() - elif [[ $line =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then - url="${BASH_REMATCH[1]}" - status="${BASH_REMATCH[2]}" - broken_links+=("$url (Status: $status)") - fi - done <<< "$MLC_OUTPUT" - - if [ -n "$current_file" ]; then - output_broken_links + has_errors=0 + current_file="" + broken_links=() + + function print_broken_links() { + if [ ${#broken_links[@]} -gt 0 ]; then + has_errors=1 + echo "File: $current_file" + for link_info in "${broken_links[@]}"; do + echo " Broken link: $link_info" + done + echo "" fi + broken_links=() + } + + while IFS= read -r line; do + if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then + if [ -n "$current_file" ]; then + print_broken_links + fi + current_file="${BASH_REMATCH[1]}" - if [ $has_error -eq 0 ]; then - echo "All links are good!" - else - echo "Found broken links in the above files" + elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then + url="${BASH_REMATCH[1]}" + status="${BASH_REMATCH[2]}" + broken_links+=("$url (Status: $status)") fi - } || true + done <<< "$MLC_OUTPUT" + + if [ -n "$current_file" ]; then + print_broken_links + fi + + if [ $has_errors -eq 0 ]; then + echo "โœ… All links are valid" + else + echo "โŒ Found broken links in the above files" + fi \ No newline at end of file From 480b0d6dc7b645920cd253df81e6cc983c1c6ff7 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 09:05:30 +0800 Subject: [PATCH 33/47] optimize output Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 55 +++++++++++++++------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 3839eb7..a694c9d 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -32,40 +32,33 @@ runs: run: | has_errors=0 current_file="" - broken_links=() - - function print_broken_links() { - if [ ${#broken_links[@]} -gt 0 ]; then - has_errors=1 - echo "File: $current_file" - for link_info in "${broken_links[@]}"; do - echo " Broken link: $link_info" - done - echo "" - fi - broken_links=() - } + declare -A broken_links_map while IFS= read -r line; do - if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then - if [ -n "$current_file" ]; then - print_broken_links + if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then + current_file="${BASH_REMATCH[1]}" + broken_links_map[$current_file]="" + + elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then + url="${BASH_REMATCH[1]}" + status="${BASH_REMATCH[2]}" + if [ -n "$current_file" ]; then + broken_links_map[$current_file]+=" $url (Status: $status)"$'\n' + has_errors=1 + fi fi - current_file="${BASH_REMATCH[1]}" - - elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then - url="${BASH_REMATCH[1]}" - status="${BASH_REMATCH[2]}" - broken_links+=("$url (Status: $status)") - fi done <<< "$MLC_OUTPUT" - if [ -n "$current_file" ]; then - print_broken_links - fi - if [ $has_errors -eq 0 ]; then - echo "โœ… All links are valid" - else - echo "โŒ Found broken links in the above files" - fi \ No newline at end of file + echo "=========== All links are valid ===========" + else + echo "=========== Found errors: ===========" + + for file in "${!broken_links_map[@]}"; do + links="${broken_links_map[$file]}" + if [ -n "$links" ]; then + echo "File: $file" + echo "$links" + fi + done + fi From 8dea0c1398623bab069757c9151cef2b62946083 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 09:16:25 +0800 Subject: [PATCH 34/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index a694c9d..16ec7cd 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -33,32 +33,46 @@ runs: has_errors=0 current_file="" declare -A broken_links_map + declare -A current_file_links while IFS= read -r line; do if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then + if [ -n "$current_file" ]; then + if [ ${#current_file_links[@]} -gt 0 ]; then + broken_links_map[$current_file]="${current_file_links[*]}" + fi + fi + current_file="${BASH_REMATCH[1]}" - broken_links_map[$current_file]="" + unset current_file_links + declare -A current_file_links elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then url="${BASH_REMATCH[1]}" status="${BASH_REMATCH[2]}" + link_str="$url (Status: $status)" + if [ -n "$current_file" ]; then - broken_links_map[$current_file]+=" $url (Status: $status)"$'\n' + current_file_links["$link_str"]=1 has_errors=1 fi fi done <<< "$MLC_OUTPUT" + if [ -n "$current_file" ] && [ ${#current_file_links[@]} -gt 0 ]; then + broken_links_map[$current_file]="${!current_file_links[*]}" + fi + if [ $has_errors -eq 0 ]; then echo "=========== All links are valid ===========" - else - echo "=========== Found errors: ===========" + else + echo "=========== Found broken links ===========" for file in "${!broken_links_map[@]}"; do - links="${broken_links_map[$file]}" - if [ -n "$links" ]; then - echo "File: $file" - echo "$links" - fi + IFS=' ' read -ra links <<< "${broken_links_map[$file]}" + + echo "File: $file" + printf " %s\n" "${links[@]}" | sort + echo done - fi + fi \ No newline at end of file From 1f0c60cafe5944f2f5124c848deae2d0ba41ba73 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 11:43:54 +0800 Subject: [PATCH 35/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 54 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 16ec7cd..e2185b6 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -32,20 +32,13 @@ runs: run: | has_errors=0 current_file="" - declare -A broken_links_map - declare -A current_file_links + files=() + all_links=() while IFS= read -r line; do if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then - if [ -n "$current_file" ]; then - if [ ${#current_file_links[@]} -gt 0 ]; then - broken_links_map[$current_file]="${current_file_links[*]}" - fi - fi - current_file="${BASH_REMATCH[1]}" - unset current_file_links - declare -A current_file_links + files+=("$current_file") elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then url="${BASH_REMATCH[1]}" @@ -53,26 +46,41 @@ runs: link_str="$url (Status: $status)" if [ -n "$current_file" ]; then - current_file_links["$link_str"]=1 + all_links+=("${current_file}|${link_str}") has_errors=1 fi fi done <<< "$MLC_OUTPUT" - if [ -n "$current_file" ] && [ ${#current_file_links[@]} -gt 0 ]; then - broken_links_map[$current_file]="${!current_file_links[*]}" + # ่พ“ๅ‡บ็ป“่ฎบ + if [ $has_errors -eq 0 ]; then + echo "All links are valid" + exit 0 fi - if [ $has_errors -eq 0 ]; then - echo "=========== All links are valid ===========" - else - echo "=========== Found broken links ===========" + echo "Found broken links" + echo + echo "===== DETAILS =====" + + unique_files=($(printf "%s\n" "${files[@]}" | sort -u)) + + unique_links=($(printf "%s\n" "${all_links[@]}" | sort -u)) + + for file in "${unique_files[@]}"; do + file_links=() + for link in "${unique_links[@]}"; do + if [[ "$link" == "${file}|"* ]]; then + link_only="${link#*|}" + file_links+=("$link_only") + fi + done - for file in "${!broken_links_map[@]}"; do - IFS=' ' read -ra links <<< "${broken_links_map[$file]}" - + if [ ${#file_links[@]} -gt 0 ]; then echo "File: $file" - printf " %s\n" "${links[@]}" | sort + + printf " %s\n" "${file_links[@]}" | sort -u + + echo " โ†’ Found ${#file_links[@]} broken link(s)" echo - done - fi \ No newline at end of file + fi + done \ No newline at end of file From 04477d03aeb097e4e6242ab683e6a6f74506d214 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 11:54:59 +0800 Subject: [PATCH 36/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 39 ++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index e2185b6..8194771 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,56 +30,81 @@ runs: shell: bash if: always() run: | + # Initialize variables has_errors=0 current_file="" files=() all_links=() + # Process output line by line while IFS= read -r line; do + # Detect file header lines if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then current_file="${BASH_REMATCH[1]}" files+=("$current_file") - elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+) ]]; then + # Detect broken link lines - extract URL, status code, and error message + elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+)(.*)$ ]]; then url="${BASH_REMATCH[1]}" status="${BASH_REMATCH[2]}" - link_str="$url (Status: $status)" + error_msg="${BASH_REMATCH[3]}" + # Clean up error message (trim leading/trailing whitespace) + error_msg=$(echo "$error_msg" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + + # Add to links array (format: file|url|status|error) if [ -n "$current_file" ]; then - all_links+=("${current_file}|${link_str}") + all_links+=("${current_file}|${url}|${status}|${error_msg}") has_errors=1 fi fi done <<< "$MLC_OUTPUT" - # ่พ“ๅ‡บ็ป“่ฎบ + # Output final conclusion if [ $has_errors -eq 0 ]; then - echo "All links are valid" + echo "โœ… All links are valid" exit 0 fi - echo "Found broken links" + echo "โŒ Found broken links" echo echo "===== DETAILS =====" + # Remove duplicate files unique_files=($(printf "%s\n" "${files[@]}" | sort -u)) + # Remove duplicate links unique_links=($(printf "%s\n" "${all_links[@]}" | sort -u)) + # Output error details for file in "${unique_files[@]}"; do file_links=() for link in "${unique_links[@]}"; do if [[ "$link" == "${file}|"* ]]; then + # Extract link info (remove filename prefix) link_only="${link#*|}" file_links+=("$link_only") fi done + # Output if file has broken links if [ ${#file_links[@]} -gt 0 ]; then echo "File: $file" - printf " %s\n" "${file_links[@]}" | sort -u + # Output each broken link with details + for link_info in "${file_links[@]}"; do + # Split link info into components + IFS='|' read -r url status error_msg <<< "$link_info" + + # Format output with error message if present + if [ -n "$error_msg" ]; then + echo " $url (Status: $status): $error_msg" + else + echo " $url (Status: $status)" + fi + done + # Add link count echo " โ†’ Found ${#file_links[@]} broken link(s)" echo fi From 9962551a420e1c879d66c4e900763265cdf0a531 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 13:08:41 +0800 Subject: [PATCH 37/47] optimize output Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 8194771..8fc6e15 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -35,6 +35,7 @@ runs: current_file="" files=() all_links=() + in_file_section=0 # Process output line by line while IFS= read -r line; do @@ -42,6 +43,14 @@ runs: if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then current_file="${BASH_REMATCH[1]}" files+=("$current_file") + in_file_section=1 + + # Skip summary lines that come after the actual link checks + elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]] || + [[ "$line" =~ ^[[:space:]]*ERROR:[[:space:]]* ]] || + [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ [^[:space:]]+\ โ†’\ Status:\ [0-9]+[[:space:]]*$ ]]; then + # Skip these summary lines + continue # Detect broken link lines - extract URL, status code, and error message elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+)(.*)$ ]]; then @@ -49,14 +58,19 @@ runs: status="${BASH_REMATCH[2]}" error_msg="${BASH_REMATCH[3]}" - # Clean up error message (trim leading/trailing whitespace) - error_msg=$(echo "$error_msg" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - - # Add to links array (format: file|url|status|error) - if [ -n "$current_file" ]; then + # Only process if we're in a file section + if [ -n "$current_file" ] && [ $in_file_section -eq 1 ]; then + # Clean up error message (trim leading/trailing whitespace) + error_msg=$(echo "$error_msg" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + + # Add to links array (format: file|url|status|error) all_links+=("${current_file}|${url}|${status}|${error_msg}") has_errors=1 fi + + # Reset file section flag when we hit a blank line + elif [[ -z "$line" ]]; then + in_file_section=0 fi done <<< "$MLC_OUTPUT" From 13335786752bfdc2d31d62bc0094d4ee57c1c3ce Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 13:20:43 +0800 Subject: [PATCH 38/47] fix bug of error msg Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 49 ++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 8fc6e15..d76e03e 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -36,6 +36,8 @@ runs: files=() all_links=() in_file_section=0 + in_error_block=0 + current_error="" # Process output line by line while IFS= read -r line; do @@ -44,36 +46,55 @@ runs: current_file="${BASH_REMATCH[1]}" files+=("$current_file") in_file_section=1 + in_error_block=0 # Skip summary lines that come after the actual link checks elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]] || [[ "$line" =~ ^[[:space:]]*ERROR:[[:space:]]* ]] || [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ [^[:space:]]+\ โ†’\ Status:\ [0-9]+[[:space:]]*$ ]]; then # Skip these summary lines + in_error_block=0 continue - # Detect broken link lines - extract URL, status code, and error message + # Detect broken link lines - extract URL and status code elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+)(.*)$ ]]; then url="${BASH_REMATCH[1]}" status="${BASH_REMATCH[2]}" - error_msg="${BASH_REMATCH[3]}" + error_start="${BASH_REMATCH[3]}" # Only process if we're in a file section if [ -n "$current_file" ] && [ $in_file_section -eq 1 ]; then - # Clean up error message (trim leading/trailing whitespace) - error_msg=$(echo "$error_msg" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - - # Add to links array (format: file|url|status|error) - all_links+=("${current_file}|${url}|${status}|${error_msg}") - has_errors=1 + # Start a new error block + in_error_block=1 + current_error=$(echo "$error_start" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') fi + # Capture multi-line error messages + elif [ $in_error_block -eq 1 ] && [[ "$line" =~ ^[[:space:]]+ ]]; then + # Append to current error message + current_error+="\n$line" + + # End of error block + elif [ $in_error_block -eq 1 ]; then + # Add to links array (format: file|url|status|error) + all_links+=("${current_file}|${url}|${status}|${current_error}") + has_errors=1 + in_error_block=0 + current_error="" + # Reset file section flag when we hit a blank line elif [[ -z "$line" ]]; then in_file_section=0 + in_error_block=0 fi done <<< "$MLC_OUTPUT" + # Capture any remaining error block at end of input + if [ $in_error_block -eq 1 ]; then + all_links+=("${current_file}|${url}|${status}|${current_error}") + has_errors=1 + fi + # Output final conclusion if [ $has_errors -eq 0 ]; then echo "โœ… All links are valid" @@ -110,12 +131,12 @@ runs: # Split link info into components IFS='|' read -r url status error_msg <<< "$link_info" - # Format output with error message if present - if [ -n "$error_msg" ]; then - echo " $url (Status: $status): $error_msg" - else - echo " $url (Status: $status)" - fi + # Format output with error message + echo " $url (Status: $status)" + # Preserve newlines in error message + printf " %s\n" "$error_msg" | while IFS= read -r err_line; do + echo " $err_line" + done done # Add link count From 916c3b663e5b1869fe615b98580ad2d79a517025 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 13:41:48 +0800 Subject: [PATCH 39/47] test Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 118 +++++++++++---------------------- 1 file changed, 38 insertions(+), 80 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index d76e03e..4c312a6 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -33,66 +33,48 @@ runs: # Initialize variables has_errors=0 current_file="" - files=() - all_links=() - in_file_section=0 - in_error_block=0 - current_error="" + file_summaries=() + in_summary_section=0 + current_summary="" # Process output line by line while IFS= read -r line; do # Detect file header lines if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then + # Save previous file summary + if [ -n "$current_file" ] && [ -n "$current_summary" ]; then + file_summaries+=("$current_file|$current_summary") + current_summary="" + fi + current_file="${BASH_REMATCH[1]}" - files+=("$current_file") - in_file_section=1 - in_error_block=0 + in_summary_section=0 - # Skip summary lines that come after the actual link checks - elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]] || - [[ "$line" =~ ^[[:space:]]*ERROR:[[:space:]]* ]] || - [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ [^[:space:]]+\ โ†’\ Status:\ [0-9]+[[:space:]]*$ ]]; then - # Skip these summary lines - in_error_block=0 - continue + # Detect start of summary section (after "n links checked.") + elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]]; then + in_summary_section=1 + current_summary="$line" - # Detect broken link lines - extract URL and status code - elif [[ "$line" =~ ^[[:space:]]*\[โœ–\]\ ([^[:space:]]+).*Status:\ ([0-9]+)(.*)$ ]]; then - url="${BASH_REMATCH[1]}" - status="${BASH_REMATCH[2]}" - error_start="${BASH_REMATCH[3]}" + # Collect summary content + elif [ $in_summary_section -eq 1 ]; then + # Skip empty lines at the start of summary + if [[ -z "$line" && -z "$current_summary" ]]; then + continue + fi - # Only process if we're in a file section - if [ -n "$current_file" ] && [ $in_file_section -eq 1 ]; then - # Start a new error block - in_error_block=1 - current_error=$(echo "$error_start" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + # Add to current summary + current_summary+="\n$line" + + # Check if this line indicates an error + if [[ "$line" =~ ERROR: ]] || [[ "$line" =~ \[โœ–\] ]]; then + has_errors=1 fi - - # Capture multi-line error messages - elif [ $in_error_block -eq 1 ] && [[ "$line" =~ ^[[:space:]]+ ]]; then - # Append to current error message - current_error+="\n$line" - - # End of error block - elif [ $in_error_block -eq 1 ]; then - # Add to links array (format: file|url|status|error) - all_links+=("${current_file}|${url}|${status}|${current_error}") - has_errors=1 - in_error_block=0 - current_error="" - - # Reset file section flag when we hit a blank line - elif [[ -z "$line" ]]; then - in_file_section=0 - in_error_block=0 fi done <<< "$MLC_OUTPUT" - # Capture any remaining error block at end of input - if [ $in_error_block -eq 1 ]; then - all_links+=("${current_file}|${url}|${status}|${current_error}") - has_errors=1 + # Save last file summary + if [ -n "$current_file" ] && [ -n "$current_summary" ]; then + file_summaries+=("$current_file|$current_summary") fi # Output final conclusion @@ -105,42 +87,18 @@ runs: echo echo "===== DETAILS =====" - # Remove duplicate files - unique_files=($(printf "%s\n" "${files[@]}" | sort -u)) - - # Remove duplicate links - unique_links=($(printf "%s\n" "${all_links[@]}" | sort -u)) - # Output error details - for file in "${unique_files[@]}"; do - file_links=() - for link in "${unique_links[@]}"; do - if [[ "$link" == "${file}|"* ]]; then - # Extract link info (remove filename prefix) - link_only="${link#*|}" - file_links+=("$link_only") - fi - done + for entry in "${file_summaries[@]}"; do + # Split into filename and summary + IFS='|' read -r filename summary <<< "$entry" - # Output if file has broken links - if [ ${#file_links[@]} -gt 0 ]; then - echo "File: $file" - - # Output each broken link with details - for link_info in "${file_links[@]}"; do - # Split link info into components - IFS='|' read -r url status error_msg <<< "$link_info" - - # Format output with error message - echo " $url (Status: $status)" - # Preserve newlines in error message - printf " %s\n" "$error_msg" | while IFS= read -r err_line; do - echo " $err_line" - done + # Only show summaries that contain errors + if [[ "$summary" =~ ERROR: ]] || [[ "$summary" =~ \[โœ–\] ]]; then + echo "File: $filename" + # Preserve newlines in summary + printf "%s\n" "$summary" | while IFS= read -r s_line; do + echo " $s_line" done - - # Add link count - echo " โ†’ Found ${#file_links[@]} broken link(s)" echo fi done \ No newline at end of file From 5b34caadae9924471bfbfdbe1780786f42efea35 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 17:42:59 +0800 Subject: [PATCH 40/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 4c312a6..cfed419 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -35,48 +35,42 @@ runs: current_file="" file_summaries=() in_summary_section=0 - current_summary="" # Process output line by line while IFS= read -r line; do # Detect file header lines if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then # Save previous file summary - if [ -n "$current_file" ] && [ -n "$current_summary" ]; then - file_summaries+=("$current_file|$current_summary") - current_summary="" + if [ -n "$current_file" ] && [ $in_summary_section -eq 1 ]; then + file_summaries+=("$current_file") + in_summary_section=0 fi current_file="${BASH_REMATCH[1]}" - in_summary_section=0 # Detect start of summary section (after "n links checked.") elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]]; then in_summary_section=1 - current_summary="$line" + # Start new summary for this file + file_summaries+=("$current_file") + file_summaries+=("$line") # Collect summary content elif [ $in_summary_section -eq 1 ]; then - # Skip empty lines at the start of summary - if [[ -z "$line" && -z "$current_summary" ]]; then - continue - fi - # Add to current summary - current_summary+="\n$line" + file_summaries+=("$line") # Check if this line indicates an error if [[ "$line" =~ ERROR: ]] || [[ "$line" =~ \[โœ–\] ]]; then has_errors=1 fi + + # Reset summary section flag when we hit a blank line or new file + elif [[ -z "$line" ]] || [[ "$line" =~ ^FILE: ]]; then + in_summary_section=0 fi done <<< "$MLC_OUTPUT" - # Save last file summary - if [ -n "$current_file" ] && [ -n "$current_summary" ]; then - file_summaries+=("$current_file|$current_summary") - fi - # Output final conclusion if [ $has_errors -eq 0 ]; then echo "โœ… All links are valid" @@ -88,17 +82,23 @@ runs: echo "===== DETAILS =====" # Output error details - for entry in "${file_summaries[@]}"; do - # Split into filename and summary - IFS='|' read -r filename summary <<< "$entry" + current_filename="" + for line in "${file_summaries[@]}"; do + # If line is a filename + if [[ "$line" =~ ^FILE: ]]; then + current_filename="${line#FILE: }" + continue + fi # Only show summaries that contain errors - if [[ "$summary" =~ ERROR: ]] || [[ "$summary" =~ \[โœ–\] ]]; then - echo "File: $filename" - # Preserve newlines in summary - printf "%s\n" "$summary" | while IFS= read -r s_line; do - echo " $s_line" - done - echo + if [[ "$line" =~ ERROR: ]] || [[ "$line" =~ \[โœ–\] ]]; then + # Print filename if it's the start of a summary block + if [ -n "$current_filename" ]; then + echo "File: $current_filename" + current_filename="" + fi + + # Print the line with proper indentation + echo " $line" fi done \ No newline at end of file From 98d072a7d8c765fa41f5e12d360c33eec3b29e49 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 17:49:40 +0800 Subject: [PATCH 41/47] optimize output Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 56 +++++++++++++--------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index cfed419..bea2f06 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,44 +30,38 @@ runs: shell: bash if: always() run: | - # Initialize variables has_errors=0 current_file="" - file_summaries=() + files=() + summaries=() in_summary_section=0 # Process output line by line while IFS= read -r line; do # Detect file header lines if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then - # Save previous file summary - if [ -n "$current_file" ] && [ $in_summary_section -eq 1 ]; then - file_summaries+=("$current_file") - in_summary_section=0 - fi - current_file="${BASH_REMATCH[1]}" + in_summary_section=0 # Detect start of summary section (after "n links checked.") elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]]; then - in_summary_section=1 - # Start new summary for this file - file_summaries+=("$current_file") - file_summaries+=("$line") + if [ -n "$current_file" ]; then + in_summary_section=1 + # Start new summary for this file + files+=("$current_file") + summaries+=("$line") + fi # Collect summary content - elif [ $in_summary_section -eq 1 ]; then + elif [ $in_summary_section -eq 1 ] && [ -n "$current_file" ]; then # Add to current summary - file_summaries+=("$line") + last_index=$((${#summaries[@]} - 1)) + summaries[$last_index]+=$'\n'"$line" # Check if this line indicates an error if [[ "$line" =~ ERROR: ]] || [[ "$line" =~ \[โœ–\] ]]; then has_errors=1 fi - - # Reset summary section flag when we hit a blank line or new file - elif [[ -z "$line" ]] || [[ "$line" =~ ^FILE: ]]; then - in_summary_section=0 fi done <<< "$MLC_OUTPUT" @@ -82,23 +76,17 @@ runs: echo "===== DETAILS =====" # Output error details - current_filename="" - for line in "${file_summaries[@]}"; do - # If line is a filename - if [[ "$line" =~ ^FILE: ]]; then - current_filename="${line#FILE: }" - continue - fi + for i in "${!files[@]}"; do + filename="${files[$i]}" + summary="${summaries[$i]}" # Only show summaries that contain errors - if [[ "$line" =~ ERROR: ]] || [[ "$line" =~ \[โœ–\] ]]; then - # Print filename if it's the start of a summary block - if [ -n "$current_filename" ]; then - echo "File: $current_filename" - current_filename="" - fi - - # Print the line with proper indentation - echo " $line" + if [[ "$summary" =~ ERROR: ]] || [[ "$summary" =~ \[โœ–\] ]]; then + echo "File: $filename" + # Preserve newlines in summary + while IFS= read -r s_line; do + echo " $s_line" + done <<< "$summary" + echo # Add empty line between files fi done \ No newline at end of file From d9b5677309657be8fbedd638ab9b6bcf067d527f Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 20:56:42 +0800 Subject: [PATCH 42/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index bea2f06..1d0bf2e 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -63,18 +63,15 @@ runs: has_errors=1 fi fi - done <<< "$MLC_OUTPUT" + done <<< "$MLC_OUTPUT" # This is the output of the markdown link check action # Output final conclusion if [ $has_errors -eq 0 ]; then - echo "โœ… All links are valid" + echo "=========== All links are valid ===========" exit 0 fi - echo "โŒ Found broken links" - echo - echo "===== DETAILS =====" - + echo "=========== Found broken links ===========" # Output error details for i in "${!files[@]}"; do filename="${files[$i]}" From f4a8c1785e2eafd79d7d9b62b162fac0092926a4 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 20:59:45 +0800 Subject: [PATCH 43/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 1d0bf2e..9fe6eae 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -34,7 +34,7 @@ runs: current_file="" files=() summaries=() - in_summary_section=0 + in_summary_section=0 # Flag to indicate if we are in the summary section # Process output line by line while IFS= read -r line; do @@ -49,7 +49,6 @@ runs: in_summary_section=1 # Start new summary for this file files+=("$current_file") - summaries+=("$line") fi # Collect summary content From a9cde987b34e9f40aad0f7e038f6c936b45f631d Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Mon, 18 Aug 2025 21:06:09 +0800 Subject: [PATCH 44/47] optimize Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 9fe6eae..817686e 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -34,7 +34,7 @@ runs: current_file="" files=() summaries=() - in_summary_section=0 # Flag to indicate if we are in the summary section + in_summary_section=0 # Process output line by line while IFS= read -r line; do @@ -49,6 +49,7 @@ runs: in_summary_section=1 # Start new summary for this file files+=("$current_file") + summaries+=("Details:") fi # Collect summary content From 3a34e0b0fe4bb117ef119a4c4571737ef8349d6c Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Tue, 19 Aug 2025 09:23:05 +0800 Subject: [PATCH 45/47] add comments Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 817686e..0f6c920 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -34,7 +34,7 @@ runs: current_file="" files=() summaries=() - in_summary_section=0 + in_summary_section=0 # 0: not in summary section, 1: in summary section # Process output line by line while IFS= read -r line; do @@ -63,7 +63,7 @@ runs: has_errors=1 fi fi - done <<< "$MLC_OUTPUT" # This is the output of the markdown link check action + done <<< "$MLC_OUTPUT" # The output of the markdown link check action # Output final conclusion if [ $has_errors -eq 0 ]; then @@ -71,13 +71,13 @@ runs: exit 0 fi - echo "=========== Found broken links ===========" + echo "=========== Found error links ===========" # Output error details for i in "${!files[@]}"; do filename="${files[$i]}" summary="${summaries[$i]}" - # Only show summaries that contain errors + # Only output summaries that contain errors if [[ "$summary" =~ ERROR: ]] || [[ "$summary" =~ \[โœ–\] ]]; then echo "File: $filename" # Preserve newlines in summary From c7783fb7d65df08d5658759002a5d68464de18a6 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Tue, 19 Aug 2025 13:26:35 +0800 Subject: [PATCH 46/47] fix nits Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 0f6c920..39e7e73 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,6 +30,8 @@ runs: shell: bash if: always() run: | + set -e + has_errors=0 current_file="" files=() From e0365d3e9760003cdc2d0651985156fc5144fcd6 Mon Sep 17 00:00:00 2001 From: Yanxuan Liu Date: Tue, 19 Aug 2025 13:36:32 +0800 Subject: [PATCH 47/47] optimize log Signed-off-by: Yanxuan Liu --- markdown-link-check/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/markdown-link-check/action.yml b/markdown-link-check/action.yml index 39e7e73..744eca3 100644 --- a/markdown-link-check/action.yml +++ b/markdown-link-check/action.yml @@ -30,6 +30,7 @@ runs: shell: bash if: always() run: | + echo "Summarizing markdown link check results" set -e has_errors=0