-
-
Notifications
You must be signed in to change notification settings - Fork 19
232 lines (224 loc) · 9.54 KB
/
textlint.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: textlint CI
# pull_requestで何かあった時に起動する
on:
pull_request:
jobs:
# textlintをかけ、結果をPRにコメントとして表示する。
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.x ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1.4.4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
npm install -g textlint \
textlint-rule-abbr-within-parentheses \
textlint-rule-footnote-order \
textlint-rule-general-novel-style-ja \
textlint-rule-ja-hiragana-hojodoushi \
textlint-rule-ja-hiragana-keishikimeishi \
textlint-rule-ja-unnatural-alphabet \
textlint-rule-ng-word \
textlint-rule-no-dead-link \
textlint-rule-no-mixed-zenkaku-and-hankaku-alphabet \
textlint-rule-prefer-tari-tari \
textlint-rule-preset-ja-spacing \
textlint-rule-preset-ja-technical-writing \
textlint-rule-preset-jtf-style \
@proofdict/textlint-rule-proofdict \
@textlint-ja/textlint-rule-no-insert-dropping-sa
# lintする
- name: Lint files
id: lint
run: |
result="$(textlint *.md && textlint doc/*.md && textlint batch/*.md && textlint tools/*.md 2>&1)" || true
echo "$result"
result="${result//'%'/'%25'}"
result="${result//$'\n'/'%0A'}"
result="${result//$'\r'/'%0D'}"
echo "::set-output name=result::$result"
true
continue-on-error: true
# lint結果をコメントに残す
- name: Lint Comment
if: github.event.pull_request.head.repo.full_name == github.repository && steps.lint.outputs.result != ''
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issues_listComments_params = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
}
console.log("call issues.listComments:", issues_listComments_params)
const issue_comments = (await github.paginate(github.issues.listComments, issues_listComments_params)).filter(
issue_comment => issue_comment.user.id==41898282 && issue_comment.body.startsWith('日本語の')
)
for (const issue_comment of issue_comments) {
const issues_deleteComment_params = {
comment_id: issue_comment.id,
owner: context.repo.owner,
repo: context.repo.repo
}
console.log("call issues.deleteComment:", issues_deleteComment_params)
await github.issues.deleteComment(issues_deleteComment_params)
}
const result = `${{steps.lint.outputs.result}}`
const issues_createComment_params = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "日本語のLint結果\n```\n"+result+"\n```"
}
console.log("call issues.createComment:", issues_createComment_params)
await github.issues.createComment(issues_createComment_params)
- name: Exit
if: github.event.pull_request.head.repo.full_name != github.repository && steps.lint.outcome == 'failure'
run: exit 1
# PRが来たらtextlintをかけてみて、差分があればPRを作って、エラーで落ちるjob
format:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
strategy:
matrix:
node-version: [ 16.x ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1.4.4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
npm install -g textlint \
textlint-rule-abbr-within-parentheses \
textlint-rule-footnote-order \
textlint-rule-general-novel-style-ja \
textlint-rule-ja-hiragana-hojodoushi \
textlint-rule-ja-hiragana-keishikimeishi \
textlint-rule-ja-unnatural-alphabet \
textlint-rule-ng-word \
textlint-rule-no-dead-link \
textlint-rule-no-mixed-zenkaku-and-hankaku-alphabet \
textlint-rule-prefer-tari-tari \
textlint-rule-preset-ja-spacing \
textlint-rule-preset-ja-technical-writing \
textlint-rule-preset-jtf-style \
@proofdict/textlint-rule-proofdict \
@textlint-ja/textlint-rule-no-insert-dropping-sa
# textlintでformatする
- name: Format files
id: format
run: |
textlint --fix *.md
textlint --fix doc/*.md
textlint --fix batch/*.md
textlint --fix tools/*.md
continue-on-error: true
# 差分があったときは差分を出力する
- name: Show diff
id: show_diff
run: |
echo "::set-output name=diff::$(git diff)"
# 差分があったときは、コミットを作りpushする
- name: Push
if: steps.show_diff.outputs.diff != ''
run: |
git config user.name "textlint CI"
git config user.email "textlint_ci@example.com"
git add -u
git commit -m "日本語修正"
git push -f https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:refs/heads/fix-text-${{github.event.pull_request.head.ref}}
- name: Get PullRequests
uses: actions/github-script@v3
if: steps.show_diff.outputs.diff != ''
id: get_pull_requests
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pulls_list_params = {
owner: context.repo.owner,
repo: context.repo.repo,
head: "kujirahand:fix-text-${{github.event.pull_request.head.ref}}",
base: "${{github.event.pull_request.head.ref}}",
state: "open"
}
console.log("call pulls.list:", pulls_list_params)
const pulls = await github.paginate(github.pulls.list, pulls_list_params)
return pulls.length
# pushしたブランチでPRを作る
- name: Create PullRequest
uses: actions/github-script@v3
if: steps.show_diff.outputs.diff != '' && steps.get_pull_requests.outputs.result == 0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const common_params = {
owner: context.repo.owner,
repo: context.repo.repo
}
const pulls_create_params = {
head: "kujirahand:fix-text-${{github.event.pull_request.head.ref}}",
base: "${{github.event.pull_request.head.ref}}",
title: "日本語修正 (修正する場合はPRをマージしてください) #${{github.event.pull_request.number}}",
body: "日本語を修正しました。本PRをマージすると #${{github.event.pull_request.number}} に修正が適用されます。",
...common_params
}
console.log("call pulls.create:", pulls_create_params)
const create_pull_res = (await github.pulls.create(pulls_create_params)).data
const issues_add_assignees_params = {
issue_number: create_pull_res.number,
assignees: ["${{github.event.pull_request.user.login}}"],
...common_params
}
console.log("call issues.addAssignees:", issues_add_assignees_params)
await github.issues.addAssignees(issues_add_assignees_params)
# 既にformat修正のPRがある状態で、手動でformatを修正した場合、format修正のPRを閉じる
- name: Close PullRequest
uses: actions/github-script@v3
if: steps.show_diff.outputs.diff == ''
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const head_name = "fix-text-${{github.event.pull_request.head.ref}}"
const common_params = {
owner: context.repo.owner,
repo: context.repo.repo
}
const pulls_list_params = {
head: "kujirahand:" + head_name,
base: "${{github.event.pull_request.head.ref}}",
state: "open",
...common_params
}
console.log("call pulls.list:", pulls_list_params)
const pulls = await github.paginate(github.pulls.list,pulls_list_params)
for (const pull of pulls) {
const pulls_update_params = {
pull_number: pull.number,
state: "closed",
...common_params
}
console.log("call pulls.update:", pulls_update_params)
await github.pulls.update(pulls_update_params)
const git_deleteRef_params = {
ref: "heads/" + head_name,
...common_params
}
console.log("call git.deleteRef:", git_deleteRef_params)
await github.git.deleteRef(git_deleteRef_params)
}
- name: Exit
if: steps.show_diff.outputs.diff != ''
run: exit 1