Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] add prechek logic in job LintModifiedExtension #1334

Merged
merged 36 commits into from
Mar 12, 2020
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
aa2c802
Init
Feb 29, 2020
f133658
Init publish_precheck.py
Feb 29, 2020
36d5b76
Add job in azure-pipeline.yaml
Feb 29, 2020
f8f9fe5
Init verify_linter.py
Mar 1, 2020
4f5a00c
Remove publish_precheck.py
Mar 1, 2020
ae38366
Release publish prechecks in ADO
Mar 2, 2020
0b82d2d
Add new Linter to ADO
Mar 2, 2020
e5e0577
Fix error
Mar 2, 2020
1d5ca16
Add azdev
Mar 2, 2020
0b489db
Add azdev linter
Mar 2, 2020
ef277f9
Fix typo
Mar 2, 2020
1529439
Fix azdev
Mar 2, 2020
1e741ec
Fix azdev
Mar 2, 2020
6969837
Exclude deleted files from diff
Mar 4, 2020
8a37c3c
typo
Mar 5, 2020
0a52818
Add license header
Mar 5, 2020
876c1d8
Remove publish_build.py
Mar 5, 2020
7471d90
test to fix ADO bug
Mar 5, 2020
adfefa4
Update target branch to find to ADO variable System.PullRequest.Targe…
Mar 5, 2020
21824a7
Update error message of ModifiedFilesNotAllowedError
Mar 5, 2020
e802bf9
Add ADO environment variable System.PullRequest.TargetBranch
Mar 5, 2020
25b16e0
Add remote prefix for ADO environment
Mar 5, 2020
ed92700
optimize prompt output
Mar 5, 2020
d999827
Fix bug
Mar 5, 2020
1473ee1
add azdev setup -r
Mar 5, 2020
cfbefae
update Pull Request template
Mar 5, 2020
8334e5b
update Pull Request template
Mar 5, 2020
d308086
Merge branch 'master' into release-pipeline-prechecks
Mar 5, 2020
264b6f7
Rename AzExtension -> AzExtensinHelper, AzdevExtension -> AzdevExtens…
Mar 10, 2020
0799247
Merge branch 'master' into release-pipeline-prechecks
Mar 10, 2020
b5c0fcf
Rename LintModifiedExtensions
Mar 11, 2020
f34e2cf
Merge branch 'release-pipeline-prechecks' of https://github.com/Azure…
Mar 12, 2020
7139de7
fix bug that will miss new added extension
Mar 12, 2020
8a354ef
Update .github/PULL_REQUEST_TEMPLATE.md
Mar 12, 2020
bc5640d
Merge branch 'master' into release-pipeline-prechecks
Mar 12, 2020
82cd689
Merge branch 'master' into release-pipeline-prechecks
Mar 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Init publish_precheck.py
  • Loading branch information
Jianhui Harold committed Feb 29, 2020
commit f1336589b89ffaca0abc0c3138fac5b29ff71538
59 changes: 53 additions & 6 deletions scripts/ci/publish_precheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,68 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
from subprocess import check_output

CONTEXT = """
This script is used to detect requirements for publish.
If your want us to help to build, upload and publish extension wheel, src/index.json must not be modified.
A release pipeline will help to do it once PR is merged and and a Pull Request will be created to update src/index.json.
The precondition is to put your source code inside repo Azure/azure-cli-extensions, cause we must build on source code.

If your source code is outside of this repo, you have to build, upload and publish by yourself.
"""
This script is used to
"""

from subprocess import check_output, check_call, CalledProcessError

class ModifiedFilesNotAllow(Exception):
"""
Exception raise for the scenario that modified files is conflict against publish requirement.
Scenario 1: if modified files contain only src/index.json, don't raise
Scenario 2: if modified files contain not only extension code but also src/index.json, raise.
Scenario 3: if modified files don't contain src/index.json, don't raise.
"""


def find_modified_files_against_master_branch():
pass
cmd = 'git --no-pager diff --name-only origin/master -- src/'
return check_output(cmd.split())


def contain_index_json(files):
return 'src/index.json' in files


def contain_extension_code(files):
for file in files:
if os.path.isdir(file) and 'setup.py' in os.listdir(file):
return True

return False


def main():
pass
modified_files = find_modified_files_against_master_branch()

if len(modified_files) == 1 and contain_index_json(modified_files):
# Scenario 1.
# This scenarios is for modify index.json only.
# If the modified metadata items refer to the extension code exits in this repo, PR is be created via Pipeline.
# If the modified metadata items refer to the extension code doesn't exist, PR is created from Service Team.
# We allow.
pass
else:
# modified files contain more than one file

if contain_extension_code(modified_files) and contain_index_json(modified_files):
# Scenario 2, we reject.
raise ModifiedFilesNotAllow(CONTEXT)

# other scenarios, we allow.
print('Precheck is fine. We are able to help to build and upload.')


if __name__ == '__main__':
main()
try:
main()
except ModifiedFilesNotAllow as e:
print(e)