Skip to content

Commit

Permalink
Run the linter on CloudBuild CI. (#141)
Browse files Browse the repository at this point in the history
Github integration with CloudBuild does not copy over the
.git folder, thus to compute the diff we have to perform
a git clone as the first step.

Fixes #127
  • Loading branch information
ammaraskar authored and oliverchang committed Feb 11, 2019
1 parent 9466259 commit 77225c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cloudbuild.yaml
Expand Up @@ -13,6 +13,26 @@
# limitations under the License.

steps:
- id: Initialize git
name: gcr.io/cloud-builders/git
entrypoint: /bin/bash
args:
- -exc
- |
# Cloud Build x GitHub integration uses source archives to fetch
# the source, rather than Git source fetching, and as a consequence
# does not include the .git/ directory. As a workaround, we clone
# the repository to grab the .git directory.
git clone 'https://github.com/google/clusterfuzz' tmp
git -C tmp fetch origin "$COMMIT_SHA"
git -C tmp checkout -qf FETCH_HEAD
mv tmp/.git .git
rm -rf tmp
- id: Lint
name: 'gcr.io/clusterfuzz-images/ci'
args: ['python', 'butler.py', 'lint']
env:
- 'GOOGLE_CLOUDBUILD=1'
- name: 'gcr.io/clusterfuzz-images/ci'
args: ['setup']
- name: 'gcr.io/clusterfuzz-images/ci'
Expand Down
6 changes: 5 additions & 1 deletion src/local/butler/lint.py
Expand Up @@ -21,7 +21,11 @@

def execute(_):
"""Lint changed code."""
_, output = common.execute('git diff --name-only FETCH_HEAD')
if "GOOGLE_CLOUDBUILD" in os.environ:
# Explicitly compare against master if we're running on the CI
_, output = common.execute('git diff --name-only master FETCH_HEAD')
else:
_, output = common.execute('git diff --name-only FETCH_HEAD')

py_changed_file_paths = [
f for f in output.splitlines() if f.endswith('.py') and
Expand Down

0 comments on commit 77225c2

Please sign in to comment.