MegaBites-AI/Windows-powershell
0372
1name: 'Verify Markdown Links'2description: 'Verify all links in markdown files using PowerShell and Markdig'3author: 'PowerShell Team'4 5inputs:6 timeout-sec:7 description: 'Timeout in seconds for HTTP requests'8 required: false9 default: '30'10 maximum-retry-count:11 description: 'Maximum number of retries for failed requests'12 required: false13 default: '2'14 15outputs:16 total-links:17 description: 'Total number of unique links checked'18 value: ${{ steps.verify.outputs.total }}19 passed-links:20 description: 'Number of links that passed verification'21 value: ${{ steps.verify.outputs.passed }}22 failed-links:23 description: 'Number of links that failed verification'24 value: ${{ steps.verify.outputs.failed }}25 skipped-links:26 description: 'Number of links that were skipped'27 value: ${{ steps.verify.outputs.skipped }}28 29runs:30 using: 'composite'31 steps:32 - name: Get changed markdown files33 id: changed-files34 uses: "./.github/actions/infrastructure/get-changed-files"35 with:36 filter: '*.md'37 event-types: 'pull_request,push'38 39 - name: Verify markdown links40 id: verify41 shell: pwsh42 env:43 CHANGED_FILES_JSON: ${{ steps.changed-files.outputs.files }}44 run: |45 Write-Host "Starting markdown link verification..." -ForegroundColor Cyan46 47 # Get changed markdown files from environment variable (secure against injection)48 $changedFilesJson = $env:CHANGED_FILES_JSON49 $changedFiles = $changedFilesJson | ConvertFrom-Json50 51 if ($changedFiles.Count -eq 0) {52 Write-Host "No markdown files changed, skipping verification" -ForegroundColor Yellow53 "total=0" >> $env:GITHUB_OUTPUT54 "passed=0" >> $env:GITHUB_OUTPUT55 "failed=0" >> $env:GITHUB_OUTPUT56 "skipped=0" >> $env:GITHUB_OUTPUT57 exit 058 }59 60 Write-Host "Changed markdown files: $($changedFiles.Count)" -ForegroundColor Cyan61 $changedFiles | ForEach-Object { Write-Host " - $_" -ForegroundColor Gray }62 63 # Build parameters for each file64 $params = @{65 File = $changedFiles66 TimeoutSec = [int]'${{ inputs.timeout-sec }}'67 MaximumRetryCount = [int]'${{ inputs.maximum-retry-count }}'68 }69 70 # Run the verification script71 $scriptPath = Join-Path '${{ github.action_path }}' 'Verify-MarkdownLinks.ps1'72 73 # Capture output and parse results74 $output = & $scriptPath @params 2>&1 | Tee-Object -Variable capturedOutput75 76 # Try to extract metrics from output77 $totalLinks = 078 $passedLinks = 079 $failedLinks = 080 $skippedLinks = 081 82 foreach ($line in $capturedOutput) {83 if ($line -match 'Total URLs checked: (\d+)') {84 $totalLinks = $Matches[1]85 }86 elseif ($line -match 'Passed: (\d+)') {87 $passedLinks = $Matches[1]88 }89 elseif ($line -match 'Failed: (\d+)') {90 $failedLinks = $Matches[1]91 }92 elseif ($line -match 'Skipped: (\d+)') {93 $skippedLinks = $Matches[1]94 }95 }96 97 # Set outputs98 "total=$totalLinks" >> $env:GITHUB_OUTPUT99 "passed=$passedLinks" >> $env:GITHUB_OUTPUT100 "failed=$failedLinks" >> $env:GITHUB_OUTPUT101 "skipped=$skippedLinks" >> $env:GITHUB_OUTPUT102 103 Write-Host "Action completed" -ForegroundColor Cyan104 105 # Exit with the same code as the verification script106 exit $LASTEXITCODE107 108branding:109 icon: 'link'110 color: 'blue'111 