-
Notifications
You must be signed in to change notification settings - Fork 2.3k
56 lines (54 loc) · 1.84 KB
/
prettier-auto-fix.yml
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
name: Auto Fix Formatting
on:
issue_comment:
types:
- created
pull_request:
types:
- labeled
jobs:
auto-fix-formatting:
if: >
(github.event.issue.pull_request && (
contains(github.event.comment.body, 'auto fix prettier') ||
contains(github.event.comment.body, 'auto fix fmt') ||
contains(github.event.comment.body, 'auto fix formatting') ||
contains(github.event.comment.body, 'auto fix format')
)) ||
(github.event.label.name == 'fmt/auto-fix')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -B ${GITHUB_HEAD_REF}
- name: Run prettier to format the code
run: pnpm run fmt
- name: Commit and push changes
run: |
git commit -am "Auto-fix formatting issues"
git push --set-upstream origin ${{ env.BRANCH_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
- name: Remove "fmt/auto-fix" label if exists
if: github.event_name == 'pull_request'
env:
REPO_NAME: ${{ github.repository }}
run: |
curl \
-X DELETE \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$REPO_NAME/issues/$PR_ID/labels/fmt/auto-fix"