From 5441fadebd1f0ab7e3dccaf5811cc91df1f24359 Mon Sep 17 00:00:00 2001 From: Nathan Totten Date: Tue, 10 Feb 2026 08:51:02 -0500 Subject: [PATCH] Format only PR-changed files in web edit workflow Instead of running prettier on all **/*.md files, fetch the list of files changed in the PR via the GitHub API and format only those. This broadens formatting to all file types prettier supports while keeping the scope limited to what the PR actually touches. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/format.yaml | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/format.yaml diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 000000000..4b54fc54a --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,92 @@ +name: Format (Web Edits) + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: write + pull-requests: write + +jobs: + format: + # Only attempt to push if the PR branch is in the same repo (not a fork) + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: ubuntu-latest + + steps: + - name: Detect if PR contains Web UI commits + id: webui + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const pr = context.payload.pull_request.number; + + // List commits on the PR + const commits = await github.paginate( + github.rest.pulls.listCommits, + { owner, repo, pull_number: pr, per_page: 100 } + ); + + // GitHub web editor commits are typically committed by `web-flow` + const hasWebFlow = commits.some(c => c.committer?.login === "web-flow"); + + core.setOutput("is_webui", hasWebFlow ? "true" : "false"); + + - name: Checkout PR branch + if: ${{ steps.webui.outputs.is_webui == 'true' }} + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: 0 + + - name: Setup Node + if: ${{ steps.webui.outputs.is_webui == 'true' }} + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install deps + if: ${{ steps.webui.outputs.is_webui == 'true' }} + run: npm ci + + - name: Get changed files + if: ${{ steps.webui.outputs.is_webui == 'true' }} + id: changed + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const pr = context.payload.pull_request.number; + + const files = await github.paginate( + github.rest.pulls.listFiles, + { owner, repo, pull_number: pr, per_page: 100 } + ); + + // Only include added or modified files (not removed) + const paths = files + .filter(f => f.status !== "removed") + .map(f => f.filename); + + core.setOutput("files", paths.join("\n")); + + - name: Format changed files + if: ${{ steps.webui.outputs.is_webui == 'true' && steps.changed.outputs.files != '' }} + run: | + echo "${{ steps.changed.outputs.files }}" | xargs npx prettier --write --ignore-unknown + + - name: Commit & push (only if changes) + if: ${{ steps.webui.outputs.is_webui == 'true' }} + run: | + if git diff --quiet; then + echo "No changes." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m "chore: format files (web UI PR)" + git push