Skip to content

Commit

Permalink
Add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Breguła committed Oct 10, 2019
1 parent 23415e9 commit c95979b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 13 deletions.
21 changes: 21 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.
---
ignored:
# DL3008 Pin versions in apt get install. Instead of `apt-get install <package>` use
# `apt-get install <package>=<version>`
- DL3008
53 changes: 53 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre-commit==1.18.3
32 changes: 22 additions & 10 deletions site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c95979b

Please sign in to comment.