Skip to content

Commit

Permalink
mgmt, update codegen script, when fail when called as script, return …
Browse files Browse the repository at this point in the history
…exit code via error (#26423)

* mgmt, update codegen script, when fail when called as script, return exit code via error

* ignore revapi in build, as build fails at this step does not mean codegen/compile fails, but swagger is not backward compatible
  • Loading branch information
weidongxu-microsoft authored Jan 12, 2022
1 parent 7b8d79a commit 0cb8703
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
49 changes: 27 additions & 22 deletions eng/mgmt/automation/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def generate(
version: str = None,
autorest_options: str = '',
**kwargs,
):
) -> bool:
module = ARTIFACT_FORMAT.format(service)
namespace = NAMESPACE_FORMAT.format(service)
output_dir = os.path.join(
Expand Down Expand Up @@ -89,10 +89,10 @@ def generate(
return True


def compile_package(sdk_root, service):
def compile_package(sdk_root, service) -> bool:
module = ARTIFACT_FORMAT.format(service)
if os.system(
'mvn --no-transfer-progress clean verify package -f {0}/pom.xml -pl {1}:{2} -am'.format(
'mvn --no-transfer-progress clean verify package -f {0}/pom.xml -Dgpg.skip -Drevapi.skip -pl {1}:{2} -am'.format(
sdk_root, GROUP_ID, module)) != 0:
logging.error('[COMPILE] Maven build fail')
return False
Expand Down Expand Up @@ -476,25 +476,30 @@ def main():
module = ARTIFACT_FORMAT.format(service)
stable_version, current_version = set_or_increase_version(sdk_root, GROUP_ID, module, **args)
args['version'] = current_version
generate(sdk_root, **args)

compile_package(sdk_root, service)
compare_with_maven_package(sdk_root, service, stable_version,
current_version)

if args.get('auto_commit_external_change') and args.get(
'user_name') and args.get('user_email'):
pwd = os.getcwd()
try:
os.chdir(sdk_root)
os.system('git add eng/versioning eng/mgmt pom.xml {0} {1}'.format(
CI_FILE_FORMAT.format(service),
POM_FILE_FORMAT.format(service)))
os.system(
'git -c user.name={0} -c user.email={1} commit -m "[Automation] External Change"'
.format(args['user_name'], args['user_email']))
finally:
os.chdir(pwd)
succeeded = generate(sdk_root, **args)

if succeeded:
succeeded = compile_package(sdk_root, service)
if succeeded:
compare_with_maven_package(sdk_root, service, stable_version,
current_version)

if args.get('auto_commit_external_change') and args.get(
'user_name') and args.get('user_email'):
pwd = os.getcwd()
try:
os.chdir(sdk_root)
os.system('git add eng/versioning eng/mgmt pom.xml {0} {1}'.format(
CI_FILE_FORMAT.format(service),
POM_FILE_FORMAT.format(service)))
os.system(
'git -c user.name={0} -c user.email={1} commit -m "[Automation] External Change"'
.format(args['user_name'], args['user_email']))
finally:
os.chdir(pwd)

if not succeeded:
raise RuntimeError('Failed to generate code or compile the package')


if __name__ == '__main__':
Expand Down
11 changes: 7 additions & 4 deletions eng/mgmt/automation/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def generate(
use: str,
autorest_options: str = '',
**kwargs,
):
) -> bool:
namespace = 'com.{0}'.format(module.replace('-', '.'))
output_dir = os.path.join(
sdk_root,
Expand Down Expand Up @@ -149,8 +149,8 @@ def generate(
return True


def compile_package(sdk_root: str, group_id: str, module: str):
command = 'mvn --no-transfer-progress clean verify package -f {0}/pom.xml -pl {1}:{2} -am'.format(
def compile_package(sdk_root: str, group_id: str, module: str) -> bool:
command = 'mvn --no-transfer-progress clean verify package -f {0}/pom.xml -Dgpg.skip -Drevapi.skip -pl {1}:{2} -am'.format(
sdk_root, group_id, module)
logging.info(command)
if os.system(command) != 0:
Expand Down Expand Up @@ -273,7 +273,10 @@ def main():

succeeded = generate(sdk_root, **args)
if succeeded:
compile_package(sdk_root, GROUP_ID, args['module'])
succeeded = compile_package(sdk_root, GROUP_ID, args['module'])

if not succeeded:
raise RuntimeError('Failed to generate code or compile the package')


if __name__ == '__main__':
Expand Down

0 comments on commit 0cb8703

Please sign in to comment.