From 896990e46fac4b9cc94c2b3023d5eb42718b22c3 Mon Sep 17 00:00:00 2001 From: Aaron Collier Date: Wed, 2 Mar 2022 14:46:16 +0100 Subject: [PATCH] :sparkles: Make check update issue --- .github/workflows/check-links.yaml | 51 +++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-links.yaml b/.github/workflows/check-links.yaml index 3985ecbfc8..bc3e4e6de2 100644 --- a/.github/workflows/check-links.yaml +++ b/.github/workflows/check-links.yaml @@ -21,4 +21,53 @@ jobs: - name: Check links env: URL: https://pr-2189-odiepqq-652soceglkw4u.eu-3.platformsh.site - run: ./muffet --buffer-size=8192 --rate-limit=1 --max-connections-per-host=10 --color=always --header="User-Agent:Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/91.0" -e=console.platform.sh/projects/create-project -e=cloud.orange-business.com -e=developers.cloudflare.com -e=discord.com -e=pptr.dev https://pr-2189-odiepqq-652soceglkw4u.eu-3.platformsh.site + run: ./muffet --json --buffer-size=8192 --rate-limit=1 --max-connections-per-host=10 --color=always --header="User-Agent:Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/91.0" -e=console.platform.sh/projects/create-project -e=cloud.orange-business.com -e=developers.cloudflare.com -e=discord.com -e=pptr.dev https://pr-2189-odiepqq-652soceglkw4u.eu-3.platformsh.site > broken_links.json + + - name: Create Markdown file of broken links + if: ${{ always() }} + run: | + data=broken_links.json + + # Get length of broken links array + eval "$( jq -r '@sh "urls_length=\(.|length)"' "$data" )" + + # Check if any links broken + if [ -z "$urls_length" ]; then + ":tada: There are no broken links! :tada:" > broken_links.md + else + echo -e "The following pages had broken links to check and possibly fix:\n" > broken_links.md + + # Loop through the broken URLs to create items + for (( i = 0; i < urls_length; ++i )); do + unset location + unset broken_links + unset error + + # Get the location where the broken link was found + eval "$( + jq -r --argjson i "$i" ' + .[$i] | + @sh "location=\(.url)"' "$data" + )" + echo "- $location" >> broken_links.md + + # Loop through the broken links + jq -r --argjson i "$i" '.[$i] ' "$data" | + # Get the specific broken link and its error + jq -r '.links[] | (.url, .error)' | + while IFS= read -r url ; do + IFS= read -r error + # Output that as a checklist item + echo " - [ ] [$error]($url)" >> broken_links.md + done + done + fi + + - name: Create issue from Markdown file + id: create-issue + if: ${{ always() }} + uses: peter-evans/create-issue-from-file@v2 + with: + title: ":bug: Broken links" + content-filepath: broken_links.md + issue-number: 2213