You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2019/10/10 10:09:50 UTC

[airflow-site] branch aip-11 updated: Add pre-commit (#69)

This is an automated email from the ASF dual-hosted git repository.

kamilbregula pushed a commit to branch aip-11
in repository https://gitbox.apache.org/repos/asf/airflow-site.git


The following commit(s) were added to refs/heads/aip-11 by this push:
     new cbe2f5c  Add pre-commit (#69)
cbe2f5c is described below

commit cbe2f5c9a54db5da25c73673375cb86e86d2a0ef
Author: Kamil BreguĊ‚a <mi...@users.noreply.github.com>
AuthorDate: Thu Oct 10 12:09:46 2019 +0200

    Add pre-commit (#69)
---
 .travis.yml => .hadolint.yaml | 23 ++++---------------
 .pre-commit-config.yaml       | 53 +++++++++++++++++++++++++++++++++++++++++++
 .travis.yml                   |  6 +++--
 Dockerfile                    |  2 +-
 requirements.txt              |  1 +
 site.sh                       | 32 ++++++++++++++++++--------
 6 files changed, 85 insertions(+), 32 deletions(-)

diff --git a/.travis.yml b/.hadolint.yaml
similarity index 72%
copy from .travis.yml
copy to .hadolint.yaml
index d7cea39..6b4e9c7 100644
--- a/.travis.yml
+++ b/.hadolint.yaml
@@ -14,23 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
 ---
-dist: xenial
-language: python
-
-python: "3.6"
-stages:
-  - pre-test
-  - test
-services:
-  - docker
-install:
-  - ./site.sh build-image
-  - ./site.sh install-node-deps
-jobs:
-  include:
-    - stage: lint-assets
-      script: ./site.sh lint-assets
-    - stage: build
-      script: ./site.sh build-site
+ignored:
+  # DL3008 Pin versions in apt get install. Instead of `apt-get install <package>` use
+  # `apt-get install <package>=<version>`
+  - DL3008
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..fd6c2d1
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,53 @@
+# 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: lint-css
+        name: Lint CSS files
+        entry: ./site.sh lint-css
+        language: system
+        files: \.scss$
+        pass_filenames: false
+      - id: lint-js
+        name: Lint JS files
+        entry: ./site.sh lint-js
+        language: system
+        files: \.js$
+        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/Dockerfile b/Dockerfile
index 9ea780b..90a7f18 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -56,7 +56,7 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
 RUN HUGOHOME="$(mktemp -d)" \
     && export HUGOHOME \
     && curl -sL https://github.com/gohugoio/hugo/releases/download/v0.58.3/hugo_extended_0.58.3_Linux-64bit.tar.gz > "${HUGOHOME}/hugo.tar.gz" \
-    && tar -xzvf ${HUGOHOME}/hugo.tar.gz hugo \
+    && tar -xzvf "${HUGOHOME}/hugo.tar.gz" hugo \
     && mv hugo /usr/local/bin/hugo \
     && chmod +x /usr/local/bin/hugo \
     && rm -r "${HUGOHOME}"
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 c046ad8..b3ed7e2 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 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