[YUNIKORN-156] license check for release repo (#106)
Pre-commit worklfow to check license in release related files.
Add workflow badge.
Closes: #106
Signed-off-by: Wilfred Spiegelenburg <wilfreds@apache.org>
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
new file mode 100644
index 0000000..984e858
--- /dev/null
+++ b/.github/workflows/pre-commit.yml
@@ -0,0 +1,32 @@
+# 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.
+
+name: "Pre-commit checks"
+
+on:
+ pull_request:
+ branches:
+ - master
+
+jobs:
+ license:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Check out source code
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 2
+ - name: Check license
+ run: ./check_license.sh
diff --git a/README.md b/README.md
index 9b08eba..b737130 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,8 @@
# Apache YuniKorn Release
----
+[![pre-commit](https://github.com/apache/yunikorn-release/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/apache/yunikorn-release/actions/workflows/pre-commit.yml)
+
This project provides the instructions and tools needed to generate Apache YuniKorn release artifacts.
Reference:
- [ASF Release Creation Process](https://infra.apache.org/release-publishing.html)
diff --git a/check_license.sh b/check_license.sh
new file mode 100755
index 0000000..2bb03bc
--- /dev/null
+++ b/check_license.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+# 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.
+
+# Kernel (OS) Name
+OS=$(uname -s | tr '[:upper:]' '[:lower:]')
+# show that the check has started
+echo "checking license headers:"
+# run different finds on mac vs linux
+if [ "${OS}" = "darwin" ]; then
+ find -E . ! -path "./.git*" -regex ".*(Makefile|\.(go|sh|py|md|conf|yaml|yml|tpl))" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES
+else
+ find . ! -path "./.git*" -regex ".*\(Makefile\|\.\(go\|py\|sh\|md\|conf\|yaml\|yml\|tpl\)\)" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES
+fi
+# any file mentioned in the output is missing the license
+if [ -s LICRES ]; then
+ echo "following files are missing license header:"
+ cat LICRES
+ rm -f LICRES
+ exit 1
+fi
+rm -f LICRES
+echo " all OK"
+exit 0