From ecce9edcb530bffb155fb36dc6a426316f2dac4d Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Mon, 8 Mar 2021 18:07:51 -0800 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 1452 (#14179) * Use sparse checkout for generate matrix job * Add repository parameter Co-authored-by: Ben Broderick Phillips --- .../jobs/archetype-sdk-tests-generate.yml | 28 +++++++++++++-- .../templates/steps/sparse-checkout.yml | 34 +++++++++++++++++++ .../job-matrix/samples/matrix-test.yml | 4 ++- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 eng/common/pipelines/templates/steps/sparse-checkout.yml diff --git a/eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml b/eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml index cbe0c6bb6afb..9f7ca629cd5d 100644 --- a/eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml +++ b/eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml @@ -12,16 +12,40 @@ parameters: default: [] - name: JobTemplatePath type: string +# Set this to false to do a full checkout for private repositories with the azure pipelines service connection +- name: SparseCheckout + type: boolean + default: true +- name: SparseCheckoutPaths + type: object + default: [] +- name: Pool + type: string + default: azsdk-pool-mms-ubuntu-1804-general +- name: OsVmImage + type: string + default: MMSUbuntu18.04 jobs: - job: generate_matrix variables: displayNameFilter: $[ coalesce(variables.jobMatrixFilter, '.*') ] pool: - name: Azure Pipelines - vmImage: ubuntu-18.04 + name: ${{ parameters.Pool }} + vmImage: ${{ parameters.OsVmImage }} displayName: Generate Job Matrix steps: + # Skip sparse checkout for the `azure-sdk-for--pr` private mirrored repositories + # as we require the github service connection to be loaded. + - ${{ if and(parameters.SparseCheckout, not(contains(variables['Build.DefinitionName'], '-pr - '))) }}: + - template: /eng/common/pipelines/templates/steps/sparse-checkout.yml + parameters: + ${{ if ne(length(parameters.SparseCheckoutPaths), 0) }}: + Paths: ${{ parameters.SparseCheckoutPaths }} + ${{ if and(eq(length(parameters.SparseCheckoutPaths), 0), ne(parameters.AdditionalParameters.ServiceDirectory, '')) }}: + Paths: + - ${{ parameters.AdditionalParameters.ServiceDirectory }} + - ${{ each config in parameters.MatrixConfigs }}: - ${{ if eq(config.GenerateVMJobs, 'true') }}: - task: Powershell@2 diff --git a/eng/common/pipelines/templates/steps/sparse-checkout.yml b/eng/common/pipelines/templates/steps/sparse-checkout.yml new file mode 100644 index 000000000000..9c421712d4e4 --- /dev/null +++ b/eng/common/pipelines/templates/steps/sparse-checkout.yml @@ -0,0 +1,34 @@ +parameters: + - name: Paths + type: object + default: [] + - name: Repositories + type: object + default: + - Name: $(Build.Repository.Name) + Commitish: $(Build.SourceVersion) + WorkingDirectory: $(System.DefaultWorkingDirectory) + +steps: + - checkout: none + + - ${{ each repo in parameters.Repositories }}: + - pwsh: | + $dir = "${{ coalesce(repo.WorkingDirectory, format('{0}/{1}', '$(System.DefaultWorkingDirectory)', repo.Name)) }}" + New-Item $dir -ItemType Directory -Force + + - pwsh: | + git clone --no-checkout --filter=tree:0 git://github.com/${{ repo.Name }} . + git sparse-checkout init + git sparse-checkout set eng + displayName: Init sparse checkout ${{ repo.Name }} + workingDirectory: ${{ coalesce(repo.WorkingDirectory, format('{0}/{1}', '$(System.DefaultWorkingDirectory)', repo.Name)) }} + + - ${{ each path in parameters.Paths }}: + - pwsh: git sparse-checkout add ${{ path }} + displayName: Add sparse checkout path ${{ path }} + workingDirectory: ${{ coalesce(repo.WorkingDirectory, format('{0}/{1}', '$(System.DefaultWorkingDirectory)', repo.Name)) }} + + - pwsh: git checkout ${{ repo.Commitish }} + displayName: Sparse checkout at ${{ repo.Commitish }} + workingDirectory: ${{ coalesce(repo.WorkingDirectory, format('{0}/{1}', '$(System.DefaultWorkingDirectory)', repo.Name)) }} diff --git a/eng/common/scripts/job-matrix/samples/matrix-test.yml b/eng/common/scripts/job-matrix/samples/matrix-test.yml index be9d907e7c2a..bead42609983 100644 --- a/eng/common/scripts/job-matrix/samples/matrix-test.yml +++ b/eng/common/scripts/job-matrix/samples/matrix-test.yml @@ -7,7 +7,9 @@ jobs: - template: /eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml parameters: JobTemplatePath: /eng/common/scripts/job-matrix/samples/matrix-job-sample.yml - AdditionalParameters: [] + AdditionalParameters: {} + Pool: Azure Pipelines + OsVmImage: ubuntu-18.04 CloudConfig: SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources) Location: eastus2