Skip to content

[DevOps] Create broken link tests for markdown files across all documentation folders #1691

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

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 12, 2025

This PR implements comprehensive broken link testing for all markdown files in the repository, with folder-specific validation rules and automated GitHub workflow integration.

What's New

  • Comprehensive Link Validation: Added BrokenLinks.Tests.ps1 in src/powershell/Tests/Lint that validates links across all markdown files
  • Folder-Specific Rules: Each documentation folder has tailored validation logic:
    • docs/: Relative links for files within docs, root-relative for MS Learn content, fully qualified for external links, Jekyll template support
    • docs-mslearn/: Folder-relative for same folder files, root-relative for learn.microsoft.com content, fully qualified for external (prohibits explicit learn.microsoft.com URLs)
    • docs-wiki/: Relative links for files within docs-wiki, fully qualified for external links
    • Other repo files: Relative for repository files, fully qualified for external links
  • Tag-Based Testing: Independent test execution using tags (Docs, DocsMslearn, DocsWiki, Other)
  • GitHub Workflow Integration: Updated dev.yml to trigger broken link tests when markdown files change in any documentation folder

Technical Implementation

The tests automatically integrate with the existing lint test infrastructure and validate:

  • ✅ Link format compliance per folder requirements
  • ✅ File existence for relative links
  • ✅ Proper boundary enforcement (links stay within intended scopes)
  • ✅ Language/locale validation (fails for non-Azure blog links with locales)
  • ✅ Jekyll template variable recognition for docs folder

Test Results

Successfully identifies 70 broken links across the repository, demonstrating the tests are working correctly to catch real issues.

# Run all broken link tests
pwsh src/scripts/Test-PowerShell.ps1 -Lint

# Run specific folder tests
Invoke-Pester -Path 'src/powershell/Tests/Lint/BrokenLinks.Tests.ps1' -Tag 'Docs'
Invoke-Pester -Path 'src/powershell/Tests/Lint/BrokenLinks.Tests.ps1' -Tag 'DocsMslearn'

Fixes #1690.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [DevOps] Create a test to check for broken links [DevOps] Create broken link tests for markdown files across all documentation folders Jun 12, 2025
Copilot finished work on behalf of flanakin June 12, 2025 19:56
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a separate workflow documentation tests and only run the broken link test there. Don't change the PowerShell code tests. Rename dev.yml to powershell.yml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created separate documentation.yml workflow for broken link tests and renamed dev.yml to powershell.yml. The PowerShell code tests remain unchanged. Commit bccd13f

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the src/scripts/Test-PowerShell.ps1 script to add a -Markdown option that runs this broken links test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added -Markdown parameter to Test-PowerShell.ps1 that runs the broken links test. The script can now be called with src/scripts/Test-PowerShell.ps1 -Markdown. Commit bccd13f

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Issue or PR needs to be reviewed by the author or it will be closed due to no activity label Jun 19, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Review 👀 PR that is ready to be reviewed label Jun 19, 2025
Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
Copilot finished work on behalf of flanakin June 19, 2025 04:00
@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Review 👀 PR that is ready to be reviewed and removed Needs: Attention 👋 Issue or PR needs to be reviewed by the author or it will be closed due to no activity labels Jun 19, 2025
Comment on lines +14 to +26
name: Broken Links
runs-on: Windows-latest
steps:
- name: Install and cache PowerShell modules
uses: potatoqualitee/psmodulecache@v6.2.1
with:
modules-to-cache: Pester
shell: pwsh
- uses: actions/checkout@v3
- name: Run Broken Links Test
shell: pwsh
run: |
src/scripts/Test-PowerShell.ps1 -Markdown

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium documentation

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI about 12 hours ago

To fix the issue, we will add a permissions block to the root of the workflow file. This block will specify the least privileges required for the workflow to function. Since the workflow only needs to read the repository contents to check for broken links, we will set contents: read. This ensures that the workflow has no write access to the repository.

The permissions block will be added at the root level, applying to all jobs in the workflow.


Suggested changeset 1
.github/workflows/documentation.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml
--- a/.github/workflows/documentation.yml
+++ b/.github/workflows/documentation.yml
@@ -11,2 +11,5 @@
 
+permissions:
+  contents: read
+
 jobs:
EOF
@@ -11,2 +11,5 @@

permissions:
contents: read

jobs:
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Review 👀 PR that is ready to be reviewed Skill: DevOps GitHub setup and automation Skill: Documentation Documentation updates Tool: FinOps guide Implementing FinOps guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DevOps] Create a test to check for broken links
5 participants