diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index cbe405cb52d7..595aea3352e9 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -8,26 +8,38 @@ parameters: OSName: 'Linux' OSVmImage: 'ubuntu-16.04' JavaVersion: '1.8' + RunTitle: 'Linux on Java 1.8' macOS - Java 8: OSName: 'macOS' OSVmImage: 'macOS-10.13' JavaVersion: '1.8' + RunTitle: 'macOS on Java 1.8' Windows - Java 8: OSName: 'Windows' OSVmImage: 'windows-2019' JavaVersion: '1.8' + RunTitle: 'Windows on Java 1.8' Linux - Java 11: OSName: 'Linux' OSVmImage: 'ubuntu-16.04' JavaVersion: '1.11' + RunTitle: 'Linux on Java 1.11' macOS - Java 11: OSName: 'macOS' OSVmImage: 'macOS-10.13' JavaVersion: '1.11' + RunTitle: 'macOS on Java 1.11' Windows - Java 11: OSName: 'Windows' OSVmImage: 'windows-2019' JavaVersion: '1.11' + RunTitle: 'Windows on Java 1.11' + Windows From Source - Java 8: + OSName: 'Windows' + OSVmImage: 'windows-2019' + JavaVersion: '1.8' + RunTitle: 'From Source: Windows on Java 1.8' + TestFromSource: true jobs: - job: 'Build' @@ -277,6 +289,35 @@ jobs: - ${{ parameters.PreTestSteps }} + - task: UsePythonVersion@0 + displayName: 'Use Python 3.6' + inputs: + versionSpec: '3.6' + condition: and(ne(variables['SdkType'], 'data'), eq(variables['TestFromSource'],'true')) + + - pwsh: | + python --version + python eng/versioning/set_versions.py --build-type client --pst + if ($LastExitCode -eq 5678) { + echo "##vso[task.setvariable variable=ShouldRunSourceTests]$true" + echo "Changes detected, return code from set_versions.py is $($LastExitCode)" + exit 0 + } elseif ($LastExitCode -eq 0) { + echo "No changes detected, return code from set_versions.py is $($LastExitCode)" + exit 0 + } else { + echo "Invalid return code from set_versions.py, return code is $($LastExitCode)" + exit 1 + } + displayName: 'Set versions for source build' + condition: and(ne(variables['SdkType'], 'data'), eq(variables['TestFromSource'],'true')) + + - script: | + python --version + python eng/versioning/update_versions.py --update-type library --build-type client + condition: eq(variables['ShouldRunSourceTests'],'true') + displayName: 'Update versions for source build' + - task: Maven@3 displayName: 'Run tests' inputs: @@ -288,9 +329,12 @@ jobs: jdkArchitectureOption: 'x64' publishJUnitResults: false goals: ${{ parameters.TestGoals }} + # we want to run this when TestFromSource isn't true (which covers normal running when it isn't set) + # OR when ShouldRunSourceTests is true + condition: and(succeeded(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true'))) - task: PublishTestResults@2 - condition: always() + condition: and(always(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true'))) inputs: mergeTestResults: true - testRunTitle: '$(OSName) on Java $(JavaVersion)' + testRunTitle: $(RunTitle) diff --git a/eng/versioning/set_versions.py b/eng/versioning/set_versions.py index 53500cb3017f..180527994154 100644 --- a/eng/versioning/set_versions.py +++ b/eng/versioning/set_versions.py @@ -22,6 +22,7 @@ from datetime import timedelta import os import re +import sys import time from utils import BuildType from utils import CodeModule @@ -37,7 +38,7 @@ def update_versions_file(update_type, build_type, build_qualifier, artifact_id): print('version_file=' + version_file) newlines = [] - with open(version_file) as f: + with open(version_file, encoding='utf-8') as f: for raw_line in f: stripped_line = raw_line.strip() if not stripped_line or stripped_line.startswith('#'): @@ -63,9 +64,35 @@ def update_versions_file(update_type, build_type, build_qualifier, artifact_id): raise ValueError('{}\'s dependency version + build qualifier {} is not a valid semver version'.format(module.name, module.dependency + build_qualifier)) newlines.append(module.string_for_version_file()) - with open(version_file, 'w') as f: + with open(version_file, 'w', encoding='utf-8') as f: for line in newlines: f.write(line) + +# Prep the appropriate version file for source +def prep_version_file_for_source_testing(build_type): + + version_file = os.path.normpath('eng/versioning/version_' + build_type.name + '.txt') + print('version_file=' + version_file) + file_changed = False + + newlines = [] + with open(version_file, encoding='utf-8') as f: + for raw_line in f: + stripped_line = raw_line.strip() + if not stripped_line or stripped_line.startswith('#'): + newlines.append(raw_line) + else: + module = CodeModule(stripped_line) + if not module.current == module.dependency: + module.dependency = module.current + file_changed = True + newlines.append(module.string_for_version_file()) + + with open(version_file, 'w', encoding='utf-8') as f: + for line in newlines: + f.write(line) + + return file_changed def main(): parser = argparse.ArgumentParser(description='set version numbers in the appropriate version text file') @@ -73,14 +100,23 @@ def main(): parser.add_argument('--build-type', '--bt', type=BuildType, choices=list(BuildType)) parser.add_argument('--build-qualifier', '--bq', help='build qualifier to append onto the version string.') parser.add_argument('--artifact-id', '--ar', help='artifactId to target.') + parser.add_argument('--prep-source-testing', '--pst', action='store_true', help='prep the version file for source testing') args = parser.parse_args() if (args.build_type == BuildType.management): raise ValueError('{} is not currently supported.'.format(BuildType.management.name)) start_time = time.time() - update_versions_file(args.update_type, args.build_type, args.build_qualifier, args.artifact_id) + file_changed = False + if (args.prep_source_testing): + file_changed = prep_version_file_for_source_testing(args.build_type) + else: + update_versions_file(args.update_type, args.build_type, args.build_qualifier, args.artifact_id) elapsed_time = time.time() - start_time print('elapsed_time={}'.format(elapsed_time)) print('Total time for replacement: {}'.format(str(timedelta(seconds=elapsed_time)))) + # if the file changed flag is set, which only happens through a call to prep_version_file_for_source_testing, + # then exit with a unique code that allows us to know that something changed. + if (file_changed): + sys.exit(5678) if __name__ == '__main__': main() \ No newline at end of file