@@ -44,20 +44,21 @@ const exc = __importStar(require("@actions/exec"));
4444const io = __importStar ( require ( "@actions/io" ) ) ;
4545let osPlat = os . platform ( ) ;
4646let osArch = os . arch ( ) ;
47- function getProtoc ( version , includePreReleases ) {
47+ function getProtoc ( version , includePreReleases , repoToken ) {
4848 return __awaiter ( this , void 0 , void 0 , function * ( ) {
4949 // resolve the version number
50- const targetVersion = yield computeVersion ( version , includePreReleases ) ;
50+ const targetVersion = yield computeVersion ( version , includePreReleases , repoToken ) ;
5151 if ( targetVersion ) {
5252 version = targetVersion ;
5353 }
54+ process . stdout . write ( "Getting protoc version: " + version + os . EOL ) ;
5455 // look if the binary is cached
5556 let toolPath ;
5657 toolPath = tc . find ( "protoc" , version ) ;
5758 // if not: download, extract and cache
5859 if ( ! toolPath ) {
5960 toolPath = yield downloadRelease ( version ) ;
60- core . debug ( "Protoc cached under " + toolPath ) ;
61+ process . stdout . write ( "Protoc cached under " + toolPath + os . EOL ) ;
6162 }
6263 // add the bin folder to the PATH
6364 toolPath = path . join ( toolPath , "bin" ) ;
@@ -89,6 +90,7 @@ function downloadRelease(version) {
8990 // Download
9091 let fileName = getFileName ( version ) ;
9192 let downloadUrl = util . format ( "https://github.com/protocolbuffers/protobuf/releases/download/%s/%s" , version , fileName ) ;
93+ process . stdout . write ( "Downloading archive: " + downloadUrl + os . EOL ) ;
9294 let downloadPath = null ;
9395 try {
9496 downloadPath = yield tc . downloadTool ( downloadUrl ) ;
@@ -114,13 +116,23 @@ function getFileName(version) {
114116 return util . format ( "protoc-%s-win%s.zip" , version , arch ) ;
115117 }
116118 const arch = osArch == "x64" ? "x86_64" : "x86_32" ;
117- const filename = util . format ( "protoc-%s-linux-%s.zip" , version , arch ) ;
118- return filename ;
119+ if ( osPlat == "darwin" ) {
120+ return util . format ( "protoc-%s-osx-%s.zip" , version , arch ) ;
121+ }
122+ return util . format ( "protoc-%s-linux-%s.zip" , version , arch ) ;
119123}
120124// Retrieve a list of versions scraping tags from the Github API
121- function fetchVersions ( includePreReleases ) {
125+ function fetchVersions ( includePreReleases , repoToken ) {
122126 return __awaiter ( this , void 0 , void 0 , function * ( ) {
123- let rest = new restm . RestClient ( "setup-protoc" ) ;
127+ let rest ;
128+ if ( repoToken != "" ) {
129+ rest = new restm . RestClient ( "setup-protoc" , "" , [ ] , {
130+ headers : { Authorization : "Bearer " + repoToken }
131+ } ) ;
132+ }
133+ else {
134+ rest = new restm . RestClient ( "setup-protoc" ) ;
135+ }
124136 let tags = ( yield rest . get ( "https://api.github.com/repos/protocolbuffers/protobuf/releases" ) ) . result || [ ] ;
125137 return tags
126138 . filter ( tag => tag . tag_name . match ( / v \d + \. [ \w \. ] + / g) )
@@ -129,7 +141,7 @@ function fetchVersions(includePreReleases) {
129141 } ) ;
130142}
131143// Compute an actual version starting from the `version` configuration param.
132- function computeVersion ( version , includePreReleases ) {
144+ function computeVersion ( version , includePreReleases , repoToken ) {
133145 return __awaiter ( this , void 0 , void 0 , function * ( ) {
134146 // strip leading `v` char (will be re-added later)
135147 if ( version . startsWith ( "v" ) ) {
@@ -139,7 +151,7 @@ function computeVersion(version, includePreReleases) {
139151 if ( version . endsWith ( ".x" ) ) {
140152 version = version . slice ( 0 , version . length - 2 ) ;
141153 }
142- const allVersions = yield fetchVersions ( includePreReleases ) ;
154+ const allVersions = yield fetchVersions ( includePreReleases , repoToken ) ;
143155 const validVersions = allVersions . filter ( v => semver . valid ( v ) ) ;
144156 const possibleVersions = validVersions . filter ( v => v . startsWith ( version ) ) ;
145157 const versionMap = new Map ( ) ;
@@ -195,10 +207,5 @@ function normalizeVersion(version) {
195207 return version ;
196208}
197209function includePrerelease ( isPrerelease , includePrereleases ) {
198- if ( ! includePrereleases ) {
199- if ( isPrerelease ) {
200- return false ;
201- }
202- }
203- return true ;
210+ return includePrereleases || ! isPrerelease ;
204211}
0 commit comments