From 3f78c4f99f2c0267f2315b89ac1f20161576036e Mon Sep 17 00:00:00 2001 From: Jianhui Harold Date: Thu, 26 Mar 2020 10:51:22 +0800 Subject: [PATCH] [CI] add license checker (#1448) --- azure-cli-extensions.pyproj | 1 - azure-pipelines.yml | 30 +++++++++++++++ scripts/ci/source_code_static_analysis.py | 6 --- scripts/ci/verify_license.py | 47 ----------------------- src/hack/azext_hack/_validators.py | 2 +- src/hack/azext_hack/_website_utils.py | 2 +- src/hack/azext_hack/custom.py | 2 +- 7 files changed, 33 insertions(+), 57 deletions(-) delete mode 100644 scripts/ci/verify_license.py diff --git a/azure-cli-extensions.pyproj b/azure-cli-extensions.pyproj index ea9104e3bf..9c2ab2ea6c 100644 --- a/azure-cli-extensions.pyproj +++ b/azure-cli-extensions.pyproj @@ -25,7 +25,6 @@ - diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c23e6f584a..af86de99c4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,6 +33,36 @@ jobs: TSLint: false ToolLogsNotFoundAction: 'Standard' +- job: CheckLicenseHeader + displayName: "Check License" + pool: + vmImage: 'ubuntu-16.04' + steps: + - task: UsePythonVersion@0 + displayName: 'Use Python 3.6' + inputs: + versionSpec: 3.6 + - bash: | + set -ev + + # prepare and activate virtualenv + python -m venv env/ + + chmod +x ./env/bin/activate + source ./env/bin/activate + + # clone azure-cli + git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli + + pip install -q azdev + + azdev setup -c ../azure-cli -r ./ + + azdev --version + az --version + + azdev verify license + - job: StaticAnalysis displayName: "Static Analysis" pool: diff --git a/scripts/ci/source_code_static_analysis.py b/scripts/ci/source_code_static_analysis.py index 2c1ca87954..2247e551b9 100644 --- a/scripts/ci/source_code_static_analysis.py +++ b/scripts/ci/source_code_static_analysis.py @@ -7,7 +7,6 @@ from __future__ import print_function import os import sys -import argparse import multiprocessing from pylint import lint @@ -16,7 +15,6 @@ from flake8.main import application from util import get_repo_root from verify_codeowners import main as _verify_codeowners -from verify_license import main as _verify_license SDK_FILE_MARKER = r"# Code generated by Microsoft (R) AutoRest Code Generator." @@ -143,10 +141,6 @@ def main(): _verify_codeowners() - parser = argparse.ArgumentParser() - parser.add_argument('excluded_paths', nargs='*') - _verify_license(parser.parse_args()) - print("All static checks successful!") diff --git a/scripts/ci/verify_license.py b/scripts/ci/verify_license.py deleted file mode 100644 index dae9d85c2c..0000000000 --- a/scripts/ci/verify_license.py +++ /dev/null @@ -1,47 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -from __future__ import print_function - -import os -import sys -import argparse - -from util import get_repo_root - -REPO_ROOT = get_repo_root() -SRC_DIR = os.path.join(REPO_ROOT, 'src') - -LICENSE_HEADER = ("Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. " - "See License.txt in the project root for license information.") - - -def main(args): - excluded_paths = args.excluded_paths - excluded_paths.append('env') - excluded_paths = tuple([os.path.join(REPO_ROOT, relative_path) for relative_path in excluded_paths]) - - files_without_header = [] - for current_dir, _, files in os.walk(get_repo_root()): - if current_dir.startswith(excluded_paths): - continue - file_itr = (os.path.join(current_dir, p) for p in files if p.endswith('.py')) - for python_file in file_itr: - with open(python_file, 'r', encoding='utf-8') as f: - file_text = f.read().replace('\r\n', '\n') - file_text = file_text.replace('\n#', '') - if file_text and (LICENSE_HEADER not in file_text): - files_without_header.append(os.path.join(current_dir, python_file)) - - if files_without_header: - print("Error: The following files don't have the required license headers: \n{}".format( - '\n'.join(files_without_header)), file=sys.stderr) - sys.exit(1) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('excluded_paths', nargs='*') - main(parser.parse_args()) diff --git a/src/hack/azext_hack/_validators.py b/src/hack/azext_hack/_validators.py index dea19b8385..ec34a065b8 100644 --- a/src/hack/azext_hack/_validators.py +++ b/src/hack/azext_hack/_validators.py @@ -1,7 +1,7 @@ # -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -# # -------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------- import re from knack.util import CLIError diff --git a/src/hack/azext_hack/_website_utils.py b/src/hack/azext_hack/_website_utils.py index a0f38822bd..daf51bf677 100644 --- a/src/hack/azext_hack/_website_utils.py +++ b/src/hack/azext_hack/_website_utils.py @@ -1,7 +1,7 @@ # -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -# # -------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------- from azure.cli.command_modules.appservice.custom import ( create_app_service_plan, diff --git a/src/hack/azext_hack/custom.py b/src/hack/azext_hack/custom.py index 2fa9048659..8ba614f7f1 100644 --- a/src/hack/azext_hack/custom.py +++ b/src/hack/azext_hack/custom.py @@ -1,7 +1,7 @@ # -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -# # -------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------- from uuid import uuid4 from azure.cli.core.commands.client_factory import get_mgmt_service_client