professional-services icon indicating copy to clipboard operation
professional-services copied to clipboard

Running local lint checks prior to raising PR

Open prathapreddy123 opened this issue 3 years ago • 1 comments

Issue

Today when user submits a pull request to professional services repo, lint checks are executed via cloud build trigger inside google cloud project owned by repo maintainers. In case of failures, PR authors do not have visibility for the failure reasons.

To resolve this we have recommendation in Contribution section to run local lint checks. But this process has multiple steps and dependencies on terraform and docker to be available.

Proposal

Build a linitchecker.yaml that PR author can run locally using single gcloud command without need for terraform and docker

#linitchecker.yaml

steps:
  # Step 0: Pull image if exists
  - name: gcr.io/cloud-builders/docker
    entrypoint: 'bash'
    args: ['-c', 'docker pull gcr.io/$PROJECT_ID/${_IMAGE_NAME}:${_IMAGE_VERSION} || exit 0']

  # Step 1: Create docker image with required tools
  - name: gcr.io/cloud-builders/docker
    args:
      - 'build'
      - '--tag=gcr.io/$PROJECT_ID/${_IMAGE_NAME}:${_IMAGE_VERSION}'
      - '--cache-from=gcr.io/$PROJECT_ID/${_IMAGE_NAME}:${_IMAGE_VERSION}'
      - '--file=cloudbuild/Dockerfile'
      - '.'
  # Step 2: Run lint check
  - name: gcr.io/$PROJECT_ID/${_IMAGE_NAME}
    args: ["test"]

substitutions:
  # Default values
  _IMAGE_NAME: 'professionalservices-lintcheck'
  _IMAGE_VERSION: 'latest'

timeout: 900s
images: ['gcr.io/$PROJECT_ID/${_IMAGE_NAME}:${_IMAGE_VERSION}']

Run the gcloud command: gcloud builds submit --config lintchecker.yaml .

If we are planning to move forward with dynamic cloud build, rebase checks can also be included so that author has complete visibility on all the checks before PR submission

prathapreddy123 avatar Jul 25 '20 00:07 prathapreddy123

If we make the linter docker image public, we can remove the need for the terraform step. (I think someone may have already done this)

tswast avatar Jul 27 '20 13:07 tswast