@@ -1522,11 +1522,17 @@ class CocoapodsInstaller {
15221522 static getVersionFromPodfile ( podfilePath ) {
15231523 const absolutePath = path . resolve ( podfilePath ) ;
15241524 if ( ! fs . existsSync ( absolutePath ) ) {
1525- throw new Error ( `podfile is not found on path '${ absolutePath } '` ) ;
1525+ throw new Error ( `Podfile is not found on path '${ absolutePath } '` ) ;
15261526 }
15271527 const fileContent = fs . readFileSync ( absolutePath ) ;
1528- const fileLines = fileContent . toString ( ) . split ( os_1 . EOL ) ;
1529- return fileLines [ 0 ] ;
1528+ const podLines = fileContent . toString ( ) . split ( os_1 . EOL ) ;
1529+ for ( const podLine of podLines ) {
1530+ const match = podLine . match ( this . podVersionRegex ) ;
1531+ if ( match && match . length >= 2 ) {
1532+ return match [ 1 ] . trim ( ) ;
1533+ }
1534+ }
1535+ throw new Error ( `Podfile '${ absolutePath } ' doesn't contain COCOAPODS version.` ) ;
15301536 }
15311537 static async getInstalledVersion ( ) {
15321538 let stdOutput = "" ;
@@ -1545,6 +1551,7 @@ class CocoapodsInstaller {
15451551 }
15461552}
15471553exports . CocoapodsInstaller = CocoapodsInstaller ;
1554+ CocoapodsInstaller . podVersionRegex = / ^ C O C O A P O D S : ( [ \d . ] + ) $ / i;
15481555
15491556
15501557/***/ } ) ,
@@ -1569,14 +1576,15 @@ const run = async () => {
15691576 if ( process . platform !== "darwin" ) {
15701577 throw new Error ( `This task is intended only for macOS platform. It can't be run on '${ process . platform } ' platform` ) ;
15711578 }
1572- const versionInput = core . getInput ( "version" , { required : false } ) ;
1573- const podfilePathInput = core . getInput ( "podfile-path" , { required : false } ) ;
1574- if ( ! ! versionInput === ! ! podfilePathInput ) {
1579+ let versionSpec = core . getInput ( "version" , { required : false } ) ;
1580+ const podfilePath = core . getInput ( "podfile-path" , { required : false } ) ;
1581+ if ( ! ! versionSpec === ! ! podfilePath ) {
15751582 throw new Error ( "Invalid input parameters usage. Only 'version' or 'podfile-path' should be defined" ) ;
15761583 }
1577- const versionSpec = versionInput ; // || CocoapodsInstaller.getVersionFromPodfile(podfilePathInput);
15781584 if ( ! versionSpec ) {
1579- throw new Error ( `Invalid version format '${ versionSpec } '` ) ;
1585+ core . debug ( "Reading Podfile to determine the version of Cocoapods..." ) ;
1586+ versionSpec = installer_1 . CocoapodsInstaller . getVersionFromPodfile ( podfilePath ) ;
1587+ core . info ( `Podfile points to the Cocoapods ${ versionSpec } ` ) ;
15801588 }
15811589 await installer_1 . CocoapodsInstaller . install ( versionSpec ) ;
15821590 }
0 commit comments