From ae7e84dcfcbab2b9d26e244691c5a22592a40fbd Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Thu, 12 Dec 2019 12:59:56 -0800 Subject: [PATCH 1/5] Test run with everything built from source --- .../templates/jobs/archetype-sdk-client.yml | 43 ++++++++++++++++++- eng/versioning/set_versions.py | 42 ++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index cbe405cb52d7..4af34beb877b 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,30 @@ jobs: - ${{ parameters.PreTestSteps }} + # JRSSTART + - task: UsePythonVersion@0 + displayName: 'Use Python 3.6' + inputs: + versionSpec: '3.6' + condition: and(eq(variables['SdkType'], 'client'), eq(variables['TestFromSource'],'true')) + + - pwsh: | + python3 --version + python3 eng/versioning/set_versions.py --build-type client --pst + if ($LastExitCode -eq 5678) { + echo "##vso[task.setvariable variable=ShouldRunSourceTests]$true" + } else { + echo "no changes detected, return code from set_versions.py was $(LastExitCode)" + } + displayName: 'Setup for source build' + condition: and(eq(variables['SdkType'], 'client'), eq(variables['TestFromSource'],'true')) + + - script: | + python3 --version + python3 eng/versioning/update_versions.py --update-type library --build-type client + condition: eq(variables['ShouldRunSourceTests'],'true') + displayName: 'Setup for source build' + - task: Maven@3 displayName: 'Run tests' inputs: @@ -288,9 +324,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: 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 From 5ec69492497ed3672ca96c5ebc5ce4b93362f15a Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Thu, 12 Dec 2019 13:08:08 -0800 Subject: [PATCH 2/5] add missing paren --- eng/pipelines/templates/jobs/archetype-sdk-client.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index 4af34beb877b..e9930df2f6fa 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -329,7 +329,7 @@ jobs: condition: or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true')) - task: PublishTestResults@2 - condition: and(always(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true')) + condition: and(always(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true'))) inputs: mergeTestResults: true testRunTitle: $(RunTitle) From eaa4b0e55bace9a37a9d31506396ff07b65e3457 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Thu, 12 Dec 2019 13:40:07 -0800 Subject: [PATCH 3/5] use python not python3 for from source --- eng/pipelines/templates/jobs/archetype-sdk-client.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index e9930df2f6fa..fbe5efc4fe9c 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -297,8 +297,8 @@ jobs: condition: and(eq(variables['SdkType'], 'client'), eq(variables['TestFromSource'],'true')) - pwsh: | - python3 --version - python3 eng/versioning/set_versions.py --build-type client --pst + python --version + python eng/versioning/set_versions.py --build-type client --pst if ($LastExitCode -eq 5678) { echo "##vso[task.setvariable variable=ShouldRunSourceTests]$true" } else { @@ -308,8 +308,8 @@ jobs: condition: and(eq(variables['SdkType'], 'client'), eq(variables['TestFromSource'],'true')) - script: | - python3 --version - python3 eng/versioning/update_versions.py --update-type library --build-type client + python --version + python eng/versioning/update_versions.py --update-type library --build-type client condition: eq(variables['ShouldRunSourceTests'],'true') displayName: 'Setup for source build' From 65f8ab0d8b2b6799341ed6cfad9b6ff409f139b8 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Tue, 17 Dec 2019 08:57:55 -0800 Subject: [PATCH 4/5] Set return code from pwsh --- .../templates/jobs/archetype-sdk-client.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index fbe5efc4fe9c..047252f00078 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -294,18 +294,24 @@ jobs: displayName: 'Use Python 3.6' inputs: versionSpec: '3.6' - condition: and(eq(variables['SdkType'], 'client'), eq(variables['TestFromSource'],'true')) + 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 "no changes detected, return code from set_versions.py was $(LastExitCode)" + echo "Invalid return code from set_versions.py, return code is $($LastExitCode)" + exit 1 } displayName: 'Setup for source build' - condition: and(eq(variables['SdkType'], 'client'), eq(variables['TestFromSource'],'true')) + condition: and(ne(variables['SdkType'], 'data'), eq(variables['TestFromSource'],'true')) - script: | python --version From d7874448a98f832ba0694f3de9d34be27fd1c4e0 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Tue, 17 Dec 2019 10:53:00 -0800 Subject: [PATCH 5/5] Verify succeeded before running tests --- eng/pipelines/templates/jobs/archetype-sdk-client.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index 047252f00078..595aea3352e9 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -289,7 +289,6 @@ jobs: - ${{ parameters.PreTestSteps }} - # JRSSTART - task: UsePythonVersion@0 displayName: 'Use Python 3.6' inputs: @@ -310,14 +309,14 @@ jobs: echo "Invalid return code from set_versions.py, return code is $($LastExitCode)" exit 1 } - displayName: 'Setup for source build' + 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: 'Setup for source build' + displayName: 'Update versions for source build' - task: Maven@3 displayName: 'Run tests' @@ -332,7 +331,7 @@ jobs: 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: or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true')) + condition: and(succeeded(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true'))) - task: PublishTestResults@2 condition: and(always(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true')))