You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2023/01/31 11:17:21 UTC
[mynewt-core] branch master updated: ci: Add licensing checks
This is an automated email from the ASF dual-hosted git repository.
janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 9234daa05 ci: Add licensing checks
9234daa05 is described below
commit 9234daa05ee6cf88e47a9c7e83ee5fd1b052b5aa
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Mon Jan 30 22:40:51 2023 +0100
ci: Add licensing checks
Validate license of all files (new or modified) in PR.
---
.github/check_license.py | 74 ++++++++++++++++++++++
.../{check_style.yml => check_compliance.yml} | 16 +++++
2 files changed, 90 insertions(+)
diff --git a/.github/check_license.py b/.github/check_license.py
new file mode 100755
index 000000000..5e11ccd74
--- /dev/null
+++ b/.github/check_license.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+#
+# 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.
+#
+
+import os
+import subprocess
+import sys
+import shutil
+from pathlib import Path
+
+tmp_folder = "/tmp/check_license/"
+licenses_url = "https://www.apache.org/legal/resolved.html"
+
+def run_cmd(cmd: str) -> list[str]:
+ out = subprocess.check_output(cmd, text=True, shell=True)
+ return out.splitlines()
+
+
+def run_cmd_no_check(cmd: str) -> list[str]:
+ out = subprocess.run(cmd, text=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout
+ return out.splitlines()
+
+
+def main() -> bool:
+ if len(sys.argv) > 1:
+ commit = sys.argv[1]
+ else:
+ commit = "HEAD"
+ if len(sys.argv) > 2:
+ upstream = sys.argv[2]
+ else:
+ upstream = "origin/master"
+
+ mb = run_cmd(f"git merge-base {upstream} {commit}")
+ upstream = mb[0]
+
+ files = run_cmd(f"git diff --diff-filter=AM --name-only {upstream} {commit}")
+ for cfg_fname in files:
+ os.makedirs(str(Path(tmp_folder + cfg_fname).parent), 0o755, True)
+ shutil.copy(cfg_fname, tmp_folder + cfg_fname)
+
+ files = run_cmd_no_check(f"java -jar apache-rat.jar -E .rat-excludes -d {tmp_folder} | grep \"^ !\"")
+ if files :
+ print(f"\033[31m! Files with unapproved or unknown licenses detected.\033[0m")
+ print(f"\033[31m! See {licenses_url} for details.\033[0m")
+ print()
+ print(f"\033[90mLicense\t\tFilename\033[0m")
+ for f in files:
+ print(f.strip(' !').replace(tmp_folder,'\t\t'))
+ return False
+
+ return True
+
+
+if __name__ == "__main__":
+ if not main():
+ sys.exit(1)
diff --git a/.github/workflows/check_style.yml b/.github/workflows/check_compliance.yml
similarity index 69%
rename from .github/workflows/check_style.yml
rename to .github/workflows/check_compliance.yml
index ce713bb4e..79e193e34 100644
--- a/.github/workflows/check_style.yml
+++ b/.github/workflows/check_compliance.yml
@@ -36,3 +36,19 @@ jobs:
- name: check style
run: |
.github/check_style.py
+
+ style_license:
+ name: Licensing
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+ - name: Install Dependencies
+ run: |
+ wget https://dlcdn.apache.org//creadur/apache-rat-0.15/apache-rat-0.15-bin.tar.gz
+ tar zxf apache-rat-0.15-bin.tar.gz apache-rat-0.15/apache-rat-0.15.jar
+ mv apache-rat-0.15/apache-rat-0.15.jar apache-rat.jar
+ - name: check licensing
+ run: |
+ .github/check_license.py