|
| 1 | +name: Verify Links |
| 2 | + |
| 3 | +# Runs the link verification check (eng/common/scripts/Verify-Links.ps1) that |
| 4 | +# previously lived as a step in the Azure DevOps "Compliance" job in |
| 5 | +# eng/pipelines/templates/jobs/ci.yml. |
| 6 | +# |
| 7 | +# Triggers: |
| 8 | +# - pull_request: runs on every PR, scanning only changed *.md files (matches |
| 9 | +# the prior Compliance-job behavior for PR builds). |
| 10 | +# - check_run completed: fires when the Azure DevOps "net - pullrequest" |
| 11 | +# pipeline (which owns the Compliance job) reports back to GitHub, so it |
| 12 | +# effectively runs after the Compliance job. Same scanning behavior as PR. |
| 13 | +# - workflow_dispatch: manual runs. |
| 14 | + |
| 15 | +on: |
| 16 | + pull_request: |
| 17 | + branches: |
| 18 | + - main |
| 19 | + - release/* |
| 20 | + - hotfix/* |
| 21 | + check_run: |
| 22 | + types: |
| 23 | + - completed |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | +jobs: |
| 30 | + verify-links: |
| 31 | + name: Verify Links |
| 32 | + # When fired via check_run, only run after the Azure DevOps Compliance |
| 33 | + # job in the Azure/azure-sdk-for-net repo completes. |
| 34 | + if: >- |
| 35 | + github.event.check_run.check_suite.app.name == 'Azure Pipelines' && |
| 36 | + (github.repository == 'Azure/azure-sdk-for-net' && contains(github.event.check_run.name, 'Compliance')) || |
| 37 | + (github.repository == 'Azure/azure-sdk-for-python' && contains(github.event.check_run.name, 'Analyze')) || |
| 38 | + (github.repository == 'Azure/azure-sdk-for-java' && contains(github.event.check_run.name, 'Analyze')) || |
| 39 | + (github.repository == 'Azure/azure-sdk-for-js' && contains(github.event.check_run.name, 'Analyze')) || |
| 40 | + (github.repository == 'Azure/azure-sdk-for-c' && contains(github.event.check_run.name, 'GenerateReleaseArtifacts')) || |
| 41 | + (github.repository == 'Azure/azure-sdk-for-cpp' && contains(github.event.check_run.name, 'Analyze')) || |
| 42 | + (github.repository == 'Azure/azure-sdk-for-go' && contains(github.event.check_run.name, 'Analyze')) || |
| 43 | + (github.repository == 'Azure/azure-sdk-for-ios' && contains(github.event.check_run.name, 'Analyze')) |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + ref: ${{ github.event.pull_request.head.sha || github.event.check_run.head_sha || github.sha }} |
| 50 | + # Need full history so get-markdown-files-from-changed-files.ps1 can |
| 51 | + # diff against the target branch (origin/<base>) that checkout sets up. |
| 52 | + fetch-depth: 0 |
| 53 | + |
| 54 | + - name: Link verification check |
| 55 | + shell: pwsh |
| 56 | + # The shared scripts read these Azure DevOps-style variables to compute |
| 57 | + # the git diff range used by Get-ChangedFiles. Setting them lets the |
| 58 | + # script's defaults work: |
| 59 | + # $TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/") |
| 60 | + # $SourceCommittish = "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" |
| 61 | + env: |
| 62 | + SYSTEM_PULLREQUEST_TARGETBRANCH: ${{ github.base_ref }} |
| 63 | + SYSTEM_PULLREQUEST_SOURCECOMMITID: ${{ github.event.pull_request.head.sha }} |
| 64 | + run: | |
| 65 | + $urls = & ./eng/common/scripts/get-markdown-files-from-changed-files.ps1 |
| 66 | + if (-not $urls -or $urls.Count -eq 0) { |
| 67 | + Write-Host "No changed markdown files; nothing to verify." |
| 68 | + exit 0 |
| 69 | + } |
| 70 | +
|
| 71 | + $sourceRepoUri = '${{ github.event.pull_request.head.repo.html_url }}' |
| 72 | + $defaultBranch = '${{ github.event.repository.default_branch }}' |
| 73 | + $branchReplaceRegex = "^($sourceRepoUri(?:\.git)?/(?:blob|tree)/)$defaultBranch(/.*)$" |
| 74 | +
|
| 75 | + ./eng/common/scripts/Verify-Links.ps1 ` |
| 76 | + -urls $urls ` |
| 77 | + -rootUrl "file://$env:GITHUB_WORKSPACE/" ` |
| 78 | + -recursive:$false ` |
| 79 | + -ignoreLinksFile "$env:GITHUB_WORKSPACE/eng/ignore-links.txt" ` |
| 80 | + -branchReplaceRegex $branchReplaceRegex ` |
| 81 | + -branchReplacementName '${{ github.event.pull_request.head.sha }}' ` |
| 82 | + -checkLinkGuidance:$true ` |
| 83 | + -localBuildRepoName '${{ github.repository }}' ` |
| 84 | + -localBuildRepoPath $env:GITHUB_WORKSPACE ` |
| 85 | + -inputCacheFile "https://azuresdkartifacts.blob.core.windows.net/verify-links-cache/verify-links-cache.txt" ` |
| 86 | + -allowRelativeLinksFile "$env:GITHUB_WORKSPACE/eng/common/scripts/allow-relative-links.txt" |
0 commit comments