@@ -107,14 +107,74 @@ jobs:
107107 python -m pip install --upgrade pip
108108 pip install pipenv
109109 pipenv install --dev
110+ - name : Set .env
111+ run : |
112+ cp .env.example .env
110113 - name : Test
111114 run : |
112115 pipenv run python -m unittest
113116
117+ # 型ヒントのチェックを行う
118+ pr-type-hint :
119+ runs-on : ubuntu-latest
120+ strategy :
121+ matrix :
122+ python-version : [3.8]
123+
124+ steps :
125+ - uses : actions/checkout@v2
126+ - name : pipenv cache
127+ uses : actions/cache@v1
128+ with :
129+ key : ${{ runner.os }}-${{ matrix.python-version }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
130+ path : ~/.cache/pipenv
131+ restore-keys : |
132+ ${{ runner.os }}-${{ matrix.python-version }}-pipenv-
133+ - name : pip cache
134+ uses : actions/cache@v1
135+ with :
136+ path : ~/.cache/pip
137+ key : ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
138+ restore-keys : |
139+ ${{ runner.os }}-pip-
140+ - name : Set up Python ${{ matrix.python-version }}
141+ uses : actions/setup-python@v1
142+ with :
143+ python-version : ${{ matrix.python-version }}
144+ - name : Install dependencies
145+ run : |
146+ python -m pip install --upgrade pip
147+ pip install pipenv
148+ pipenv install --dev
149+ - name : Check type hints
150+ run : |
151+ pipenv run mypy .
152+
153+ # 差分があるPythonファイルを取得する
154+ pr-check-python-files-with-diff :
155+ runs-on : ubuntu-latest
156+
157+ outputs :
158+ files : ${{steps.check-python-files-with-diff.outputs.files}}
159+
160+ steps :
161+ - uses : actions/checkout@v2
162+ with :
163+ fetch-depth : 0
164+ - name : Check Python file with diff
165+ id : check-python-files-with-diff
166+ run : |
167+ git fetch --no-tags --prune --depth=1 origin ${GITHUB_HEAD_REF}
168+ git fetch --no-tags --prune --depth=1 origin ${GITHUB_BASE_REF}
169+ echo "::set-output name=files::$(git diff origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} --diff-filter=AM --name-only -- '*.py' | tr '\n' ' ')"
170+
114171 # lintを行い、結果をPRにコメントとして表示する。
115172 # ここではチェックは落ちない
116173 pr-lint :
117174 runs-on : ubuntu-latest
175+ needs : pr-check-python-files-with-diff
176+ # Pythonファイルが差分に含まれていない場合はスキップ
177+ if : needs.pr-check-python-files-with-diff.outputs.files != ''
118178 strategy :
119179 matrix :
120180 python-version : [3.8]
@@ -151,9 +211,7 @@ jobs:
151211 - name : Lint files
152212 id : lint
153213 run : |
154- git fetch --no-tags --prune --depth=1 origin ${GITHUB_HEAD_REF}
155- git fetch --no-tags --prune --depth=1 origin ${GITHUB_BASE_REF}
156- result=$(pipenv run pylint --rcfile=./.pylintrc $(git diff origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} --diff-filter=AM --name-only -- '*.py') 2>&1) || true
214+ result=$(pipenv run pylint --rcfile=./.pylintrc ${{needs.pr-check-python-files-with-diff.outputs.files}} 2>&1) || true
157215 result="${result//'%'/'%25'}"
158216 result="${result//$'\n'/'%0A'}"
159217 result="${result//$'\r'/'%0D'}"
@@ -162,6 +220,7 @@ jobs:
162220 continue-on-error : true
163221 # lint結果をコメントに残す
164222 - name : Lint Comment
223+ if : steps.lint.outputs.result != ''
165224 uses : actions/github-script@0.9.0
166225 with :
167226 github-token : ${{secrets.GITHUB_TOKEN}}
0 commit comments