microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
.github/workflows/create-stale-docs-issues.yml
119lines · modecode
| 1 | name: Create Stale Documentation Issues |
| 2 | |
| 3 | on: |
| 4 | workflow_call: |
| 5 | inputs: |
| 6 | threshold-days: |
| 7 | description: 'Number of days before ms.date is considered stale' |
| 8 | required: false |
| 9 | type: number |
| 10 | default: 90 |
| 11 | artifact-name: |
| 12 | description: 'Name of the artifact containing freshness check results' |
| 13 | required: false |
| 14 | type: string |
| 15 | default: msdate-freshness-results |
| 16 | results-file: |
| 17 | description: 'Path to JSON results file after artifact download' |
| 18 | required: false |
| 19 | type: string |
| 20 | default: logs/msdate-freshness-results.json |
| 21 | |
| 22 | permissions: |
| 23 | contents: read |
| 24 | issues: write |
| 25 | |
| 26 | jobs: |
| 27 | create-stale-docs-issues: |
| 28 | name: Create or Update Issues for Stale Documentation |
| 29 | runs-on: ubuntu-latest |
| 30 | permissions: |
| 31 | contents: read |
| 32 | issues: write |
| 33 | steps: |
| 34 | - name: Checkout code |
| 35 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 |
| 36 | with: |
| 37 | persist-credentials: false |
| 38 | |
| 39 | - name: Download freshness check results |
| 40 | uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 41 | with: |
| 42 | name: ${{ inputs.artifact-name }} |
| 43 | path: logs |
| 44 | |
| 45 | - name: Create or Update Issues (One Per File) |
| 46 | shell: pwsh |
| 47 | env: |
| 48 | GH_TOKEN: ${{ github.token }} |
| 49 | RESULTS_FILE: ${{ inputs.results-file }} |
| 50 | THRESHOLD_DAYS: ${{ inputs.threshold-days }} |
| 51 | REPO: ${{ github.repository }} |
| 52 | SERVER_URL: ${{ github.server_url }} |
| 53 | RUN_ID: ${{ github.run_id }} |
| 54 | run: | |
| 55 | $results = Get-Content $env:RESULTS_FILE | ConvertFrom-Json |
| 56 | $staleFiles = $results | Where-Object { $_.IsStale -eq $true } |
| 57 | |
| 58 | if (-not $staleFiles) { |
| 59 | Write-Host "No stale files found, skipping issue creation" |
| 60 | exit 0 |
| 61 | } |
| 62 | |
| 63 | foreach ($file in $staleFiles) { |
| 64 | $filePath = $file.File |
| 65 | $msDate = $file.MsDate |
| 66 | $ageDays = $file.AgeDays |
| 67 | |
| 68 | $issueTitle = "docs: Update stale documentation - $filePath" |
| 69 | $automationMarker = "<!-- automation:stale-docs:$filePath -->" |
| 70 | |
| 71 | $searchQuery = "repo:$env:REPO is:issue is:open in:body `"automation:stale-docs:$filePath`"" |
| 72 | $existingIssueJson = gh issue list ` |
| 73 | --repo $env:REPO ` |
| 74 | --search $searchQuery ` |
| 75 | --limit 1 ` |
| 76 | --json number ` |
| 77 | --jq '.[0].number // empty' |
| 78 | |
| 79 | $existingIssue = if ($existingIssueJson) { $existingIssueJson.Trim() } else { $null } |
| 80 | |
| 81 | $issueBody = @" |
| 82 | ## Stale Documentation Detected |
| 83 | |
| 84 | **File:** ``$filePath`` |
| 85 | **Current ms.date:** ``$msDate`` |
| 86 | **Age:** $ageDays days (threshold: $env:THRESHOLD_DAYS days) |
| 87 | |
| 88 | --- |
| 89 | **Workflow Run:** $env:SERVER_URL/$env:REPO/actions/runs/$env:RUN_ID |
| 90 | **Detection Date:** $(Get-Date -Format 'yyyy-MM-dd' -AsUTC) |
| 91 | |
| 92 | ### Action Required |
| 93 | - [ ] Review and update this documentation file |
| 94 | - [ ] Update ``ms.date`` frontmatter to current date |
| 95 | - [ ] Verify technical accuracy of content |
| 96 | - [ ] Close this issue manually after fixes are merged |
| 97 | |
| 98 | $automationMarker |
| 99 | "@ |
| 100 | |
| 101 | if ($existingIssue) { |
| 102 | Write-Host "Updating existing issue #$existingIssue for $filePath" |
| 103 | gh issue edit $existingIssue ` |
| 104 | --repo $env:REPO ` |
| 105 | --body $issueBody |
| 106 | |
| 107 | $updateDate = Get-Date -Format 'yyyy-MM-dd' -AsUTC |
| 108 | gh issue comment $existingIssue ` |
| 109 | --repo $env:REPO ` |
| 110 | --body "🔄 **Weekly validation update:** Still stale ($ageDays days) as of $updateDate" |
| 111 | } else { |
| 112 | Write-Host "Creating new issue for $filePath" |
| 113 | gh issue create ` |
| 114 | --repo $env:REPO ` |
| 115 | --title $issueTitle ` |
| 116 | --body $issueBody ` |
| 117 | --label "documentation,stale-docs,automated,needs-triage" |
| 118 | } |
| 119 | } |