|
| 1 | +name: Readability report |
| 2 | + |
| 3 | +# **What it does**: Analyzes readability of rendered content for changed Markdown files in pull requests |
| 4 | +# **Why we have it**: We want to track and improve the readability of our documentation over time |
| 5 | +# **Who does it impact**: Contributors and content writers |
| 6 | + |
| 7 | +on: |
| 8 | + # pull_request: |
| 9 | + # paths: |
| 10 | + # - 'content/**/*.md' |
| 11 | + # - 'data/reusables/**/*.md' |
| 12 | + # The pull_request trigger is currently disabled for testing purposes. |
| 13 | + # Re-enable this trigger when ready to run readability analysis automatically on PRs. |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + pull_request_number: |
| 17 | + description: 'Pull request number to analyze (for testing)' |
| 18 | + required: true |
| 19 | + type: number |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + pull-requests: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + readability-analysis: |
| 27 | + if: github.repository == 'github/docs-internal' |
| 28 | + runs-on: ${{ fromJSON('["ubuntu-latest", "ubuntu-20.04-xl"]')[github.repository == 'github/docs-internal'] }} |
| 29 | + steps: |
| 30 | + - name: Check out repo with full history |
| 31 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Checkout PR for manual dispatch |
| 36 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 37 | + run: | |
| 38 | + gh pr checkout ${{ inputs.pull_request_number }} |
| 39 | + env: |
| 40 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - uses: ./.github/actions/node-npm-setup |
| 43 | + |
| 44 | + - uses: ./.github/actions/get-docs-early-access |
| 45 | + if: ${{ github.repository == 'github/docs-internal' }} |
| 46 | + with: |
| 47 | + token: ${{ secrets.DOCS_BOT_PAT_BASE }} |
| 48 | + |
| 49 | + - name: Get changed content files |
| 50 | + id: changed_files |
| 51 | + uses: ./.github/actions/get-changed-files |
| 52 | + with: |
| 53 | + files: 'content/**/*.md' |
| 54 | + # For workflow_dispatch, compare against main |
| 55 | + base: ${{ github.event_name == 'workflow_dispatch' && 'main' || '' }} |
| 56 | + |
| 57 | + - name: Disable Next.js telemetry |
| 58 | + run: npx next telemetry disable |
| 59 | + |
| 60 | + - name: Start server in the background |
| 61 | + if: ${{ steps.changed_files.outputs.filtered_changed_files }} |
| 62 | + run: npm start > /tmp/stdout.log 2> /tmp/stderr.log & |
| 63 | + |
| 64 | + - name: Run readability analysis |
| 65 | + if: ${{ steps.changed_files.outputs.filtered_changed_files }} |
| 66 | + env: |
| 67 | + CHANGED_FILES: ${{ steps.changed_files.outputs.filtered_changed_files }} |
| 68 | + run: npm run readability-report |
| 69 | + |
| 70 | + - name: Find existing readability comment |
| 71 | + if: ${{ steps.changed_files.outputs.filtered_changed_files }} |
| 72 | + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e |
| 73 | + id: findComment |
| 74 | + with: |
| 75 | + issue-number: ${{ github.event_name == 'workflow_dispatch' && inputs.pull_request_number || github.event.number }} |
| 76 | + comment-author: 'github-actions[bot]' |
| 77 | + body-includes: '<!-- READABILITY_REPORT -->' |
| 78 | + |
| 79 | + - name: Read readability report |
| 80 | + if: ${{ steps.changed_files.outputs.filtered_changed_files }} |
| 81 | + id: read_report |
| 82 | + run: | |
| 83 | + if [ -f "readability-report.md" ]; then |
| 84 | + { |
| 85 | + echo 'report<<EOF' |
| 86 | + cat readability-report.md |
| 87 | + echo EOF |
| 88 | + } >> "$GITHUB_OUTPUT" |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Create or update readability comment |
| 92 | + if: ${{ steps.changed_files.outputs.filtered_changed_files && steps.read_report.outputs.report }} |
| 93 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 |
| 94 | + with: |
| 95 | + comment-id: ${{ steps.findComment.outputs.comment-id }} |
| 96 | + issue-number: ${{ github.event_name == 'workflow_dispatch' && inputs.pull_request_number || github.event.number }} |
| 97 | + body: | |
| 98 | + <!-- READABILITY_REPORT --> |
| 99 | + ${{ steps.read_report.outputs.report }} |
| 100 | + edit-mode: replace |
| 101 | + |
| 102 | + - if: ${{ failure() }} |
| 103 | + name: Debug server outputs on errors |
| 104 | + run: | |
| 105 | + echo "____STDOUT____" |
| 106 | + cat /tmp/stdout.log || echo "No stdout log found" |
| 107 | + echo "____STDERR____" |
| 108 | + cat /tmp/stderr.log || echo "No stderr log found" |
0 commit comments