This is an automated email from the ASF dual-hosted git repository. kamilbregula pushed a commit to branch pre-commit-minimal in repository https://gitbox.apache.org/repos/asf/airflow-site.git
commit cda77c1206bc62d969aac63cceee97dc3959ff33 Author: Kamil BreguĊa <kamil.breg...@polidea.com> AuthorDate: Thu Oct 10 00:09:16 2019 +0200 Add pre-commit --- .pre-commit-config.yaml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 6 ++++-- requirements.txt | 1 + site.sh | 32 ++++++++++++++++++++++---------- 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8e98b2d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +--- +default_stages: [commit, push] +default_language_version: + # force all unspecified python hooks to run python3 + python: python3 + +repos: + - repo: meta + hooks: + - id: check-hooks-apply + - repo: local + hooks: + - id: shellcheck + name: Check Shell scripts syntax correctness + language: docker_image + entry: koalaman/shellcheck:stable -x -a + types: [shell] + files: ^breeze$|^breeze-complete$|\.sh$|^hooks/build$|^hooks/push$ + exclude: ^airflow/_vendor/.*$ + - id: lint-dockerfile + name: Lint dockerfile + language: docker_image + types: + - dockerfile + entry: --entrypoint /bin/hadolint hadolint/hadolint:latest - + - id: eslint + name: Lint assets files + entry: ./site.sh lint-assets + language: system + always_run: true + pass_filenames: false diff --git a/.travis.yml b/.travis.yml index d7cea39..a31b12a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,9 +28,11 @@ services: install: - ./site.sh build-image - ./site.sh install-node-deps + - pip install -r requirements.txt jobs: include: - - stage: lint-assets - script: ./site.sh lint-assets + - stage: lint + script: + - pre-commit run --all-files --show-diff-on-failure - stage: build script: ./site.sh build-site diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f555665 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pre-commit==1.18.3 diff --git a/site.sh b/site.sh index b11befc..9aa79e0 100755 --- a/site.sh +++ b/site.sh @@ -39,8 +39,9 @@ These are ${0} commands used in various situations: install-node-deps Download all the Node dependencies preview Starts the web server build-site Builds a website - lint-assets Lint assets files e.g. CSS, JS. - shell Start shell. + lint-css Lint CSS files + lint-js Lint Javascript files + shell Start shell help Display usage Unrecognized commands are run as programs in the container. @@ -63,7 +64,7 @@ function ensure_image_exists { function ensure_node_module_exists { if [[ ! -d landing-pages/node_modules/ ]] ; then echo "Missing node depedencies. Start installation." - start_container bash -c "cd landing-pages/ && yarn install" + start_container_non_interactive bash -c "cd landing-pages/ && yarn install" echo "Dependencies installed" fi } @@ -74,14 +75,22 @@ function build_image { echo "End building image" } +COMMON_DOCKER_ARGS=( + -v "$(pwd):/opt/site/" + -p 1313:1313 + -p 3000:3000 +) + function start_container { ensure_image_exists - docker run -ti \ - -v "$(pwd):/opt/site/" \ - -p 1313:1313 \ - -p 3000:3000 \ - airflow-site "$@" + docker run -ti "${COMMON_DOCKER_ARGS[@]}" airflow-site "$@" +} + +function start_container_non_interactive { + ensure_image_exists + + docker run "${COMMON_DOCKER_ARGS[@]}" airflow-site "$@" } if [[ "$#" -ge 1 ]] ; then @@ -95,9 +104,12 @@ if [[ "$#" -ge 1 ]] ; then elif [[ "$1" == "build-site" ]]; then ensure_node_module_exists start_container_non bash -c "cd landing-pages/site && npm run build" - elif [[ "$1" == "lint-assets" ]]; then + elif [[ "$1" == "lint-js" ]]; then + ensure_node_module_exists + start_container_non_interactive bash -c "cd landing-pages/site && npm run lint:js" + elif [[ "$1" == "lint-css" ]]; then ensure_node_module_exists - start_container bash -c "cd landing-pages/site && npm run lint" + start_container_non_interactive bash -c "cd landing-pages/site && npm run lint:css" elif [[ "$1" == "shell" ]]; then start_container "bash" elif [[ "$1" == "help" ]]; then