-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add workflow to check broken links #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Abhijeet2409
wants to merge
17
commits into
hiero-ledger:main
Choose a base branch
from
Abhijeet2409:fix-broken-links-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−0
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a05c8e3
feat: add broken link checker
Abhijeet2409 01a9f0c
chore: add and configure broken link checker workflow (weekly schedule)
Abhijeet2409 dcf7e69
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 ad41d12
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 7158423
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 6ebac06
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 4418a12
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 0949095
fix: update runner
Abhijeet2409 4efb2b3
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 7ffcdbe
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 cb25b45
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 1715a12
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 ff15b34
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 25cd393
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 fd62b7a
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 393ae9e
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 f3593ee
Merge branch 'main' into fix-broken-links-workflow
Abhijeet2409 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| name: Cron – Check Broken Markdown Links | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 0 * * 0" | ||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| description: "Run without creating issues? (true/false)" | ||
| required: true | ||
| default: true | ||
| type: boolean | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| cron-check-broken-links: | ||
| runs-on: hl-web-lin-md | ||
| steps: | ||
| - name: Harden runner (audit outbound calls) | ||
| uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||
|
|
||
| - name: Check Markdown links (Lychee) | ||
| id: lychee | ||
| uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0 | ||
| continue-on-error: true | ||
| with: | ||
| args: --verbose --no-progress './**/*.md' | ||
| fail: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Report Broken Links (Idempotent Issue Management) | ||
| if: steps.lychee.outcome == 'failure' | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| // Determine if this is a dry run | ||
| const isManual = context.eventName === 'workflow_dispatch'; | ||
| const dryRun = isManual ? String(context.payload.inputs.dry_run).toLowerCase() === 'true' : false; | ||
|
|
||
| // Labels configuration | ||
| const targetLabels = ['broken-markdown-links', 'automated']; | ||
| const issueTitle = "Scheduled Markdown Link Check Found Broken Links"; | ||
| const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | ||
|
|
||
| console.log(`Event: ${context.eventName}, Dry Run: ${dryRun}`); | ||
|
|
||
| // Define Issue Body | ||
| const body = `### 🔗 Broken Links Detected\n\n` + | ||
| `The scheduled markdown link check workflow has detected broken links.\n\n` + | ||
| `**Run Details:**\n` + | ||
| `- **Timestamp:** ${new Date().toISOString()}\n` + | ||
| `- **Workflow Run:** [View Logs](${runUrl})\n\n` + | ||
| `> **Note:** We use [Lychee](https://github.com/lycheeverse/lychee) for link checking. ` + | ||
| `Please check the "Check Markdown links" step in the logs to see the specific URLs that failed.`; | ||
|
|
||
| if (dryRun) { | ||
| console.log("DRY RUN: Would have created or updated an issue."); | ||
| return; | ||
| } | ||
|
|
||
| // Search for existing issue and Update/Create | ||
| try { | ||
| const { data: issues } = await github.rest.issues.listForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| labels: targetLabels.join(','), | ||
| per_page: 100 | ||
| }); | ||
|
|
||
| const existingIssue = issues.find(issue => issue.title === issueTitle); | ||
|
|
||
| if (existingIssue) { | ||
| console.log(`Updating existing issue #${existingIssue.number}`); | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: existingIssue.number, | ||
| body: `**Update ${new Date().toISOString()}:** Still finding broken links.\nCheck new run logs: ${runUrl}` | ||
| }); | ||
| } else { | ||
| console.log("Creating a new issue..."); | ||
| await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: issueTitle, | ||
| body: body, | ||
| labels: targetLabels | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| console.error('Failed to manage broken link issue:', error); | ||
| core.setFailed(`Failed to create or update issue: ${error.message}`); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.