-
Notifications
You must be signed in to change notification settings - Fork 51
65 lines (58 loc) · 2.71 KB
/
Copy pathformat-command.yml
File metadata and controls
65 lines (58 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: format-command
# This workflow no longer triggers on issue_comment directly. It only runs
# after .github/workflows/slash-command-dispatch.yml has verified that the
# commenter has write access to the repository and created a
# "format-command" repository_dispatch event. This removes the unauthenticated
# pwn-request path: untrusted commenters never reach this job.
on:
repository_dispatch:
types: [format-command]
jobs:
format:
name: "Format code via /format command"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Run Prettier
run: npx prettier --write .
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "style: auto-format code with Prettier (/format)"
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
- name: Post completion comment
if: success()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.payload.client_payload.github.payload.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "I have successfully run Prettier and pushed the formatting fixes to this PR.\n\n**Note for Contributors:** Because this commit was pushed by a bot, GitHub will not automatically re-run the CI checks. To trigger them to pass, you must either:\n- Push an empty commit locally (`git commit --allow-empty -m \"Trigger builds\"` and push)\n- Close and immediately reopen this Pull Request."
})
- name: Post failure comment
if: failure()
uses: actions/github-script@v7
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
github.rest.issues.createComment({
issue_number: context.payload.client_payload.github.payload.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `I tried to run Prettier on this PR but the run failed. Please check the [workflow logs](${runUrl}) or run \`npx prettier --write .\` locally instead.`
})