From b5c016b16ad4175915603ff00fc59f3c5badf0d5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 21 Jan 2025 19:23:09 +0100 Subject: [PATCH] Update links.yml (#152) Signed-off-by: Glenn Jocher --- .github/workflows/links.yml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml index 959605a89c..fcf304fc6e 100644 --- a/.github/workflows/links.yml +++ b/.github/workflows/links.yml @@ -13,6 +13,7 @@ name: Check Website links on: workflow_dispatch: + pull_request: schedule: - cron: "0 0 * * *" # runs at 00:00 UTC every day @@ -86,6 +87,39 @@ jobs: --no-verbose \ --force-directories + - name: Run codespell on downloaded pages + id: codespell + continue-on-error: true # Ensure the workflow continues even if spelling errors are found + run: | + pip install codespell + CODESPELL_OUTPUT=$(find ${{ matrix.website }} -type f -name "*.html" -print0 | xargs -0 codespell \ + --ignore-words-list "crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall,skelton,goin,referer,pre,uint,dto,linkedin,webp,webgl,href,onclick,github,api,http,png,svg,gif,jpg,jpeg,href,js" \ + --skip "*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,*lock*,__pycache__*,*.ico,*.jpg,*.png,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml" \ + 2>&1 || true) + echo "$CODESPELL_OUTPUT" + + # Process CODESPELL_OUTPUT + MODIFIED_OUTPUT=$(echo "$CODESPELL_OUTPUT" | sed 's#\(.*/\)[^/]*:[0-9]*: \(.*\)#\1 \2#') + echo "$MODIFIED_OUTPUT" + + # Check for spelling errors + if [[ "$CODESPELL_OUTPUT" == *"==>"* ]]; then + echo "Spelling errors found ⚠️" + + echo "CODESPELL_SUMMARY<> $GITHUB_ENV + echo "## 📝 Spelling Errors" >> $GITHUB_ENV + # Use MODIFIED_OUTPUT here instead of CODESPELL_OUTPUT + echo "$MODIFIED_OUTPUT" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + # Set output for Slack notification + echo "CODESPELL_ERRORS=$CODESPELL_SUMMARY" >> $GITHUB_OUTPUT + echo "CODESPELL_FAILED=true" >> $GITHUB_OUTPUT + else + echo "No spelling errors found ✅" + echo "CODESPELL_FAILED=false" >> $GITHUB_OUTPUT + fi + - name: Run Broken Link Checks on Website id: lychee uses: ultralytics/actions/retry@main @@ -139,7 +173,12 @@ jobs: exit 1 fi - - name: Check for failure and notify + - name: Add spelling errors to GitHub Summary + if: always() && steps.codespell.outputs.CODESPELL_FAILED == 'true' + run: | + echo "${{ env.CODESPELL_SUMMARY }}" >> $GITHUB_STEP_SUMMARY + + - name: Notify Slack for broken links if: always() && steps.lychee.outcome == 'failure' && github.event_name == 'schedule' && github.run_attempt == '1' uses: slackapi/slack-github-action@v2.0.0 with: @@ -147,3 +186,14 @@ jobs: webhook: ${{ matrix.website == 'www.ultralytics.com' && secrets.SLACK_WEBHOOK_URL_WEBSITE || secrets.SLACK_WEBHOOK_URL_YOLO }} payload: | text: "GitHub Actions: Errors found in ${{ github.workflow }} for ${{ matrix.website }} ❌\n\n\n*Repository:* https://github.com/${{ github.repository }}\n*Action:* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n*Author:* ${{ github.actor }}\n*Event:* ${{ github.event_name }}\n\n\n${{ env.SUMMARY }}\n" + + - name: Notify Slack for spelling errors + if: always() && steps.codespell.outputs.CODESPELL_FAILED == 'true' && github.event_name == 'schedule' && github.run_attempt == '1' + uses: slackapi/slack-github-action@v2.0.0 + with: + webhook-type: incoming-webhook + webhook: ${{ matrix.website == 'www.ultralytics.com' && secrets.SLACK_WEBHOOK_URL_WEBSITE || secrets.SLACK_WEBHOOK_URL_YOLO }} + payload: | + { + "text": "GitHub Actions: Spelling errors found in ${{ github.workflow }} for ${{ matrix.website }} ❌\n\n\n*Repository:* https://github.com/${{ github.repository }}\n*Action:* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n*Author:* ${{ github.actor }}\n*Event:* ${{ github.event_name }}\n\n\n*Misspelled words:*\n${{ steps.codespell.outputs.CODESPELL_ERRORS }}\n" + }