Skip to content

Commit

Permalink
Merge pull request #815 from dev-hato/develop
Browse files Browse the repository at this point in the history
リリース
  • Loading branch information
nakkaa authored Feb 23, 2022
2 parents cca6dee + 1429863 commit 56f1082
Show file tree
Hide file tree
Showing 28 changed files with 1,764 additions and 418 deletions.
5 changes: 0 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ updates:
schedule:
interval: "daily"
open-pull-requests-limit: 1
- package-ecosystem: docker
directory: "/setup/pgsql"
schedule:
interval: "daily"
open-pull-requests-limit: 1
- package-ecosystem: github-actions
directory: "/"
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/linters/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
ignored:
- DL3018
- DL3008
2 changes: 2 additions & 0 deletions .github/linters/.sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[sqlfluff]
dialect = postgres
6 changes: 4 additions & 2 deletions .github/linters/.textlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"filters": {},
"rules": {
"@textlint-ja/no-insert-dropping-sa": true,
"@proofdict/proofdict": {
"dictURL": "https://azu.github.io/proof-dictionary/"
},
"abbr-within-parentheses": true,
"footnote-order": true,
"general-novel-style-ja": {
Expand Down Expand Up @@ -36,7 +39,6 @@
"1.1.3.箇条書き": false,
"4.3.1.丸かっこ()": false,
"4.3.2.大かっこ[]": false
},
"spellcheck-tech-word": true
}
}
}
17 changes: 7 additions & 10 deletions .github/workflows/pr-check-yarn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ jobs:
# package.jsonかyarn.lockに差分があれば、package.jsonからyarn.lockを作り出す
pr-check-yarn:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
fail-fast: false

steps:
- uses: actions/checkout@v2
Expand All @@ -20,10 +16,11 @@ jobs:
# submodule: 'recursive'
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Node.js ${{ matrix.node-version }}
- run: echo "NODE_VERSION=16" >> "${GITHUB_ENV}"
- name: Set up Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v2.5.1
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- name: Install dependencies
run: |
Expand Down Expand Up @@ -55,7 +52,7 @@ jobs:
GITHUB_HEAD="HEAD:refs/heads/yarn-${HEAD_REF}"
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
- name: Get PullRequests
uses: actions/github-script@v5
uses: actions/github-script@v6
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
Expand All @@ -80,7 +77,7 @@ jobs:
return pulls.length
# pushしたブランチでPRを作る
- name: Create PullRequest
uses: actions/github-script@v5
uses: actions/github-script@v6
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
Expand Down Expand Up @@ -110,7 +107,7 @@ jobs:
)
return create_pull_res.data.number
- name: Assign a user
uses: actions/github-script@v5
uses: actions/github-script@v6
if: ${{ env.REPO_NAME == github.repository
&& steps.diff.outputs.result != ''
&& steps.get_pull_requests.outputs.result == 0
Expand All @@ -130,7 +127,7 @@ jobs:
# 既にpackage.json, yarn.lock修正のPRがある状態で、
# 手動でpackage.json, yarn.lockを修正した場合、修正のPRを閉じる
- name: Close PullRequest
uses: actions/github-script@v5
uses: actions/github-script@v6
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-copy-ci-hato-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
find hato-bot/${worklows_path} -type f \
-not -name "*hato-bot.yml" \
-exec cp {} "${DEST_PATH}" \;
for f in .markdown-lint.yml .python-lint .python-lint
for f in .markdown-lint.yml .python-lint .python-lint .textlintrc
do
cp hato-bot/.github/linters/${f} sudden-death/.github/linters/
done
for f in .gitleaks.toml .pre-commit-config.yaml package.json yarn.lock
for f in .gitleaks.toml .pre-commit-config.yaml .python-version package.json yarn.lock
do
cp hato-bot/${f} sudden-death/
done
Expand Down
35 changes: 4 additions & 31 deletions .github/workflows/pr-docker-hato-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,10 @@ jobs:
if: ${{ github.event_name == 'release' }}
- name: Build docker image
run: docker-compose build --build-arg BUILDKIT_INLINE_CACHE=1
- name: Start docker
run: docker-compose up -d
# Dockerコンテナ立ち上げから2分以内に疎通できるようになるかテストする
- name: Test
run: |
cmd="curl -XPOST -d '{\"message\": \"help\"}'"
cmd+=" -H \"Content-Type: application/json\""
cmd+=" http://localhost:3000/healthcheck"
cmd_="${cmd} -w '%{http_code}' -o /dev/null -s"
start_unixtime=$(date +%s)
while [ "$(echo "$(date +%s) - ${start_unixtime}" | bc)" -lt 120 ] \
&& (! (docker-compose ps | grep -q Exit))
do
if [ "$(eval "${cmd_}")" = 200 ] && eval "${cmd}"
then
docker-compose logs
exit 0
fi
sleep 1
done
docker-compose logs
exit 1
- run: docker-compose push
- run: |
for image in postgres hato-bot; do
image_name="ghcr.io/dev-hato/hato-bot/${image}"
latest_tag="${image_name}:latest"
docker tag "${image_name}:${TAG_NAME}" "${latest_tag}"
docker push "${latest_tag}"
done
image_name="ghcr.io/dev-hato/hato-bot/hato-bot"
latest_tag="${image_name}:latest"
docker tag "${image_name}:${TAG_NAME}" "${latest_tag}"
docker push "${latest_tag}"
if: ${{ github.event_name == 'release' }}
212 changes: 212 additions & 0 deletions .github/workflows/pr-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
---
name: pr-format

# pull_requestで何かあった時に起動する
on:
pull_request:

jobs:
# PRが来たらformatをかけてみて、差分があればPRを作って、エラーで落ちるjob
pr-format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
# ここでsubmodule持ってくるとdetached headにcommitして死ぬ
# submodule: 'recursive'
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- run: echo "PYTHON_VERSION=$(cat .python-version)" >> "${GITHUB_ENV}"
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v2.3.2
with:
python-version: ${{env.PYTHON_VERSION }}
cache: pipenv
- name: Install pipenv
id: install_pipenv
continue-on-error: true
run: |
file_name=Dockerfile
package_name=pipenv
if [ -f ${file_name} ]
then
PATTERN="${package_name}[^ ]+"
package_name_with_version=$(grep -oE "${PATTERN}" ${file_name})
else
package_name_with_version=${package_name}
fi
pip install ${package_name_with_version}
if [ -f ${file_name} ]
then
new_version="$(pip list --outdated | grep pipenv || true)"
new_version="$(echo -e "${new_version}" | awk '{print $3}')"
if [ -n "${new_version}" ]
then
PATTERN_BEFORE="${package_name}[^ ]+"
PATTERN_AFTER="${package_name}==${new_version}"
sed -i -E "s/${PATTERN_BEFORE}/${PATTERN_AFTER}/g" ${file_name}
pip install "${package_name}==${new_version}"
exit 1
fi
fi
- name: pipenv version
run: pipenv --version
- name: Install dependencies
run: |
pipenv install --dev
# autopep8でformatする
# --exit-codeをつけることで、autopep8内でエラーが起きれば1、差分があれば2のエラーステータスコードが返ってくる。正常時は0が返る
- name: Format files
id: format
run: |
pipenv run autopep8 --exit-code --in-place --recursive .
continue-on-error: true
# 差分があったときは差分を出力する
- name: Show diff
if: ${{ steps.install_pipenv.outcome == 'failure'
|| steps.format.outcome == 'failure' }}
run: |
git diff
- run: |
REPO_NAME="${{ github.event.pull_request.head.repo.full_name }}"
echo "REPO_NAME=${REPO_NAME}" >> "${GITHUB_ENV}"
# 差分があったときは、コミットを作りpushする
- name: Push
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
&& (steps.install_pipenv.outcome == 'failure'
|| steps.format.outcome == 'failure') }}
run: |
git config user.name "github-actions[bot]"
EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
git config user.email "${EMAIL}"
git add -u
git commit -m "鳩は唐揚げ!(自動で直してあげたよ!)"
REPO_URL="https://"
REPO_URL+="${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/"
REPO_URL+="${{github.repository}}.git"
GITHUB_HEAD="HEAD:refs/heads/fix-format-${HEAD_REF}"
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
- name: Get PullRequests
uses: actions/github-script@v6
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
&& (steps.install_pipenv.outcome == 'failure'
|| steps.format.outcome == 'failure') }}
id: get_pull_requests
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const HEAD_REF = process.env["HEAD_REF"]
const pulls_list_params = {
owner: context.repo.owner,
repo: context.repo.repo,
head: "dev-hato:fix-format-" + HEAD_REF,
base: HEAD_REF,
state: "open"
}
console.log("call pulls.list:", pulls_list_params)
const pulls = await github.paginate(github.rest.pulls.list,
pulls_list_params)
return pulls.length
# pushしたブランチでPRを作る
- name: Create PullRequest
uses: actions/github-script@v6
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
&& (steps.install_pipenv.outcome == 'failure'
|| steps.format.outcome == 'failure')
&& steps.get_pull_requests.outputs.result == 0 }}
id: create_pull_request
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const HEAD_REF = process.env["HEAD_REF"]
const number = "#${{github.event.pull_request.number}}"
let title = "formatが間違ってたので直してあげたよ!PRをマージしてね! "
title += number
const pulls_create_params = {
owner: context.repo.owner,
repo: context.repo.repo,
head: "dev-hato:fix-format-" + HEAD_REF,
base: HEAD_REF,
title,
body: "鳩の唐揚げおいしい!😋😋😋 " + number
}
console.log("call pulls.create:", pulls_create_params)
const create_pull_res = await github.rest.pulls.create(
pulls_create_params
)
return create_pull_res.data.number
- name: Assign a user
uses: actions/github-script@v6
if: ${{ env.REPO_NAME == github.repository
&& (steps.install_pipenv.outcome == 'failure'
|| steps.format.outcome == 'failure')
&& steps.get_pull_requests.outputs.result == 0
&& github.event.pull_request.user.login != 'dependabot[bot]' }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issues_add_assignees_params = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{steps.create_pull_request.outputs.result}},
assignees: ["${{github.event.pull_request.user.login}}"]
}
console.log("call issues.addAssignees:")
console.log(issues_add_assignees_params)
await github.rest.issues.addAssignees(issues_add_assignees_params)
# 既にformat修正のPRがある状態で、手動でformatを修正した場合、format修正のPRを閉じる
- name: Close PullRequest
uses: actions/github-script@v6
env:
HEAD_REF: ${{github.event.pull_request.head.ref}}
if: ${{ env.REPO_NAME == github.repository
&& (steps.install_pipenv.outcome != 'failure'
&& steps.format.outcome != 'failure') }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const HEAD_REF = process.env["HEAD_REF"]
const head_name = "fix-format-" + HEAD_REF
const common_params = {
owner: context.repo.owner,
repo: context.repo.repo
}
const pulls_list_params = {
head: "dev-hato:" + head_name,
base: HEAD_REF,
state: "open",
...common_params
}
console.log("call pulls.list:", pulls_list_params)
const pulls = await github.paginate(github.rest.pulls.list,
pulls_list_params)
for(const data of pulls) {
const pulls_update_params = {
pull_number: data.number,
state: "closed",
...common_params
}
console.log("call pulls.update:", pulls_update_params)
await github.rest.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.rest.git.deleteRef(git_deleteRef_params)
}
- name: Exit
if: ${{ steps.install_pipenv.outcome == 'failure'
|| steps.format.outcome == 'failure' }}
run: exit 1
7 changes: 2 additions & 5 deletions .github/workflows/pr-merge-develop-hato-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ jobs:
# masterとdevelopの間でコミットログに差異が出ないようにする
pr-master-to-develop:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get PullRequests
uses: actions/github-script@v5
uses: actions/github-script@v6
id: get_pull_requests
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -37,7 +34,7 @@ jobs:
pulls_list_params)
return pulls.length
- name: Create PullRequest
uses: actions/github-script@v5
uses: actions/github-script@v6
if: ${{ steps.get_pull_requests.outputs.result == 0 }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand Down
Loading

0 comments on commit 56f1082

Please sign in to comment.