@@ -16,31 +16,51 @@ var __importStar = (this && this.__importStar) || function (mod) {
1616 return result ;
1717} ;
1818Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
19+ const core = __importStar ( require ( "@actions/core" ) ) ;
1920const exec = __importStar ( require ( "@actions/exec" ) ) ;
2021const io = __importStar ( require ( "@actions/io" ) ) ;
2122var psPath ;
2223exports . initializeAz = ( servicePrincipalId , servicePrincipalKey , tenantId , subscriptionId ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
2324 psPath = yield io . which ( "pwsh" , true ) ;
2425 setPSModulePath ( ) ;
26+ setPSModulePath ( yield getLatestAzModule ( ) ) ;
2527 yield loginToAzure ( servicePrincipalId , servicePrincipalKey , tenantId , subscriptionId ) ;
2628} ) ;
27- function setPSModulePath ( ) {
28- // TODO: get latest module/setup action
29- let azPSVersion = "3.5.0" ;
29+ function setPSModulePath ( azPSVersion = "" ) {
3030 let modulePath = "" ;
3131 switch ( process . env . RUNNER_OS ) {
3232 case "Linux" :
33- modulePath = `/usr/share/az_ ${ azPSVersion } :` ;
33+ modulePath = `/usr/share/${ azPSVersion } :` ;
3434 break ;
3535 case "Windows" :
36- modulePath = `C:\\Modules\\az_ ${ azPSVersion } ;` ;
36+ modulePath = `C:\\Modules\\${ azPSVersion } ;` ;
3737 break ;
3838 case "macOS" :
3939 // TODO: add modulepath
4040 break ;
4141 }
4242 process . env . PSModulePath = `${ modulePath } ${ process . env . PSModulePath } ` ;
4343}
44+ function getLatestAzModule ( ) {
45+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
46+ const moduleName = "Az.Accounts" ;
47+ let output = "" ;
48+ let error = "" ;
49+ let options = {
50+ listeners : {
51+ stdout : ( data ) => {
52+ output += data . toString ( ) ;
53+ } ,
54+ stderr : ( data ) => {
55+ error += data . toString ( ) ;
56+ }
57+ }
58+ } ;
59+ yield executePowerShellCommand ( `(Get-Module -Name ${ moduleName } -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()` , options ) ;
60+ core . debug ( `Az Module version used: ${ output } ` ) ;
61+ return `az_${ output } ` ;
62+ } ) ;
63+ }
4464function loginToAzure ( servicePrincipalId , servicePrincipalKey , tenantId , subscriptionId ) {
4565 return __awaiter ( this , void 0 , void 0 , function * ( ) {
4666 const environment = "AzureCloud" ;
@@ -53,10 +73,10 @@ function loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscri
5373 yield executePowerShellCommand ( `Get-AzContext` ) ;
5474 } ) ;
5575}
56- function executePowerShellCommand ( command ) {
76+ function executePowerShellCommand ( command , options = { } ) {
5777 return __awaiter ( this , void 0 , void 0 , function * ( ) {
5878 try {
59- yield exec . exec ( `"${ psPath } " -Command "${ command } "` , [ ] , { } ) ;
79+ yield exec . exec ( `"${ psPath } " -Command "${ command } "` , [ ] , options ) ;
6080 }
6181 catch ( error ) {
6282 throw new Error ( error ) ;
0 commit comments