-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (78 loc) · 2.23 KB
/
lint-fix-in-pr.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Run lint auto fix on a PR
on:
issue_comment:
types: [created]
jobs:
lint-fix:
if: ${{ github.event.issue.pull_request && contains('!lint-fix', github.event.comment.body) }}
runs-on: ubuntu-latest
permissions:
id-token: write # Enable OIDC
pull-requests: write
contents: write
steps:
- name: Check that !lint-fix is at the start of a line
shell: node {0}
env:
COMMENT: ${{ github.event.comment.body }}
run: |
const matcher = /^!lint-fix/m;
const comment = process.env['COMMENT'];
if (!comment.match(matcher)) {
process.exit(1);
}
- name: Signal we're processing the comment
uses: actions/github-script@v4
with:
script: |
const {owner, repo} = context.issue
github.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "eyes",
});
- name: Get PR branch
id: branch
uses: actions/github-script@v4
with:
result-encoding: string
script: |
const {owner, repo, number} = context.issue;
const pr = await github.pulls.get({
owner,
repo,
pull_number: number,
});
return pr.data.head.ref;
- uses: actions/checkout@v4
with:
ref: ${{ steps.branch.outputs.result }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: chainguard-dev/actions/setup-gitsign@main
- name: Autolint
run: |
yarn install --frozen-lockfile
yarn lint-fix || true
- name: Commit and push
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git commit -am "fmt: automatic lint-fix"
git push
- name: Signal we're done
if: always()
uses: actions/github-script@v4
with:
script: |
const {owner, repo} = context.issue
github.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "rocket",
});