-
Notifications
You must be signed in to change notification settings - Fork 52
73 lines (65 loc) · 2.95 KB
/
Copy pathformat-command.yml
File metadata and controls
73 lines (65 loc) · 2.95 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
66
67
68
69
70
71
72
73
name: format-command
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
id: auto_commit
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() && steps.auto_commit.outputs.changes_detected == 'true'
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: "All done! 💅 I've run Prettier and pushed the formatting fixes to this PR.\n\n**Just a heads up:** Since this commit was pushed by a bot, GitHub won't automatically re-run your CI checks. To trigger them, you can either:\n- Push an empty commit (`git commit --allow-empty -m \"Trigger builds\"` and push)\n- Close and immediately reopen this Pull Request."
})
- name: Post no-changes comment
if: success() && steps.auto_commit.outputs.changes_detected == 'false'
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: "Everything is beautifully formatted! ✨ No changes were needed."
})
- 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: `Oops, something went wrong while running Prettier! 🫠\n\nPlease check the [workflow logs](${runUrl}) to see what happened, or just run \`npx prettier --write .\` locally instead.`
})