name:CheckallEnglishlinks# **What it does**: This script once a day checks all English links and reports in issues.# **Why we have it**: We want to know if any links break.# **Who does it impact**: Docs content.on:workflow_dispatch:schedule:-cron:'40 19 * * *'# once a day at 19:40 UTC / 11:40 PSTpermissions:contents:readissues:writejobs:check_all_english_links:name:Checkalllinksif:github.repository=='github/docs-internal'runs-on:ubuntu-latestenv:GITHUB_TOKEN:${{secrets.DOCUBOT_READORG_REPO_WORKFLOW_SCOPES}}FIRST_RESPONDER_PROJECT:DocscontentfirstresponderREPORT_AUTHOR:docubotREPORT_LABEL:brokenlinkreportREPORT_REPOSITORY:github/docs-contentsteps:-name:Checkoutrepo'sdefaultbranchuses:actions/checkout@v3-name:SetupNodeuses:actions/setup-node@v3with:node-version:16.13.xcache:npm-name:npmcirun:npmci-name:npmrunbuildrun:npmrunbuild-name:Runscriptrun:|
script/check-english-links.js > broken_links.md
# check-english-links.js returns 0 if no links are broken, and 1 if any links# are broken. When an Actions step's exit code is 1, the action run's job status# is failure and the run ends. The following steps create an issue for the# broken link report only if any links are broken, so `if: ${{ failure() }}`# ensures the steps run despite the previous step's failure of the job.-if:${{failure()}}name:Gettitleforissueid:checkrun:echo"title=$(head -1 broken_links.md)">>$GITHUB_OUTPUT-if:${{failure()}}name:Createissuefromfileid:broken-link-reportuses:peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77ewith:token:${{env.GITHUB_TOKEN}}title:${{steps.check.outputs.title}}content-filepath:./broken_links.mdrepository:${{env.REPORT_REPOSITORY}}labels:${{env.REPORT_LABEL}}-if:${{failure()}}name:Closeand/orcommentonoldissuesenv:NEW_REPORT_URL:'https://github.com/${{ env.REPORT_REPOSITORY }}/issues/${{ steps.broken-link-report.outputs.issue-number }}'run:|
gh alias set list-reports "issue list \
--repo ${{ env.REPORT_REPOSITORY }} \
--author ${{ env.REPORT_AUTHOR }} \
--label '${{ env.REPORT_LABEL }}'"
# Link to the previous report from the new report that triggered this# workflow run.previous_report_url=$(ghlist-reports\--stateall\--limit2\--jsonurl\--jq'.[].url'\|grep-v${{env.NEW_REPORT_URL}}|head-1)ghissuecomment${{env.NEW_REPORT_URL}}--body"⬅️ [Previous report]($previous_report_url)"# If an old report is open and assigned to someone, link to the newer# report without closing the old report.forissue_urlin$(ghlist-reports\--jsonassignees,url\--jq'.[] | select (.assignees != []) | .url');doif [ "$issue_url"!="${{ env.NEW_REPORT_URL }}" ];thenghissuecomment$issue_url--body"➡️ [Newer report](${{ env.NEW_REPORT_URL }})"fidone# Link to the newer report from any older report that is still open,# then close the older report and remove it from the first responder's# project board.forissue_urlin$(ghlist-reports\--search'no:assignee'\--jsonurl\--jq'.[].url');doif [ "$issue_url"!="${{ env.NEW_REPORT_URL }}" ];thenghissuecomment$issue_url--body"➡️ [Newer report](${{ env.NEW_REPORT_URL }})"ghissueclose$issue_urlghissueedit$issue_url--remove-project"${{ env.FIRST_RESPONDER_PROJECT }}"fidone