1
1
// Load tempDirectory before it gets wiped by tool-cache
2
- let tempDirectory = process . env [ " RUNNER_TEMP" ] || "" ;
2
+ let tempDirectory = process . env . RUNNER_TEMP || "" ;
3
3
4
4
import * as os from "os" ;
5
5
import * as path from "path" ;
@@ -11,7 +11,7 @@ if (!tempDirectory) {
11
11
let baseLocation ;
12
12
if ( process . platform === "win32" ) {
13
13
// On windows use the USERPROFILE env variable
14
- baseLocation = process . env [ " USERPROFILE" ] || "C:\\" ;
14
+ baseLocation = process . env . USERPROFILE || "C:\\" ;
15
15
} else {
16
16
if ( process . platform === "darwin" ) {
17
17
baseLocation = "/Users" ;
@@ -27,8 +27,8 @@ import * as tc from "@actions/tool-cache";
27
27
import * as exc from "@actions/exec" ;
28
28
import * as io from "@actions/io" ;
29
29
30
- let osPlat : string = os . platform ( ) ;
31
- let osArch : string = os . arch ( ) ;
30
+ const osPlat : string = os . platform ( ) ;
31
+ const osArch : string = os . arch ( ) ;
32
32
33
33
interface IProtocRelease {
34
34
tag_name : string ;
@@ -73,7 +73,7 @@ export async function getProtoc(
73
73
// Go is installed, add $GOPATH/bin to the $PATH because setup-go
74
74
// doesn't do it for us.
75
75
let stdOut = "" ;
76
- let options = {
76
+ const options = {
77
77
listeners : {
78
78
stdout : ( data : Buffer ) => {
79
79
stdOut += data . toString ( ) ;
@@ -91,8 +91,8 @@ export async function getProtoc(
91
91
92
92
async function downloadRelease ( version : string ) : Promise < string > {
93
93
// Download
94
- let fileName : string = getFileName ( version , osPlat , osArch ) ;
95
- let downloadUrl : string = util . format (
94
+ const fileName : string = getFileName ( version , osPlat , osArch ) ;
95
+ const downloadUrl : string = util . format (
96
96
"https://github.com/protocolbuffers/protobuf/releases/download/%s/%s" ,
97
97
version ,
98
98
fileName
@@ -105,26 +105,28 @@ async function downloadRelease(version: string): Promise<string> {
105
105
} catch ( err ) {
106
106
if ( err instanceof tc . HTTPError ) {
107
107
core . debug ( err . message ) ;
108
- throw `Failed to download version ${ version } : ${ err . name } , ${ err . message } - ${ err . httpStatusCode } ` ;
108
+ throw new Error (
109
+ `Failed to download version ${ version } : ${ err . name } , ${ err . message } - ${ err . httpStatusCode } `
110
+ ) ;
109
111
}
110
- throw `Failed to download version ${ version } : ${ err } ` ;
112
+ throw new Error ( `Failed to download version ${ version } : ${ err } ` ) ;
111
113
}
112
114
113
115
// Extract
114
- let extPath : string = await tc . extractZip ( downloadPath ) ;
116
+ const extPath : string = await tc . extractZip ( downloadPath ) ;
115
117
116
118
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
117
- return await tc . cacheDir ( extPath , "protoc" , version ) ;
119
+ return tc . cacheDir ( extPath , "protoc" , version ) ;
118
120
}
119
121
120
122
/**
121
123
*
122
- * @param osArch - A string identifying operating system CPU architecture for which the Node.js binary was compiled.
124
+ * @param osArc - A string identifying operating system CPU architecture for which the Node.js binary was compiled.
123
125
* See https://nodejs.org/api/os.html#osarch for possible values.
124
126
* @returns Suffix for the protoc filename.
125
127
*/
126
- function fileNameSuffix ( osArch : string ) : string {
127
- switch ( osArch ) {
128
+ function fileNameSuffix ( osArc : string ) : string {
129
+ switch ( osArc ) {
128
130
case "x64" : {
129
131
return "x86_64" ;
130
132
}
@@ -147,32 +149,32 @@ function fileNameSuffix(osArch: string): string {
147
149
* Returns the filename of the protobuf compiler.
148
150
*
149
151
* @param version - The version to download
150
- * @param osPlat - The operating system platform for which the Node.js binary was compiled.
152
+ * @param osPlatf - The operating system platform for which the Node.js binary was compiled.
151
153
* See https://nodejs.org/api/os.html#osplatform for more.
152
- * @param osArch - The operating system CPU architecture for which the Node.js binary was compiled.
154
+ * @param osArc - The operating system CPU architecture for which the Node.js binary was compiled.
153
155
* See https://nodejs.org/api/os.html#osarch for more.
154
156
* @returns The filename of the protocol buffer for the given release, platform and architecture.
155
157
*
156
158
*/
157
159
export function getFileName (
158
160
version : string ,
159
- osPlat : string ,
160
- osArch : string
161
+ osPlatf : string ,
162
+ osArc : string
161
163
) : string {
162
164
// to compose the file name, strip the leading `v` char
163
165
if ( version . startsWith ( "v" ) ) {
164
166
version = version . slice ( 1 , version . length ) ;
165
167
}
166
168
167
169
// The name of the Windows package has a different naming pattern
168
- if ( osPlat == "win32" ) {
169
- const arch : string = osArch == "x64" ? "64" : "32" ;
170
+ if ( osPlatf == "win32" ) {
171
+ const arch : string = osArc == "x64" ? "64" : "32" ;
170
172
return util . format ( "protoc-%s-win%s.zip" , version , arch ) ;
171
173
}
172
174
173
- const suffix = fileNameSuffix ( osArch ) ;
175
+ const suffix = fileNameSuffix ( osArc ) ;
174
176
175
- if ( osPlat == "darwin" ) {
177
+ if ( osPlatf == "darwin" ) {
176
178
return util . format ( "protoc-%s-osx-%s.zip" , version , suffix ) ;
177
179
}
178
180
@@ -195,11 +197,11 @@ async function fetchVersions(
195
197
196
198
let tags : IProtocRelease [ ] = [ ] ;
197
199
for ( let pageNum = 1 , morePages = true ; morePages ; pageNum ++ ) {
198
- let p = await rest . get < IProtocRelease [ ] > (
200
+ const p = await rest . get < IProtocRelease [ ] > (
199
201
"https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
200
202
pageNum
201
203
) ;
202
- let nextPage : IProtocRelease [ ] = p . result || [ ] ;
204
+ const nextPage : IProtocRelease [ ] = p . result || [ ] ;
203
205
if ( nextPage . length > 0 ) {
204
206
tags = tags . concat ( nextPage ) ;
205
207
} else {
@@ -208,7 +210,7 @@ async function fetchVersions(
208
210
}
209
211
210
212
return tags
211
- . filter ( tag => tag . tag_name . match ( / v \d + \. [ \w \ .] + / g) )
213
+ . filter ( tag => tag . tag_name . match ( / v \d + \. [ \w . ] + / g) )
212
214
. filter ( tag => includePrerelease ( tag . prerelease , includePreReleases ) )
213
215
. map ( tag => tag . tag_name . replace ( "v" , "" ) ) ;
214
216
}
0 commit comments