-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #815 from dev-hato/develop
リリース
- Loading branch information
Showing
28 changed files
with
1,764 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
--- | ||
ignored: | ||
- DL3018 | ||
- DL3008 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[sqlfluff] | ||
dialect = postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.