Skip to content

Commit 8cf3246

Browse files
authored
Make testgallery as optional during version bump (#17541)
1 parent 392aa58 commit 8cf3246

File tree

4 files changed

+71
-38
lines changed

4 files changed

+71
-38
lines changed

.azure-pipelines/daily-build.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Please don't use ADO UI defined scheduled triggers because it takes precedence over YAML scheduled triggers.
22
# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers
3+
variables:
4+
today: $(Get-Date -Format yyyyMMddhhmmss)
5+
36
schedules:
47
- cron: "0 18 * * *"
58
displayName: 2:00 AM (UTC + 8:00) China Daily Build
@@ -55,24 +58,11 @@ jobs:
5558
targetType: 'inline'
5659
script: |
5760
$command = "`$PSVersionTable `
58-
./tools/RunVersionController.ps1 -MonthName $(MonthName) -Year $(Year) `
61+
Get-PSRepository `
62+
./tools/RunVersionController.ps1 -Release 'Daily Build $(today)' `
5963
Exit"
6064
dotnet tool run pwsh -c $command
6165
62-
# - task: PowerShell@2
63-
# displayName: 'Push to Branch internal/dailybuild'
64-
# inputs:
65-
# targetType: 'inline'
66-
# script: |
67-
# git config user.email "[email protected]"
68-
# git config user.name "azuresdkci"
69-
# git remote set-url origin https://$(Token)@github.com/Azure/azure-powershell.git
70-
# git checkout -b internal/dailybuild
71-
# git add .
72-
# git commit -m "Bump Version"
73-
# git status
74-
# git push -u origin internal/dailybuild --force
75-
7666
- task: PowerShell@2
7767
displayName: 'Clean artifacts folder'
7868
inputs:
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
"Module","Minimal Version"
2-
"Az.Security","1.1.1"
3-
"Az.CloudService","1.0.0"
4-
"Az.Functions","4.0.0"
5-
"Az.StackHCI","1.0.0"
6-
"Az.MySql","1.0.0"
7-
"Az.PostgreSql","1.0.0"
8-
"Az.Synapse","1.0.0"
1+
"Module","Minimal Version"

tools/VersionController/Models/VersionBumper.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class VersionBumper
3535
private bool _isPreview;
3636

3737
public AzurePSVersion MinimalVersion { get; set; }
38+
public string PSRepositories { get; set; }
3839

3940
public VersionBumper(VersionFileHelper fileHelper)
4041
{
@@ -93,7 +94,6 @@ public Tuple<string, bool> GetOldVersion()
9394

9495
using (PowerShell powershell = PowerShell.Create())
9596
{
96-
powershell.AddScript("Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process;");
9797
powershell.AddScript("$metadata = Test-ModuleManifest -Path " + _fileHelper.OutputModuleManifestPath + ";$metadata.Version;$metadata.PrivateData.PSData.Prerelease");
9898
var cmdletResult = powershell.Invoke();
9999
localVersion = cmdletResult[0]?.ToString();
@@ -220,15 +220,14 @@ private List<AzurePSVersion> GetGalleryVersion()
220220
HashSet<AzurePSVersion> galleryVersion = new HashSet<AzurePSVersion>();
221221
using (PowerShell powershell = PowerShell.Create())
222222
{
223-
powershell.AddScript("Register-PackageSource -Name PSGallery -Location https://www.powershellgallery.com/api/v2 -ProviderName PowerShellGet");
224-
powershell.AddScript("Register-PackageSource -Name TestGallery -Location https://www.poshtestgallery.com/api/v2 -ProviderName PowerShellGet");
225-
powershell.AddScript("Find-Module -Name " + moduleName + " -Repository PSGallery, TestGallery -AllowPrerelease -AllVersions");
223+
powershell.AddScript($"Find-Module -Name {moduleName} -Repository {PSRepositories} -AllowPrerelease -AllVersions");
226224
var cmdletResult = powershell.Invoke();
227-
foreach (var versionImformation in cmdletResult)
225+
foreach (var versionInformation in cmdletResult)
228226
{
229-
Regex reg = new Regex("Version=(.*?);");
230-
Match match = reg.Match(versionImformation.ToString());
231-
galleryVersion.Add(new AzurePSVersion(match.Groups[1].Value));
227+
if(versionInformation.Properties["Version"]?.Value != null)
228+
{
229+
galleryVersion.Add(new AzurePSVersion(versionInformation.Properties["Version"]?.Value?.ToString()));
230+
}
232231
}
233232
}
234233
return galleryVersion.ToList();

tools/VersionController/Program.cs

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
using System;
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
216
using System.Collections.Generic;
3-
using System.Diagnostics;
417
using System.IO;
518
using System.Linq;
619
using System.Management.Automation;
720
using System.Reflection;
21+
using Tools.Common.Loaders;
822
using Tools.Common.Models;
9-
using VersionController.Models;
1023
using Tools.Common.Utilities;
11-
using Tools.Common.Loaders;
24+
using VersionController.Models;
1225

1326
namespace VersionController
1427
{
@@ -104,6 +117,43 @@ private static bool GetModuleReadMe(string directory)
104117
/// </summary>
105118
private static void BumpVersions()
106119
{
120+
string targetRepositories = null;
121+
using (PowerShell powershell = PowerShell.Create())
122+
{
123+
powershell.AddScript("Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process;");
124+
powershell.AddScript("Register-PackageSource -Name PSGallery -Location https://www.powershellgallery.com/api/v2 -ProviderName PowerShellGet");
125+
powershell.AddScript("Register-PackageSource -Name TestGallery -Location https://www.poshtestgallery.com/api/v2 -ProviderName PowerShellGet");
126+
powershell.AddScript("Get-PSRepository");
127+
var repositories = powershell.Invoke();
128+
string psgallery = null;
129+
string testgallery = null;
130+
foreach (var repo in repositories)
131+
{
132+
if ("https://www.powershellgallery.com/api/v2".Equals(repo.Properties["SourceLocation"]?.Value))
133+
{
134+
psgallery = repo.Properties["Name"]?.Value?.ToString();
135+
}
136+
if ("https://www.poshtestgallery.com/api/v2".Equals(repo.Properties["SourceLocation"]?.Value))
137+
{
138+
testgallery = repo.Properties["Name"]?.Value?.ToString();
139+
}
140+
}
141+
if (psgallery == null)
142+
{
143+
throw new Exception("Cannot calculate module version because PSGallery is not available.");
144+
}
145+
targetRepositories = psgallery;
146+
if (testgallery == null)
147+
{
148+
Console.WriteLine("Warning: Cannot calculate module version precisely because TestGallery is not available.");
149+
}
150+
else
151+
{
152+
targetRepositories += $",{testgallery}";
153+
}
154+
155+
}
156+
107157
var changedModules = new List<string>();
108158
foreach (var directory in _projectDirectories)
109159
{
@@ -132,7 +182,8 @@ private static void BumpVersions()
132182
}
133183
}
134184
}
135-
185+
//Make Az.Accounts as the first module to calcuate
186+
changedModules = changedModules.OrderBy(c => c == "Az.Accounts" ? "" : c).ToList();
136187
foreach (var projectModuleManifestPath in changedModules)
137188
{
138189
var moduleFileName = Path.GetFileName(projectModuleManifestPath);
@@ -154,8 +205,8 @@ private static void BumpVersions()
154205
var outputModuleManifestFile = outputModuleManifest.FirstOrDefault();
155206

156207
_versionBumper = new VersionBumper(new VersionFileHelper(_rootDirectory, outputModuleManifestFile, projectModuleManifestPath));
157-
158-
if(_minimalVersion.ContainsKey(moduleName))
208+
_versionBumper.PSRepositories = targetRepositories;
209+
if (_minimalVersion.ContainsKey(moduleName))
159210
{
160211
_versionBumper.MinimalVersion = _minimalVersion[moduleName];
161212
}

0 commit comments

Comments
 (0)