Skip to content

Commit 56f1082

Browse files
authored
Merge pull request #815 from dev-hato/develop
リリース
2 parents cca6dee + 1429863 commit 56f1082

28 files changed

Lines changed: 1764 additions & 418 deletions

.github/dependabot.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ updates:
1111
schedule:
1212
interval: "daily"
1313
open-pull-requests-limit: 1
14-
- package-ecosystem: docker
15-
directory: "/setup/pgsql"
16-
schedule:
17-
interval: "daily"
18-
open-pull-requests-limit: 1
1914
- package-ecosystem: github-actions
2015
directory: "/"
2116
schedule:

.github/linters/.hadolint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
---
22
ignored:
3-
- DL3018
3+
- DL3008

.github/linters/.sqlfluff

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[sqlfluff]
2+
dialect = postgres

.github/linters/.textlintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"filters": {},
33
"rules": {
44
"@textlint-ja/no-insert-dropping-sa": true,
5+
"@proofdict/proofdict": {
6+
"dictURL": "https://azu.github.io/proof-dictionary/"
7+
},
58
"abbr-within-parentheses": true,
69
"footnote-order": true,
710
"general-novel-style-ja": {
@@ -36,7 +39,6 @@
3639
"1.1.3.箇条書き": false,
3740
"4.3.1.丸かっこ()": false,
3841
"4.3.2.大かっこ[]": false
39-
},
40-
"spellcheck-tech-word": true
42+
}
4143
}
4244
}

.github/workflows/pr-check-yarn.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ jobs:
88
# package.jsonかyarn.lockに差分があれば、package.jsonからyarn.lockを作り出す
99
pr-check-yarn:
1010
runs-on: ubuntu-latest
11-
strategy:
12-
matrix:
13-
node-version: [16.x]
14-
fail-fast: false
1511

1612
steps:
1713
- uses: actions/checkout@v2
@@ -20,10 +16,11 @@ jobs:
2016
# submodule: 'recursive'
2117
fetch-depth: 0
2218
ref: ${{ github.event.pull_request.head.sha }}
23-
- name: Set up Node.js ${{ matrix.node-version }}
19+
- run: echo "NODE_VERSION=16" >> "${GITHUB_ENV}"
20+
- name: Set up Node.js ${{ env.NODE_VERSION }}
2421
uses: actions/setup-node@v2.5.1
2522
with:
26-
node-version: ${{ matrix.node-version }}
23+
node-version: ${{ env.NODE_VERSION }}
2724
cache: yarn
2825
- name: Install dependencies
2926
run: |
@@ -55,7 +52,7 @@ jobs:
5552
GITHUB_HEAD="HEAD:refs/heads/yarn-${HEAD_REF}"
5653
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
5754
- name: Get PullRequests
58-
uses: actions/github-script@v5
55+
uses: actions/github-script@v6
5956
env:
6057
HEAD_REF: ${{github.event.pull_request.head.ref}}
6158
if: ${{ env.REPO_NAME == github.repository
@@ -80,7 +77,7 @@ jobs:
8077
return pulls.length
8178
# pushしたブランチでPRを作る
8279
- name: Create PullRequest
83-
uses: actions/github-script@v5
80+
uses: actions/github-script@v6
8481
env:
8582
HEAD_REF: ${{github.event.pull_request.head.ref}}
8683
if: ${{ env.REPO_NAME == github.repository
@@ -110,7 +107,7 @@ jobs:
110107
)
111108
return create_pull_res.data.number
112109
- name: Assign a user
113-
uses: actions/github-script@v5
110+
uses: actions/github-script@v6
114111
if: ${{ env.REPO_NAME == github.repository
115112
&& steps.diff.outputs.result != ''
116113
&& steps.get_pull_requests.outputs.result == 0
@@ -130,7 +127,7 @@ jobs:
130127
# 既にpackage.json, yarn.lock修正のPRがある状態で、
131128
# 手動でpackage.json, yarn.lockを修正した場合、修正のPRを閉じる
132129
- name: Close PullRequest
133-
uses: actions/github-script@v5
130+
uses: actions/github-script@v6
134131
env:
135132
HEAD_REF: ${{github.event.pull_request.head.ref}}
136133
if: ${{ env.REPO_NAME == github.repository

.github/workflows/pr-copy-ci-hato-bot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
find hato-bot/${worklows_path} -type f \
3232
-not -name "*hato-bot.yml" \
3333
-exec cp {} "${DEST_PATH}" \;
34-
for f in .markdown-lint.yml .python-lint .python-lint
34+
for f in .markdown-lint.yml .python-lint .python-lint .textlintrc
3535
do
3636
cp hato-bot/.github/linters/${f} sudden-death/.github/linters/
3737
done
38-
for f in .gitleaks.toml .pre-commit-config.yaml package.json yarn.lock
38+
for f in .gitleaks.toml .pre-commit-config.yaml .python-version package.json yarn.lock
3939
do
4040
cp hato-bot/${f} sudden-death/
4141
done

.github/workflows/pr-docker-hato-bot.yml

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,10 @@ jobs:
4242
if: ${{ github.event_name == 'release' }}
4343
- name: Build docker image
4444
run: docker-compose build --build-arg BUILDKIT_INLINE_CACHE=1
45-
- name: Start docker
46-
run: docker-compose up -d
47-
# Dockerコンテナ立ち上げから2分以内に疎通できるようになるかテストする
48-
- name: Test
49-
run: |
50-
cmd="curl -XPOST -d '{\"message\": \"help\"}'"
51-
cmd+=" -H \"Content-Type: application/json\""
52-
cmd+=" http://localhost:3000/healthcheck"
53-
cmd_="${cmd} -w '%{http_code}' -o /dev/null -s"
54-
start_unixtime=$(date +%s)
55-
56-
while [ "$(echo "$(date +%s) - ${start_unixtime}" | bc)" -lt 120 ] \
57-
&& (! (docker-compose ps | grep -q Exit))
58-
do
59-
if [ "$(eval "${cmd_}")" = 200 ] && eval "${cmd}"
60-
then
61-
docker-compose logs
62-
exit 0
63-
fi
64-
65-
sleep 1
66-
done
67-
68-
docker-compose logs
69-
exit 1
7045
- run: docker-compose push
7146
- run: |
72-
for image in postgres hato-bot; do
73-
image_name="ghcr.io/dev-hato/hato-bot/${image}"
74-
latest_tag="${image_name}:latest"
75-
docker tag "${image_name}:${TAG_NAME}" "${latest_tag}"
76-
docker push "${latest_tag}"
77-
done
47+
image_name="ghcr.io/dev-hato/hato-bot/hato-bot"
48+
latest_tag="${image_name}:latest"
49+
docker tag "${image_name}:${TAG_NAME}" "${latest_tag}"
50+
docker push "${latest_tag}"
7851
if: ${{ github.event_name == 'release' }}

.github/workflows/pr-format.yml

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
---
2+
name: pr-format
3+
4+
# pull_requestで何かあった時に起動する
5+
on:
6+
pull_request:
7+
8+
jobs:
9+
# PRが来たらformatをかけてみて、差分があればPRを作って、エラーで落ちるjob
10+
pr-format:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
# ここでsubmodule持ってくるとdetached headにcommitして死ぬ
17+
# submodule: 'recursive'
18+
fetch-depth: 0
19+
ref: ${{ github.event.pull_request.head.sha }}
20+
- run: echo "PYTHON_VERSION=$(cat .python-version)" >> "${GITHUB_ENV}"
21+
- name: Set up Python ${{ env.PYTHON_VERSION }}
22+
uses: actions/setup-python@v2.3.2
23+
with:
24+
python-version: ${{env.PYTHON_VERSION }}
25+
cache: pipenv
26+
- name: Install pipenv
27+
id: install_pipenv
28+
continue-on-error: true
29+
run: |
30+
file_name=Dockerfile
31+
package_name=pipenv
32+
33+
if [ -f ${file_name} ]
34+
then
35+
PATTERN="${package_name}[^ ]+"
36+
package_name_with_version=$(grep -oE "${PATTERN}" ${file_name})
37+
else
38+
package_name_with_version=${package_name}
39+
fi
40+
41+
pip install ${package_name_with_version}
42+
43+
if [ -f ${file_name} ]
44+
then
45+
new_version="$(pip list --outdated | grep pipenv || true)"
46+
new_version="$(echo -e "${new_version}" | awk '{print $3}')"
47+
if [ -n "${new_version}" ]
48+
then
49+
PATTERN_BEFORE="${package_name}[^ ]+"
50+
PATTERN_AFTER="${package_name}==${new_version}"
51+
sed -i -E "s/${PATTERN_BEFORE}/${PATTERN_AFTER}/g" ${file_name}
52+
pip install "${package_name}==${new_version}"
53+
exit 1
54+
fi
55+
fi
56+
- name: pipenv version
57+
run: pipenv --version
58+
- name: Install dependencies
59+
run: |
60+
pipenv install --dev
61+
# autopep8でformatする
62+
# --exit-codeをつけることで、autopep8内でエラーが起きれば1、差分があれば2のエラーステータスコードが返ってくる。正常時は0が返る
63+
- name: Format files
64+
id: format
65+
run: |
66+
pipenv run autopep8 --exit-code --in-place --recursive .
67+
continue-on-error: true
68+
# 差分があったときは差分を出力する
69+
- name: Show diff
70+
if: ${{ steps.install_pipenv.outcome == 'failure'
71+
|| steps.format.outcome == 'failure' }}
72+
run: |
73+
git diff
74+
- run: |
75+
REPO_NAME="${{ github.event.pull_request.head.repo.full_name }}"
76+
echo "REPO_NAME=${REPO_NAME}" >> "${GITHUB_ENV}"
77+
# 差分があったときは、コミットを作りpushする
78+
- name: Push
79+
env:
80+
HEAD_REF: ${{github.event.pull_request.head.ref}}
81+
if: ${{ env.REPO_NAME == github.repository
82+
&& (steps.install_pipenv.outcome == 'failure'
83+
|| steps.format.outcome == 'failure') }}
84+
run: |
85+
git config user.name "github-actions[bot]"
86+
EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
87+
git config user.email "${EMAIL}"
88+
git add -u
89+
git commit -m "鳩は唐揚げ!(自動で直してあげたよ!)"
90+
REPO_URL="https://"
91+
REPO_URL+="${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/"
92+
REPO_URL+="${{github.repository}}.git"
93+
GITHUB_HEAD="HEAD:refs/heads/fix-format-${HEAD_REF}"
94+
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
95+
- name: Get PullRequests
96+
uses: actions/github-script@v6
97+
env:
98+
HEAD_REF: ${{github.event.pull_request.head.ref}}
99+
if: ${{ env.REPO_NAME == github.repository
100+
&& (steps.install_pipenv.outcome == 'failure'
101+
|| steps.format.outcome == 'failure') }}
102+
id: get_pull_requests
103+
with:
104+
github-token: ${{secrets.GITHUB_TOKEN}}
105+
script: |
106+
const HEAD_REF = process.env["HEAD_REF"]
107+
const pulls_list_params = {
108+
owner: context.repo.owner,
109+
repo: context.repo.repo,
110+
head: "dev-hato:fix-format-" + HEAD_REF,
111+
base: HEAD_REF,
112+
state: "open"
113+
}
114+
console.log("call pulls.list:", pulls_list_params)
115+
const pulls = await github.paginate(github.rest.pulls.list,
116+
pulls_list_params)
117+
return pulls.length
118+
# pushしたブランチでPRを作る
119+
- name: Create PullRequest
120+
uses: actions/github-script@v6
121+
env:
122+
HEAD_REF: ${{github.event.pull_request.head.ref}}
123+
if: ${{ env.REPO_NAME == github.repository
124+
&& (steps.install_pipenv.outcome == 'failure'
125+
|| steps.format.outcome == 'failure')
126+
&& steps.get_pull_requests.outputs.result == 0 }}
127+
id: create_pull_request
128+
with:
129+
github-token: ${{secrets.GITHUB_TOKEN}}
130+
script: |
131+
const HEAD_REF = process.env["HEAD_REF"]
132+
const number = "#${{github.event.pull_request.number}}"
133+
let title = "formatが間違ってたので直してあげたよ!PRをマージしてね! "
134+
title += number
135+
const pulls_create_params = {
136+
owner: context.repo.owner,
137+
repo: context.repo.repo,
138+
head: "dev-hato:fix-format-" + HEAD_REF,
139+
base: HEAD_REF,
140+
title,
141+
body: "鳩の唐揚げおいしい!😋😋😋 " + number
142+
}
143+
console.log("call pulls.create:", pulls_create_params)
144+
const create_pull_res = await github.rest.pulls.create(
145+
pulls_create_params
146+
)
147+
return create_pull_res.data.number
148+
- name: Assign a user
149+
uses: actions/github-script@v6
150+
if: ${{ env.REPO_NAME == github.repository
151+
&& (steps.install_pipenv.outcome == 'failure'
152+
|| steps.format.outcome == 'failure')
153+
&& steps.get_pull_requests.outputs.result == 0
154+
&& github.event.pull_request.user.login != 'dependabot[bot]' }}
155+
with:
156+
github-token: ${{secrets.GITHUB_TOKEN}}
157+
script: |
158+
const issues_add_assignees_params = {
159+
owner: context.repo.owner,
160+
repo: context.repo.repo,
161+
issue_number: ${{steps.create_pull_request.outputs.result}},
162+
assignees: ["${{github.event.pull_request.user.login}}"]
163+
}
164+
console.log("call issues.addAssignees:")
165+
console.log(issues_add_assignees_params)
166+
await github.rest.issues.addAssignees(issues_add_assignees_params)
167+
# 既にformat修正のPRがある状態で、手動でformatを修正した場合、format修正のPRを閉じる
168+
- name: Close PullRequest
169+
uses: actions/github-script@v6
170+
env:
171+
HEAD_REF: ${{github.event.pull_request.head.ref}}
172+
if: ${{ env.REPO_NAME == github.repository
173+
&& (steps.install_pipenv.outcome != 'failure'
174+
&& steps.format.outcome != 'failure') }}
175+
with:
176+
github-token: ${{secrets.GITHUB_TOKEN}}
177+
script: |
178+
const HEAD_REF = process.env["HEAD_REF"]
179+
const head_name = "fix-format-" + HEAD_REF
180+
const common_params = {
181+
owner: context.repo.owner,
182+
repo: context.repo.repo
183+
}
184+
const pulls_list_params = {
185+
head: "dev-hato:" + head_name,
186+
base: HEAD_REF,
187+
state: "open",
188+
...common_params
189+
}
190+
console.log("call pulls.list:", pulls_list_params)
191+
const pulls = await github.paginate(github.rest.pulls.list,
192+
pulls_list_params)
193+
194+
for(const data of pulls) {
195+
const pulls_update_params = {
196+
pull_number: data.number,
197+
state: "closed",
198+
...common_params
199+
}
200+
console.log("call pulls.update:", pulls_update_params)
201+
await github.rest.pulls.update(pulls_update_params)
202+
const git_deleteRef_params = {
203+
ref: "heads/" + head_name,
204+
...common_params
205+
}
206+
console.log("call git.deleteRef:", git_deleteRef_params)
207+
await github.rest.git.deleteRef(git_deleteRef_params)
208+
}
209+
- name: Exit
210+
if: ${{ steps.install_pipenv.outcome == 'failure'
211+
|| steps.format.outcome == 'failure' }}
212+
run: exit 1

.github/workflows/pr-merge-develop-hato-bot.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ jobs:
1111
# masterとdevelopの間でコミットログに差異が出ないようにする
1212
pr-master-to-develop:
1313
runs-on: ubuntu-latest
14-
strategy:
15-
matrix:
16-
python-version: [3.9]
1714

1815
steps:
1916
- uses: actions/checkout@v2
2017
with:
2118
fetch-depth: 0
2219
- name: Get PullRequests
23-
uses: actions/github-script@v5
20+
uses: actions/github-script@v6
2421
id: get_pull_requests
2522
with:
2623
github-token: ${{secrets.GITHUB_TOKEN}}
@@ -37,7 +34,7 @@ jobs:
3734
pulls_list_params)
3835
return pulls.length
3936
- name: Create PullRequest
40-
uses: actions/github-script@v5
37+
uses: actions/github-script@v6
4138
if: ${{ steps.get_pull_requests.outputs.result == 0 }}
4239
with:
4340
github-token: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)