Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 1452 (Azure#14179)
Browse files Browse the repository at this point in the history
* Use sparse checkout for generate matrix job

* Add repository parameter

Co-authored-by: Ben Broderick Phillips <[email protected]>
  • Loading branch information
azure-sdk and benbp authored Mar 9, 2021
1 parent 0f9117c commit ecce9ed
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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-<lang>-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
Expand Down
34 changes: 34 additions & 0 deletions eng/common/pipelines/templates/steps/sparse-checkout.yml
Original file line number Diff line number Diff line change
@@ -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)) }}
4 changes: 3 additions & 1 deletion eng/common/scripts/job-matrix/samples/matrix-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecce9ed

Please sign in to comment.