Skip to content

Commit

Permalink
Add -i option to fix ASF headers to lint scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
areusch committed Feb 17, 2022
1 parent 0009a30 commit 19138e3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docker/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function run_lint_step() {
;;
asf)
cmd=( tests/lint/check_asf_header.sh --local )
if [ $inplace_fix -eq 1 ]; then
cmd=( "${cmd[@]}" --fix )
fi
;;
clang_format)
if [ $inplace_fix -eq 0 ]; then
Expand Down
43 changes: 34 additions & 9 deletions tests/lint/check_asf_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# specific language governing permissions and limitations
# under the License.

set -euo pipefail

rat_tempdir="$(mktemp -d)"

Expand All @@ -26,10 +27,23 @@ trap cleanup EXIT

rat_output="${rat_tempdir}/$$.apache-rat.txt"

fix=0
filter_untracked=0
if [ "$1" == "--local" ]; then
filter_untracked=1
fi
while [ "x${1-}" != "x" ]; do
case "$1" in
--local)
filter_untracked=1
;;
--fix)
fix=1
;;
*)
echo "Unrecognized option: $1"
exit 2
;;
esac
shift
done

java -jar /bin/apache-rat.jar -E tests/lint/rat-excludes -d . | (grep -E "^== File" >"${rat_output}" || true)

Expand All @@ -43,14 +57,25 @@ if [ ${filter_untracked} -eq 1 ]; then
rat_output="${processed_rat_output}"
fi

if grep --quiet -E "File" "${rat_output}"; then
echo "Need to add ASF header to the following files."
grep --quiet -E "File" "${rat_output}" && success=1 || success=0

if [ $success -eq 0 ]; then
echo "No files violate ASF header check"
else
if [ $fix -eq 1 ]; then
python3 tests/lint/add_asf_header.py file_list.txt
echo "Ran add_asf_header.py to fix the following files:"
else
echo "Need to add ASF header to the following files."
fi
echo "----------------File List----------------"
cat "${rat_output}"
echo "-----------------------------------------"
echo "Use the following steps to add the headers:"
echo "- Create file_list.txt in your text editor"
echo "- Copy paste the above content in file-list into file_list.txt"
echo "- python3 tests/lint/add_asf_header.py file_list.txt"
if [ $fix -eq 0 ]; then
echo "To fix, run check_asf_header.sh --fix, or use the following manual steps:"
echo "- Create file_list.txt in your text editor"
echo "- Copy paste the above content in file-list into file_list.txt"
echo "- python3 tests/lint/add_asf_header.py file_list.txt"
fi
exit 1
fi

0 comments on commit 19138e3

Please sign in to comment.