Skip to content

Commit 6420712

Browse files
authored
[AIRFLOW-5204] Shellcheck + common licences + executable shebangs in shell files (apache#5807)
* [AIRFLOW-5204] Shellcheck + common licence in shell files
1 parent 9d10ac7 commit 6420712

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+540
-631
lines changed

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ repos:
6565
- "/**| *| */"
6666
- --license-filepath
6767
- license-templates/LICENSE.txt
68+
- id: insert-license
69+
name: Add licence for shell files
70+
exclude: ^\.github/.*$"|^airflow/_vendor/.*$
71+
types: [shell]
72+
args:
73+
- --comment-style
74+
- "|#|"
75+
- --license-filepath
76+
- license-templates/LICENSE.txt
77+
- repo: https://github.com/pre-commit/pre-commit-hooks
78+
rev: v2.3.0
79+
hooks:
80+
- id: check-executables-have-shebangs
6881
- repo: meta
6982
hooks:
7083
- id: check-hooks-apply
@@ -77,6 +90,11 @@ repos:
7790
- id: mixed-line-ending
7891
- repo: local
7992
hooks:
93+
- id: shellcheck
94+
name: Check Shell scripts syntax correctness
95+
language: docker_image
96+
entry: koalaman/shellcheck:stable -x -a
97+
types: [shell]
8098
- id: lint-dockerfile
8199
name: Lint dockerfile
82100
language: system

CONTRIBUTING.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,15 +698,19 @@ you that you should rebuild the image with REBUILD="true" environment variable s
698698
In airflow we have the following checks:
699699

700700
```text
701-
lint-dockerfile Lint dockerfile
702-
mypy Run mypy
703-
pylint Run pylint
704-
flake8 Run flake8
705-
forbid-tabs Fails if tabs are used in the project
706701
check-merge-conflict Checks if merge conflict is being committed
702+
check-executables-have-shebangs Check that executables have shebang
703+
check-hooks-apply Check hooks apply to the repository
707704
detect-private-key Detects if private key is added to the repository
708705
end-of-file-fixer Make sure that there is an empty line at the end
706+
flake8 Run flake8
707+
forbid-tabs Fails if tabs are used in the project
708+
insert-license Add licences for shell file types
709+
lint-dockerfile Lint dockerfile
709710
mixed-line-ending Detects if mixed line ending is used (\r vs. \r\n)
711+
mypy Run mypy
712+
pylint Run pylint
713+
shellcheck Check shell files with shellcheck
710714
```
711715
## Using pre-commit hooks
712716

airflow/bin/airflow_scheduler_autorestart.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#
1+
#!/usr/bin/env bash
22
# Licensed to the Apache Software Foundation (ASF) under one
33
# or more contributor license agreements. See the NOTICE file
44
# distributed with this work for additional information
55
# regarding copyright ownership. The ASF licenses this file
66
# to you under the Apache License, Version 2.0 (the
77
# "License"); you may not use this file except in compliance
88
# with the License. You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing,
1313
# software distributed under the License is distributed on an
1414
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

airflow/contrib/hooks/qubole_hook.py

100755100644
File mode changed.

airflow/contrib/hooks/ssh_hook.py

100755100644
File mode changed.

airflow/contrib/operators/bigquery_to_mysql_operator.py

100755100644
File mode changed.

airflow/contrib/operators/qubole_operator.py

100755100644
File mode changed.

airflow/example_dags/docker_copy_data.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
#
32
# Licensed to the Apache Software Foundation (ASF) under one
43
# or more contributor license agreements. See the NOTICE file
54
# distributed with this work for additional information
@@ -81,7 +80,13 @@
8180
# network_mode='bridge',
8281
# volumes=['/your/host/input_dir/path:/your/input_dir/path',
8382
# '/your/host/output_dir/path:/your/output_dir/path'],
84-
# command='./entrypoint.sh',
83+
# command=[
84+
# "/bin/bash",
85+
# "-c",
86+
# "/bin/sleep 30; "
87+
# "/bin/mv {{params.source_location}}/{{ ti.xcom_pull('view_file') }} {{params.target_location}};"
88+
# "/bin/echo '{{params.target_location}}/{{ ti.xcom_pull('view_file') }}';"
89+
# ],
8590
# task_id='move_data',
8691
# do_xcom_push=True,
8792
# params={'source_location': '/your/input_dir/path',

airflow/example_dags/entrypoint.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

airflow/models/__init__.py

100755100644
File mode changed.

airflow/models/taskfail.py

100755100644
File mode changed.

airflow/models/taskreschedule.py

100755100644
File mode changed.

airflow/www/compile_assets.sh

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
#!/bin/sh
2-
# Licensed to the Apache Software Foundation (ASF) under one or more
3-
# contributor license agreements. See the NOTICE file distributed with
4-
# this work for additional information regarding copyright ownership.
5-
# The ASF licenses this file to You under the Apache License, Version 2.0
6-
# (the "License"); you may not use this file except in compliance with
7-
# the License. You may obtain a copy of the License at
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
89
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
10+
# http://www.apache.org/licenses/LICENSE-2.0
1611
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
1718

1819
set -e
1920

2021
# first bump up package.json manually, commit and tag
21-
if [ -d airflow/www/static/dist ]; then
22+
if [[ -d airflow/www/static/dist ]]; then
2223
rm -f airflow/www/static/dist/*
2324
fi
2425

dev/README.md

100755100644
File mode changed.

dev/sign.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
29
#
3-
# Licensed to the Apache Software Foundation (ASF) under one or more
4-
# contributor license agreements. See the NOTICE file distributed with
5-
# this work for additional information regarding copyright ownership.
6-
# The ASF licenses this file to You under the Apache License, Version 2.0
7-
# (the "License"); you may not use this file except in compliance with
8-
# the License. You may obtain a copy of the License at
9-
#
10-
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
12-
# Unless required by applicable law or agreed to in writing, software
13-
# distributed under the License is distributed on an "AS IS" BASIS,
14-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
# See the License for the specific language governing permissions and
16-
# limitations under the License.
10+
# http://www.apache.org/licenses/LICENSE-2.0
1711
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
1818

1919
# Use this to sign the tar balls generated from
2020
# python setup.py sdist --formats=gztar
2121
# ie. sign.sh <my_tar_ball>
2222
# you will still be required to type in your signing key password
2323
# or it needs to be available in your keychain
2424

25-
NAME=${1}
25+
NAME="${1}"
2626

27-
gpg --armor --output ${NAME}.asc --detach-sig ${NAME}
28-
gpg --print-md SHA512 ${NAME} > ${NAME}.sha512
27+
gpg --armor --output "${NAME}.asc" --detach-sig "${NAME}"
28+
gpg --print-md SHA512 "${NAME}" > "${NAME}.sha512"

docs/build.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#!/usr/bin/env bash
2-
3-
#
42
# Licensed to the Apache Software Foundation (ASF) under one
53
# or more contributor license agreements. See the NOTICE file
64
# distributed with this work for additional information
75
# regarding copyright ownership. The ASF licenses this file
86
# to you under the Apache License, Version 2.0 (the
97
# "License"); you may not use this file except in compliance
108
# with the License. You may obtain a copy of the License at
11-
#
9+
#
1210
# http://www.apache.org/licenses/LICENSE-2.0
13-
#
11+
#
1412
# Unless required by applicable law or agreed to in writing,
1513
# software distributed under the License is distributed on an
1614
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -40,7 +38,7 @@ if [[ -f /.dockerenv ]]; then
4038
sudo mkdir -pv _api
4139
echo "Created the _build and _api folders in case they do not exist"
4240
echo "Changing ownership of _build and _api folders to ${AIRFLOW_USER}:${AIRFLOW_USER}"
43-
sudo chown -R "${AIRFLOW_USER}:${AIRFLOW_USER}" .
41+
sudo chown -R "${AIRFLOW_USER}":"${AIRFLOW_USER}" .
4442
echo "Changed ownership of the whole doc folder to ${AIRFLOW_USER}:${AIRFLOW_USER}"
4543
else
4644
# We are outside the container so we simply make sure that the directories exist
@@ -86,23 +84,23 @@ SUCCEED_LINE=$(make html |\
8684
grep 'build succeeded' |\
8785
head -1)
8886

89-
NUM_CURRENT_WARNINGS=$(echo ${SUCCEED_LINE} |\
87+
NUM_CURRENT_WARNINGS=$(echo "${SUCCEED_LINE}" |\
9088
sed -E 's/build succeeded, ([0-9]+) warnings?\./\1/g')
9189

9290
if [[ -f /.dockerenv ]]; then
9391
# We are inside the container which means that we should fix back the permissions of the
9492
# _build and _api folder files, so that they can be accessed by the host user
9593
# The _api folder should be deleted by then but just in case we should change the ownership
9694
echo "Changing ownership of docs/_build folder back to ${HOST_USER_ID}:${HOST_GROUP_ID}"
97-
sudo chown ${HOST_USER_ID}:${HOST_GROUP_ID} _build
95+
sudo chown "${HOST_USER_ID}":"${HOST_GROUP_ID}" _build
9896
if [[ -d _api ]]; then
99-
sudo chown ${HOST_USER_ID}:${HOST_GROUP_ID} _api
97+
sudo chown "${HOST_USER_ID}":"${HOST_GROUP_ID}" _api
10098
fi
10199
echo "Changed ownership of docs/_build folder back to ${HOST_USER_ID}:${HOST_GROUP_ID}"
102100
fi
103101

104102

105-
if echo ${SUCCEED_LINE} | grep -q "warning"; then
103+
if echo "${SUCCEED_LINE}" | grep -q "warning"; then
106104
echo
107105
echo "Unexpected problems found in the documentation. "
108106
echo "Currently, ${NUM_CURRENT_WARNINGS} warnings found. "

docs/start_doc_server.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env bash
2-
3-
#
42
# Licensed to the Apache Software Foundation (ASF) under one
53
# or more contributor license agreements. See the NOTICE file
64
# distributed with this work for additional information
@@ -18,8 +16,8 @@
1816
# specific language governing permissions and limitations
1917
# under the License.
2018

21-
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22-
(cd $THIS_DIR/_build/html;
19+
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20+
(cd "${MY_DIR}"/_build/html || exit;
2321
# The below command works on both Python 2 and Python 3
2422
python -m http.server 8000 && python -m SimpleHTTPServer 8000
2523
)

hooks/_default_branch.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
219
export DEFAULT_BRANCH="master"

hooks/build

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#!/usr/bin/env bash
2-
3-
#
4-
# Licensed to the Apache Software Foundation (ASF) under one
5-
# or more contributor license agreements. See the NOTICE file
6-
# distributed with this work for additional information
7-
# regarding copyright ownership. The ASF licenses this file
8-
# to you under the Apache License, Version 2.0 (the
9-
# "License"); you may not use this file except in compliance
10-
# with the License. You may obtain a copy of the License at
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
119
#
12-
# http://www.apache.org/licenses/LICENSE-2.0
10+
# http://www.apache.org/licenses/LICENSE-2.0
1311
#
14-
# Unless required by applicable law or agreed to in writing,
15-
# software distributed under the License is distributed on an
16-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17-
# KIND, either express or implied. See the License for the
18-
# specific language governing permissions and limitations
19-
# under the License.
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
2018

2119
# This is hook build used by DockerHub. We are also using it
2220
# on Travis CI to potentially rebuild (and refresh layers that
@@ -158,7 +156,7 @@ export PYTHON_VERSION=\
158156
${PYTHON_VERSION:=$(${PYTHON_BINARY} -c \
159157
'import sys;print("%s.%s" % (sys.version_info.major, sys.version_info.minor))')}
160158

161-
# shellcheck source=./_default_branch.sh
159+
# shellcheck source=hooks/_default_branch.sh
162160
. "${MY_DIR}/_default_branch.sh"
163161

164162
# Source brnnch will be set in DockerHub

run-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env bash
2-
#
32
# Licensed to the Apache Software Foundation (ASF) under one
43
# or more contributor license agreements. See the NOTICE file
54
# distributed with this work for additional information
@@ -16,6 +15,7 @@
1615
# KIND, either express or implied. See the License for the
1716
# specific language governing permissions and limitations
1817
# under the License.
18+
1919
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2020

2121
# Bash sanity settings (error on exit, complain for undefined vars, error when pipe fails)

0 commit comments

Comments
 (0)