[CI] add license checker (#1448)
This commit is contained in:
Родитель
93f3ab87a0
Коммит
3f78c4f99f
|
@ -25,7 +25,6 @@
|
||||||
<Compile Include="scripts\ci\test_source.py" />
|
<Compile Include="scripts\ci\test_source.py" />
|
||||||
<Compile Include="scripts\ci\util.py" />
|
<Compile Include="scripts\ci\util.py" />
|
||||||
<Compile Include="scripts\ci\verify_codeowners.py" />
|
<Compile Include="scripts\ci\verify_codeowners.py" />
|
||||||
<Compile Include="scripts\ci\verify_license.py" />
|
|
||||||
<Compile Include="scripts\refdoc\azhelpgen\azhelpgen.py" />
|
<Compile Include="scripts\refdoc\azhelpgen\azhelpgen.py" />
|
||||||
<Compile Include="scripts\refdoc\azhelpgen\__init__.py" />
|
<Compile Include="scripts\refdoc\azhelpgen\__init__.py" />
|
||||||
<Compile Include="scripts\refdoc\cligroup\cligroup.py" />
|
<Compile Include="scripts\refdoc\cligroup\cligroup.py" />
|
||||||
|
|
|
@ -33,6 +33,36 @@ jobs:
|
||||||
TSLint: false
|
TSLint: false
|
||||||
ToolLogsNotFoundAction: 'Standard'
|
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
|
- job: StaticAnalysis
|
||||||
displayName: "Static Analysis"
|
displayName: "Static Analysis"
|
||||||
pool:
|
pool:
|
||||||
|
|
|
@ -7,7 +7,6 @@ from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
from pylint import lint
|
from pylint import lint
|
||||||
|
@ -16,7 +15,6 @@ from flake8.main import application
|
||||||
from util import get_repo_root
|
from util import get_repo_root
|
||||||
|
|
||||||
from verify_codeowners import main as _verify_codeowners
|
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."
|
SDK_FILE_MARKER = r"# Code generated by Microsoft (R) AutoRest Code Generator."
|
||||||
|
@ -143,10 +141,6 @@ def main():
|
||||||
|
|
||||||
_verify_codeowners()
|
_verify_codeowners()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('excluded_paths', nargs='*')
|
|
||||||
_verify_license(parser.parse_args())
|
|
||||||
|
|
||||||
print("All static checks successful!")
|
print("All static checks successful!")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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())
|
|
|
@ -1,7 +1,7 @@
|
||||||
# --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License. See License.txt in the project root for license information.
|
# Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
# # --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
import re
|
import re
|
||||||
from knack.util import CLIError
|
from knack.util import CLIError
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License. See License.txt in the project root for license information.
|
# Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
# # --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
from azure.cli.command_modules.appservice.custom import (
|
from azure.cli.command_modules.appservice.custom import (
|
||||||
create_app_service_plan,
|
create_app_service_plan,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License. See License.txt in the project root for license information.
|
# Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
# # --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from azure.cli.core.commands.client_factory import get_mgmt_service_client
|
from azure.cli.core.commands.client_factory import get_mgmt_service_client
|
||||||
|
|
Загрузка…
Ссылка в новой задаче