Begin Implementing Ref Updater (#662)
* Begin Implementing Ref Updater * Switch to using Regex Replace * Remove Yaml Parser * Use different repository Names
This commit is contained in:
Родитель
36c1c96a50
Коммит
ef75c6005d
|
@ -0,0 +1,36 @@
|
|||
# Updates repository Refs on all pipelines
|
||||
parameters:
|
||||
Tag: ''
|
||||
ToolRepo: ''
|
||||
ToolsRepoPath: ''
|
||||
Repos: []
|
||||
|
||||
steps:
|
||||
|
||||
- ${{ each repo in parameters.Repos }}:
|
||||
- pwsh: |
|
||||
git clone --branch master https://github.com/azure/${{ repo }}
|
||||
displayName: Clone ${{ repo }}
|
||||
workingDirectory: $(System.DefaultWorkingDirectory)
|
||||
|
||||
- task: Powershell@2
|
||||
inputs:
|
||||
targetType: 'filePath'
|
||||
filePath: ${{ parameters.ToolsRepoPath }}/scripts/powershell/ref-updater.ps1
|
||||
arguments: >
|
||||
-RepoRoot $(System.DefaultWorkingDirectory)/${{ repo }}
|
||||
-Tag ${{ parameters.Tag }}
|
||||
-ToolRepo ${{ parameters.ToolRepo }}
|
||||
pwsh: true
|
||||
displayName: Update Refs
|
||||
|
||||
- template: ../../../common/pipelines/templates/steps/create-pull-request.yml
|
||||
parameters:
|
||||
RepoName: ${{ repo }}
|
||||
PRBranchName: UpdateRepositoryRefsFor${{ parameters.ToolRepo }}
|
||||
CommitMsg: Update ${{ parameters.ToolRepo }} Repository Resource Refs in Yaml files
|
||||
PRTitle: Update ${{ parameters.ToolRepo }} Repository Resource Refs in Yaml files
|
||||
PushArgs: -f
|
||||
WorkingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
|
||||
ScriptDirectory: ${{ parameters.ToolsRepoPath }}/eng/common/scripts
|
||||
BaseBranchName: refs/heads/master
|
|
@ -16,7 +16,24 @@ jobs:
|
|||
# Remove Organization name i.e Transform Azure/azure-sdk-tools -> azure-sdk-tools before appending build Number
|
||||
$Tag = "$(Build.Repository.Name)".SubString("$(Build.Repository.Name)".IndexOf('/') + 1) + "_$(Build.BuildNumber)"
|
||||
Write-Host "Tagging Repo with $Tag"
|
||||
echo "##vso[task.setvariable variable=Tag]$Tag"
|
||||
git -c user.name="azure-sdk" -c user.email="azuresdk@microsoft.com" tag -a $tag -m "Release tools version $Tag"
|
||||
git push $PushURL $tag
|
||||
displayName: Create and Push Version Tag
|
||||
workingDirectory: $(Build.SourcesDirectory)
|
||||
|
||||
- template: /eng/pipelines/templates/steps/ref-updater.yml
|
||||
parameters:
|
||||
Tag: $(Tag)
|
||||
ToolRepo: azure-sdk-tools
|
||||
ToolsRepoPath: $(Build.SourcesDirectory)
|
||||
Repos:
|
||||
# - azure-sdk-for-android
|
||||
# - azure-sdk-for-c
|
||||
# - azure-sdk-for-cpp
|
||||
# - azure-sdk-for-go
|
||||
# - azure-sdk-for-ios
|
||||
- azure-sdk-for-java
|
||||
- azure-sdk-for-js
|
||||
- azure-sdk-for-net
|
||||
# - azure-sdk-for-python
|
|
@ -0,0 +1,31 @@
|
|||
# Updates the Ref in all Yml files in the Repository
|
||||
param (
|
||||
[Parameter(Mandatory=$True)]
|
||||
[String]$RepoRoot,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[String]$Tag,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[String]$ToolRepo
|
||||
)
|
||||
|
||||
$ymlFiles = Get-ChildItem -Path $RepoRoot -File -Include *.yml -Recurse
|
||||
|
||||
foreach ($file in $ymlFiles)
|
||||
{
|
||||
$regex = [Regex]"ref: refs/tags/${ToolRepo}_[\d\.]+"
|
||||
Write-Host "Operating on: " $file.FullName
|
||||
$ymlContent = Get-Content $file.FullName -Raw
|
||||
|
||||
$updated = $false
|
||||
|
||||
if ($ymlContent -match $regex)
|
||||
{
|
||||
$ymlContent = $regex.Replace($ymlContent, "ref: refs/tags/$Tag", 1)
|
||||
$updated = $true
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
Write-Host "Updated " $file.FullName
|
||||
$ymlContent | Set-Content -Path $file.FullName -Force -NoNewline
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче