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 ;
2
16
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
17
using System . IO ;
5
18
using System . Linq ;
6
19
using System . Management . Automation ;
7
20
using System . Reflection ;
21
+ using Tools . Common . Loaders ;
8
22
using Tools . Common . Models ;
9
- using VersionController . Models ;
10
23
using Tools . Common . Utilities ;
11
- using Tools . Common . Loaders ;
24
+ using VersionController . Models ;
12
25
13
26
namespace VersionController
14
27
{
@@ -104,6 +117,43 @@ private static bool GetModuleReadMe(string directory)
104
117
/// </summary>
105
118
private static void BumpVersions ( )
106
119
{
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
+
107
157
var changedModules = new List < string > ( ) ;
108
158
foreach ( var directory in _projectDirectories )
109
159
{
@@ -132,7 +182,8 @@ private static void BumpVersions()
132
182
}
133
183
}
134
184
}
135
-
185
+ //Make Az.Accounts as the first module to calcuate
186
+ changedModules = changedModules . OrderBy ( c => c == "Az.Accounts" ? "" : c ) . ToList ( ) ;
136
187
foreach ( var projectModuleManifestPath in changedModules )
137
188
{
138
189
var moduleFileName = Path . GetFileName ( projectModuleManifestPath ) ;
@@ -154,8 +205,8 @@ private static void BumpVersions()
154
205
var outputModuleManifestFile = outputModuleManifest . FirstOrDefault ( ) ;
155
206
156
207
_versionBumper = new VersionBumper ( new VersionFileHelper ( _rootDirectory , outputModuleManifestFile , projectModuleManifestPath ) ) ;
157
-
158
- if ( _minimalVersion . ContainsKey ( moduleName ) )
208
+ _versionBumper . PSRepositories = targetRepositories ;
209
+ if ( _minimalVersion . ContainsKey ( moduleName ) )
159
210
{
160
211
_versionBumper . MinimalVersion = _minimalVersion [ moduleName ] ;
161
212
}
0 commit comments