From f3f99aa1b9d3306f760ee7834901845552d32470 Mon Sep 17 00:00:00 2001 From: azure-sdk Date: Wed, 19 Aug 2020 00:23:52 +0000 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools repository for Tools PR https://github.com/Azure/azure-sdk-tools/pull/899 --- eng/common/README.md | 13 +++++- .../templates/steps/create-pull-request.yml | 2 + eng/common/scripts/Submit-PullRequest.ps1 | 4 +- eng/common/scripts/Verify-Resource-Ref.ps1 | 43 +++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 eng/common/scripts/Verify-Resource-Ref.ps1 diff --git a/eng/common/README.md b/eng/common/README.md index f855e54adae..0c413a8ea5b 100644 --- a/eng/common/README.md +++ b/eng/common/README.md @@ -9,4 +9,15 @@ should not contain binary files as they don't play well with git. Any updates to files in the `eng/common` directory should be made in the [azure-sdk-tools](https://github.com/azure/azure-sdk-tools) repo. All changes made will cause a PR to created in all subscribed azure-sdk language repos which will blindly replace all contents of the `eng/common` directory in that repo. For that reason do **NOT** make changes to files in this directory in the individual azure-sdk -languages repos as they will be overwritten the next time an update is taken from the common azure-sdk-tools repo. \ No newline at end of file +languages repos as they will be overwritten the next time an update is taken from the common azure-sdk-tools repo. + +### Workflow + +Starting from [these changes](https://github.com/Azure/azure-sdk-tools/commit/401dbcaa17075ceb94073b6a4d7acafce8687a5d) the 'Sync eng/common directory' PRs will be created in the language repositories once a pull request that touches the eng/common directory is submitted against the master branch. This will make it easier for changes to be tested in each individual language repo before merging the changes in the azure-sdk-tools repo. The workflow is explained bellow + +1. Create a PR against Azure/azure-sdk-tools:master. This is the **Tools PR**. +2. `azure-sdk-tools - sync - eng-common` is run automatically. It creates **Sync PRs** in each of the connected language repositories using the format `Sync eng/common directory with azure-sdk-tools for PR {Tools PR Number}`. Each **Sync PR** will contain a link back to the **Tools PR** that triggered it. +3. More changes pushed to the **Tools PR**, will automatically triggered new pipeline runs in the respective **Sync PRs**. The **Sync PRs** are used to make sure the changes would not break any of the connected pipelines. +4. Once satisfied with the changes; + - First merge all the **Sync PRs**. The **Tools PR** contains links to all the **Sync PRs** + - Finally merge the **Tools PR**. Each **Sync PR** contains the link to the corresponding **Tools PR**. \ No newline at end of file diff --git a/eng/common/pipelines/templates/steps/create-pull-request.yml b/eng/common/pipelines/templates/steps/create-pull-request.yml index 10af61de110..7b3e3a75f45 100644 --- a/eng/common/pipelines/templates/steps/create-pull-request.yml +++ b/eng/common/pipelines/templates/steps/create-pull-request.yml @@ -11,6 +11,7 @@ parameters: PushArgs: WorkingDirectory: $(System.DefaultWorkingDirectory) PRTitle: not-specified + PRBody: not-specified ScriptDirectory: eng/common/scripts GHReviewersVariable: '' GHTeamReviewersVariable: '' @@ -65,6 +66,7 @@ steps: -PRBranch "${{ parameters.PRBranchName }}" -AuthToken "$(azuresdk-github-pat)" -PRTitle "${{ parameters.PRTitle }}" + -PRBody "${{ parameters.PRBody }}" - task: PowerShell@2 displayName: Tag a Reviewer on PR diff --git a/eng/common/scripts/Submit-PullRequest.ps1 b/eng/common/scripts/Submit-PullRequest.ps1 index 5edabc599a9..732d0d4b2b9 100644 --- a/eng/common/scripts/Submit-PullRequest.ps1 +++ b/eng/common/scripts/Submit-PullRequest.ps1 @@ -38,7 +38,9 @@ param( [Parameter(Mandatory = $true)] $PRTitle, - $PRBody = $PRTitle + + [Parameter(Mandatory = $true)] + $PRBody ) $headers = @{ diff --git a/eng/common/scripts/Verify-Resource-Ref.ps1 b/eng/common/scripts/Verify-Resource-Ref.ps1 new file mode 100644 index 00000000000..9b8d6c9c862 --- /dev/null +++ b/eng/common/scripts/Verify-Resource-Ref.ps1 @@ -0,0 +1,43 @@ + +. (Join-Path $PSScriptRoot common.ps1) +Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser +$ymlfiles = Get-ChildItem $RepoRoot | Where-Object {$_ -like '*.yml'} +$affectedRepos = @() + +foreach ($file in $ymlfiles) +{ + Write-Host "Verifying '${file}'" + $ymlContent = Get-Content $file.FullName -Raw + $ymlObject = ConvertFrom-Yaml $ymlContent -Ordered + + if ($ymlObject.Contains("resources")) + { + if ($ymlObject["resources"]["repositories"]) + { + $repositories = $ymlObject["resources"]["repositories"] + foreach ($repo in $repositories) + { + $repoName = $repo["repository"] + if (-not ($repo.Contains("ref"))) + { + $errorMessage = "File: ${file}, Repository: ${repoName}." + $affectedRepos.Add($errorMessage) + } + } + } + } +} + +if ($affectedRepos.Count -gt 0) +{ + Write-Error "Ref not found in the following Repository Resources." + foreach ($errorMessage in $affectedRepos) + { + Write-Information $errorMessage + } + Write-Information "Please ensure you add a Ref: when using repository resources" + Write-Information "More Info at https://aka.ms/azsdk/engsys/tools-versioning" + exit 1 +} + +Write-Information "All repository resources in yaml files reference a valid tag" \ No newline at end of file