|
| 1 | +### These steps synchronize new code from product repositories into the VMR (https://github.com/dotnet/dotnet). |
| 2 | +### They initialize the darc CLI and pull the new updates. |
| 3 | +### Changes are applied locally onto the already cloned VMR (located in $vmrPath). |
| 4 | + |
| 5 | +parameters: |
| 6 | +- name: targetRef |
| 7 | + displayName: Target revision in dotnet/<repo> to synchronize |
| 8 | + type: string |
| 9 | + default: $(Build.SourceVersion) |
| 10 | + |
| 11 | +- name: vmrPath |
| 12 | + displayName: Path where the dotnet/dotnet is checked out to |
| 13 | + type: string |
| 14 | + default: $(Agent.BuildDirectory)/vmr |
| 15 | + |
| 16 | +- name: additionalSyncs |
| 17 | + displayName: Optional list of package names whose repo's source will also be synchronized in the local VMR, e.g. NuGet.Protocol |
| 18 | + type: object |
| 19 | + default: [] |
| 20 | + |
| 21 | +steps: |
| 22 | +- checkout: vmr |
| 23 | + displayName: Clone dotnet/dotnet |
| 24 | + path: vmr |
| 25 | + clean: true |
| 26 | + |
| 27 | +- checkout: self |
| 28 | + displayName: Clone $(Build.Repository.Name) |
| 29 | + path: repo |
| 30 | + fetchDepth: 0 |
| 31 | + |
| 32 | +# This step is needed so that when we get a detached HEAD / shallow clone, |
| 33 | +# we still pull the commit into the temporary repo clone to use it during the sync. |
| 34 | +# Also unshallow the clone so that forwardflow command would work. |
| 35 | +- script: | |
| 36 | + git branch repo-head |
| 37 | + git rev-parse HEAD |
| 38 | + displayName: Label PR commit |
| 39 | + workingDirectory: $(Agent.BuildDirectory)/repo |
| 40 | + |
| 41 | +- script: | |
| 42 | + vmr_sha=$(grep -oP '(?<=Sha=")[^"]*' $(Agent.BuildDirectory)/repo/eng/Version.Details.xml) |
| 43 | + echo "##vso[task.setvariable variable=vmr_sha]$vmr_sha" |
| 44 | + displayName: Obtain the vmr sha from Version.Details.xml (Unix) |
| 45 | + condition: ne(variables['Agent.OS'], 'Windows_NT') |
| 46 | + workingDirectory: $(Agent.BuildDirectory)/repo |
| 47 | + |
| 48 | +- powershell: | |
| 49 | + [xml]$xml = Get-Content -Path $(Agent.BuildDirectory)/repo/eng/Version.Details.xml |
| 50 | + $vmr_sha = $xml.SelectSingleNode("//Source").Sha |
| 51 | + Write-Output "##vso[task.setvariable variable=vmr_sha]$vmr_sha" |
| 52 | + displayName: Obtain the vmr sha from Version.Details.xml (Windows) |
| 53 | + condition: eq(variables['Agent.OS'], 'Windows_NT') |
| 54 | + workingDirectory: $(Agent.BuildDirectory)/repo |
| 55 | + |
| 56 | +- script: | |
| 57 | + git fetch --all |
| 58 | + git checkout $(vmr_sha) |
| 59 | + displayName: Checkout VMR at correct sha for repo flow |
| 60 | + workingDirectory: ${{ parameters.vmrPath }} |
| 61 | + |
| 62 | +- script: | |
| 63 | + git config --global user.name "dotnet-maestro[bot]" |
| 64 | + git config --global user.email "dotnet-maestro[bot]@users.noreply.github.com" |
| 65 | + displayName: Set git author to dotnet-maestro[bot] |
| 66 | + workingDirectory: ${{ parameters.vmrPath }} |
| 67 | + |
| 68 | +- script: | |
| 69 | + ./eng/common/vmr-sync.sh \ |
| 70 | + --vmr ${{ parameters.vmrPath }} \ |
| 71 | + --tmp $(Agent.TempDirectory) \ |
| 72 | + --azdev-pat '$(dn-bot-all-orgs-code-r)' \ |
| 73 | + --ci \ |
| 74 | + --debug |
| 75 | +
|
| 76 | + if [ "$?" -ne 0 ]; then |
| 77 | + echo "##vso[task.logissue type=error]Failed to synchronize the VMR" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + displayName: Sync repo into VMR (Unix) |
| 81 | + condition: ne(variables['Agent.OS'], 'Windows_NT') |
| 82 | + workingDirectory: $(Agent.BuildDirectory)/repo |
| 83 | + |
| 84 | +- script: | |
| 85 | + git config --global diff.astextplain.textconv echo |
| 86 | + git config --system core.longpaths true |
| 87 | + displayName: Configure Windows git (longpaths, astextplain) |
| 88 | + condition: eq(variables['Agent.OS'], 'Windows_NT') |
| 89 | + |
| 90 | +- powershell: | |
| 91 | + ./eng/common/vmr-sync.ps1 ` |
| 92 | + -vmr ${{ parameters.vmrPath }} ` |
| 93 | + -tmp $(Agent.TempDirectory) ` |
| 94 | + -azdevPat '$(dn-bot-all-orgs-code-r)' ` |
| 95 | + -ci ` |
| 96 | + -debugOutput |
| 97 | +
|
| 98 | + if ($LASTEXITCODE -ne 0) { |
| 99 | + echo "##vso[task.logissue type=error]Failed to synchronize the VMR" |
| 100 | + exit 1 |
| 101 | + } |
| 102 | + displayName: Sync repo into VMR (Windows) |
| 103 | + condition: eq(variables['Agent.OS'], 'Windows_NT') |
| 104 | + workingDirectory: $(Agent.BuildDirectory)/repo |
| 105 | + |
| 106 | +- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: |
| 107 | + - task: CopyFiles@2 |
| 108 | + displayName: Collect failed patches |
| 109 | + condition: failed() |
| 110 | + inputs: |
| 111 | + SourceFolder: '$(Agent.TempDirectory)' |
| 112 | + Contents: '*.patch' |
| 113 | + TargetFolder: '$(Build.ArtifactStagingDirectory)/FailedPatches' |
| 114 | + |
| 115 | + - publish: '$(Build.ArtifactStagingDirectory)/FailedPatches' |
| 116 | + artifact: $(System.JobDisplayName)_FailedPatches |
| 117 | + displayName: Upload failed patches |
| 118 | + condition: failed() |
| 119 | + |
| 120 | +- ${{ each assetName in parameters.additionalSyncs }}: |
| 121 | + # The vmr-sync script ends up staging files in the local VMR so we have to commit those |
| 122 | + - script: |
| 123 | + git commit --allow-empty -am "Forward-flow $(Build.Repository.Name)" |
| 124 | + displayName: Commit local VMR changes |
| 125 | + workingDirectory: ${{ parameters.vmrPath }} |
| 126 | + |
| 127 | + - script: | |
| 128 | + set -ex |
| 129 | +
|
| 130 | + echo "Searching for details of asset ${{ assetName }}..." |
| 131 | +
|
| 132 | + # Use darc to get dependencies information |
| 133 | + dependencies=$(./.dotnet/dotnet darc get-dependencies --name '${{ assetName }}' --ci) |
| 134 | +
|
| 135 | + # Extract repository URL and commit hash |
| 136 | + repository=$(echo "$dependencies" | grep 'Repo:' | sed 's/Repo:[[:space:]]*//' | head -1) |
| 137 | +
|
| 138 | + if [ -z "$repository" ]; then |
| 139 | + echo "##vso[task.logissue type=error]Asset ${{ assetName }} not found in the dependency list" |
| 140 | + exit 1 |
| 141 | + fi |
| 142 | +
|
| 143 | + commit=$(echo "$dependencies" | grep 'Commit:' | sed 's/Commit:[[:space:]]*//' | head -1) |
| 144 | +
|
| 145 | + echo "Updating the VMR from $repository / $commit..." |
| 146 | + cd .. |
| 147 | + git clone $repository ${{ assetName }} |
| 148 | + cd ${{ assetName }} |
| 149 | + git checkout $commit |
| 150 | + git branch "sync/$commit" |
| 151 | +
|
| 152 | + ./eng/common/vmr-sync.sh \ |
| 153 | + --vmr ${{ parameters.vmrPath }} \ |
| 154 | + --tmp $(Agent.TempDirectory) \ |
| 155 | + --azdev-pat '$(dn-bot-all-orgs-code-r)' \ |
| 156 | + --ci \ |
| 157 | + --debug |
| 158 | +
|
| 159 | + if [ "$?" -ne 0 ]; then |
| 160 | + echo "##vso[task.logissue type=error]Failed to synchronize the VMR" |
| 161 | + exit 1 |
| 162 | + fi |
| 163 | + displayName: Sync ${{ assetName }} into (Unix) |
| 164 | + condition: ne(variables['Agent.OS'], 'Windows_NT') |
| 165 | + workingDirectory: $(Agent.BuildDirectory)/repo |
| 166 | +
|
| 167 | + - powershell: | |
| 168 | + $ErrorActionPreference = 'Stop' |
| 169 | +
|
| 170 | + Write-Host "Searching for details of asset ${{ assetName }}..." |
| 171 | +
|
| 172 | + $dependencies = .\.dotnet\dotnet darc get-dependencies --name '${{ assetName }}' --ci |
| 173 | +
|
| 174 | + $repository = $dependencies | Select-String -Pattern 'Repo:\s+([^\s]+)' | Select-Object -First 1 |
| 175 | + $repository -match 'Repo:\s+([^\s]+)' | Out-Null |
| 176 | + $repository = $matches[1] |
| 177 | +
|
| 178 | + if ($repository -eq $null) { |
| 179 | + Write-Error "Asset ${{ assetName }} not found in the dependency list" |
| 180 | + exit 1 |
| 181 | + } |
| 182 | +
|
| 183 | + $commit = $dependencies | Select-String -Pattern 'Commit:\s+([^\s]+)' | Select-Object -First 1 |
| 184 | + $commit -match 'Commit:\s+([^\s]+)' | Out-Null |
| 185 | + $commit = $matches[1] |
| 186 | +
|
| 187 | + Write-Host "Updating the VMR from $repository / $commit..." |
| 188 | + cd .. |
| 189 | + git clone $repository ${{ assetName }} |
| 190 | + cd ${{ assetName }} |
| 191 | + git checkout $commit |
| 192 | + git branch "sync/$commit" |
| 193 | +
|
| 194 | + .\eng\common\vmr-sync.ps1 ` |
| 195 | + -vmr ${{ parameters.vmrPath }} ` |
| 196 | + -tmp $(Agent.TempDirectory) ` |
| 197 | + -azdevPat '$(dn-bot-all-orgs-code-r)' ` |
| 198 | + -ci ` |
| 199 | + -debugOutput |
| 200 | +
|
| 201 | + if ($LASTEXITCODE -ne 0) { |
| 202 | + echo "##vso[task.logissue type=error]Failed to synchronize the VMR" |
| 203 | + exit 1 |
| 204 | + } |
| 205 | + displayName: Sync ${{ assetName }} into (Windows) |
| 206 | + condition: ne(variables['Agent.OS'], 'Windows_NT') |
| 207 | + workingDirectory: $(Agent.BuildDirectory)/repo |
0 commit comments