Update moss-state-management.mdx #19
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: Harper (grammar suggestions) | |
| on: | |
| pull_request: | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| harper: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Harper | |
| run: | | |
| curl -fsSL https://raw.githubusercontent.com/automattic/harper/main/install.sh | sh | |
| echo "$HOME/.harper/bin" >> $GITHUB_PATH | |
| - name: Run Harper on changed md/mdx | |
| id: harper | |
| run: | | |
| set -euo pipefail | |
| mapfile -t FILES < <( | |
| git diff --name-only origin/${{ github.base_ref }}...${{ github.sha }} \ | |
| -- '*.md' '*.mdx' || true | |
| ) | |
| if [ ${#FILES[@]} -eq 0 ]; then | |
| echo "No markdown files changed." > harper.txt | |
| exit 0 | |
| fi | |
| { | |
| echo "## Harper grammar suggestions" | |
| echo | |
| for f in "${FILES[@]}"; do | |
| [ -f "$f" ] || continue | |
| echo "### $f" | |
| harper "$f" || true | |
| echo | |
| done | |
| } > harper.txt | |
| - name: Post PR comment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require("fs"); | |
| const body = fs.readFileSync("harper.txt", "utf8").trim(); | |
| const marker = "<!-- harper-report -->"; | |
| const commentBody = `${marker}\n${body || "No issues found."}`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existing = comments.find(c => | |
| c.body && c.body.includes(marker) | |
| ); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body: commentBody, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: commentBody, | |
| }); | |
| } |