DOCS-404: follow-up Gateway UI visibility and manage-path clarifications #132
Workflow file for this run
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
| name: ReadMe Docs Constraints | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - edited | |
| - ready_for_review | |
| paths: | |
| - "docs/**/*.md" | |
| - ".github/scripts/check_readme_docs_constraints.py" | |
| - ".github/workflows/readme-docs-constraints.yml" | |
| workflow_dispatch: | |
| jobs: | |
| validate-readme-docs-constraints: | |
| if: github.event_name != 'pull_request' || github.event.pull_request.draft == false | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Setup Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Collect changed PR files | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const files = await github.paginate( | |
| github.rest.pulls.listFiles, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number, | |
| per_page: 100, | |
| } | |
| ); | |
| fs.mkdirSync('.github/automation-reports', { recursive: true }); | |
| fs.writeFileSync( | |
| '.github/automation-reports/readme-constraints-pr-files.json', | |
| JSON.stringify( | |
| files.map((file) => ({ | |
| filename: file.filename, | |
| status: file.status, | |
| previous_filename: file.previous_filename || '', | |
| })), | |
| null, | |
| 2 | |
| ) | |
| ); | |
| - name: Create fallback changed files list for manual runs | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| mkdir -p .github/automation-reports | |
| echo '[]' > .github/automation-reports/readme-constraints-pr-files.json | |
| - name: Validate ReadMe docs constraints | |
| id: validate | |
| run: | | |
| python .github/scripts/check_readme_docs_constraints.py \ | |
| --docs-root docs \ | |
| --changed-files-json .github/automation-reports/readme-constraints-pr-files.json \ | |
| --max-depth 3 \ | |
| --out-json .github/automation-reports/readme-constraints-report.json \ | |
| --out-md .github/automation-reports/readme-constraints-report.md | |
| - name: Add or update PR comment | |
| if: always() && github.event_name == 'pull_request' | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const marker = '<!-- readme-docs-constraints-comment -->'; | |
| const reportPath = '.github/automation-reports/readme-constraints-report.md'; | |
| const reportJsonPath = '.github/automation-reports/readme-constraints-report.json'; | |
| if (!fs.existsSync(reportPath) || !fs.existsSync(reportJsonPath)) { | |
| core.info('ReadMe constraints report was not produced; skipping PR comment update.'); | |
| return; | |
| } | |
| const report = fs.readFileSync(reportPath, 'utf8').trim(); | |
| const reportJson = JSON.parse(fs.readFileSync(reportJsonPath, 'utf8')); | |
| const failed = Boolean(reportJson.failed); | |
| const comments = await github.paginate( | |
| github.rest.issues.listComments, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| per_page: 100, | |
| } | |
| ); | |
| const existing = comments.find((comment) => comment.body && comment.body.includes(marker)); | |
| if (!failed) { | |
| if (existing) { | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| }); | |
| core.info('Removed stale ReadMe constraints comment because no violations were detected.'); | |
| } else { | |
| core.info('No ReadMe constraints violations detected; no PR comment to add.'); | |
| } | |
| return; | |
| } | |
| const heading = '### ReadMe docs constraints failed'; | |
| const summary = 'This pull request cannot be merged until the violations below are resolved.'; | |
| const body = `${marker}\n${heading}\n\n${summary}\n\n${report}\n`; | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body, | |
| }); | |
| } | |
| - name: Upload constraint reports | |
| if: always() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: readme-docs-constraints-report | |
| path: | | |
| .github/automation-reports/readme-constraints-pr-files.json | |
| .github/automation-reports/readme-constraints-report.json | |
| .github/automation-reports/readme-constraints-report.md |