diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 255097ef..385da08c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: push: branches: - master - pull_request: + pull_request: jobs: test: @@ -21,12 +21,14 @@ jobs: - name: Set Node.js 10.x uses: actions/setup-node@master with: - version: 10.x + node-version: 10.x - name: npm install run: npm install - name: npm lint + # check style only once + if: matrix.operating-system == 'ubuntu-latest' run: npm run format-check - name: npm test diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 55bb28f2..47bf198e 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -31,7 +31,7 @@ describe("installer tests", () => { }); it("Downloads version of protoc if no matching version is installed", async () => { - await installer.getProtoc("3.9.0", true); + await installer.getProtoc("3.9.0", true, ""); const protocDir = path.join(toolDir, "protoc", "3.9.0", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); @@ -58,7 +58,7 @@ describe("installer tests", () => { }); it("Gets the latest 3.7.x version of protoc using 3.7 and no matching version is installed", async () => { - await installer.getProtoc("3.7", true); + await installer.getProtoc("3.7", true, ""); const protocDir = path.join(toolDir, "protoc", "3.7.1", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); @@ -72,7 +72,7 @@ describe("installer tests", () => { }, 100000); it("Gets latest version of protoc using 3.x and no matching version is installed", async () => { - await installer.getProtoc("3.x", true); + await installer.getProtoc("3.x", true, ""); const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); @@ -99,7 +99,7 @@ describe("installer tests", () => { }); it("Gets latest version of protoc using 3.x with a broken rc tag, filtering pre-releases", async () => { - await installer.getProtoc("3.x", false); + await installer.getProtoc("3.x", false, ""); const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); diff --git a/lib/installer.js b/lib/installer.js index 412c1003..8894bcc2 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -44,20 +44,21 @@ const exc = __importStar(require("@actions/exec")); const io = __importStar(require("@actions/io")); let osPlat = os.platform(); let osArch = os.arch(); -function getProtoc(version, includePreReleases) { +function getProtoc(version, includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { // resolve the version number - const targetVersion = yield computeVersion(version, includePreReleases); + const targetVersion = yield computeVersion(version, includePreReleases, repoToken); if (targetVersion) { version = targetVersion; } + process.stdout.write("Getting protoc version: " + version + os.EOL); // look if the binary is cached let toolPath; toolPath = tc.find("protoc", version); // if not: download, extract and cache if (!toolPath) { toolPath = yield downloadRelease(version); - core.debug("Protoc cached under " + toolPath); + process.stdout.write("Protoc cached under " + toolPath + os.EOL); } // add the bin folder to the PATH toolPath = path.join(toolPath, "bin"); @@ -89,6 +90,7 @@ function downloadRelease(version) { // Download let fileName = getFileName(version); let downloadUrl = util.format("https://github.com/protocolbuffers/protobuf/releases/download/%s/%s", version, fileName); + process.stdout.write("Downloading archive: " + downloadUrl + os.EOL); let downloadPath = null; try { downloadPath = yield tc.downloadTool(downloadUrl); @@ -114,13 +116,23 @@ function getFileName(version) { return util.format("protoc-%s-win%s.zip", version, arch); } const arch = osArch == "x64" ? "x86_64" : "x86_32"; - const filename = util.format("protoc-%s-linux-%s.zip", version, arch); - return filename; + if (osPlat == "darwin") { + return util.format("protoc-%s-osx-%s.zip", version, arch); + } + return util.format("protoc-%s-linux-%s.zip", version, arch); } // Retrieve a list of versions scraping tags from the Github API -function fetchVersions(includePreReleases) { +function fetchVersions(includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { - let rest = new restm.RestClient("setup-protoc"); + let rest; + if (repoToken != "") { + rest = new restm.RestClient("setup-protoc", "", [], { + headers: { Authorization: "Bearer " + repoToken } + }); + } + else { + rest = new restm.RestClient("setup-protoc"); + } let tags = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases")).result || []; return tags .filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g)) @@ -129,7 +141,7 @@ function fetchVersions(includePreReleases) { }); } // Compute an actual version starting from the `version` configuration param. -function computeVersion(version, includePreReleases) { +function computeVersion(version, includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { // strip leading `v` char (will be re-added later) if (version.startsWith("v")) { @@ -139,7 +151,7 @@ function computeVersion(version, includePreReleases) { if (version.endsWith(".x")) { version = version.slice(0, version.length - 2); } - const allVersions = yield fetchVersions(includePreReleases); + const allVersions = yield fetchVersions(includePreReleases, repoToken); const validVersions = allVersions.filter(v => semver.valid(v)); const possibleVersions = validVersions.filter(v => v.startsWith(version)); const versionMap = new Map(); @@ -195,10 +207,5 @@ function normalizeVersion(version) { return version; } function includePrerelease(isPrerelease, includePrereleases) { - if (!includePrereleases) { - if (isPrerelease) { - return false; - } - } - return true; + return includePrereleases || !isPrerelease; } diff --git a/lib/main.js b/lib/main.js index 5b7c5472..ef1dbd5c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -22,7 +22,8 @@ function run() { try { let version = core.getInput("version"); let includePreReleases = convertToBoolean(core.getInput("include-pre-releases")); - yield installer.getProtoc(version, includePreReleases); + let repoToken = core.getInput("repo-token"); + yield installer.getProtoc(version, includePreReleases, repoToken); } catch (error) { core.setFailed(error.message); diff --git a/package-lock.json b/package-lock.json index c0c123ea..2fc0a746 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1135,9 +1135,9 @@ } }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true, "optional": true }, @@ -2369,9 +2369,9 @@ "dev": true }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.5.tgz", + "integrity": "sha512-0Ce31oWVB7YidkaTq33ZxEbN+UDxMMgThvCe8ptgQViymL5DPis9uLdTA13MiRPhgvqyxIegugrP97iK3JeBHg==", "dev": true, "requires": { "neo-async": "^2.6.0", @@ -5089,13 +5089,13 @@ "dev": true }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.3.tgz", + "integrity": "sha512-KfQUgOqTkLp2aZxrMbCuKCDGW9slFYu2A23A36Gs7sGzTLcRBDORdOi5E21KWHFIfkY8kzgi/Pr1cXCh0yIp5g==", "dev": true, "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "~2.20.3", "source-map": "~0.6.1" } }, diff --git a/src/installer.ts b/src/installer.ts index 26866a0a..0487d6d3 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -35,12 +35,21 @@ interface IProtocRelease { prerelease: boolean; } -export async function getProtoc(version: string, includePreReleases: boolean) { +export async function getProtoc( + version: string, + includePreReleases: boolean, + repoToken: string +) { // resolve the version number - const targetVersion = await computeVersion(version, includePreReleases); + const targetVersion = await computeVersion( + version, + includePreReleases, + repoToken + ); if (targetVersion) { version = targetVersion; } + process.stdout.write("Getting protoc version: " + version + os.EOL); // look if the binary is cached let toolPath: string; @@ -49,7 +58,7 @@ export async function getProtoc(version: string, includePreReleases: boolean) { // if not: download, extract and cache if (!toolPath) { toolPath = await downloadRelease(version); - core.debug("Protoc cached under " + toolPath); + process.stdout.write("Protoc cached under " + toolPath + os.EOL); } // add the bin folder to the PATH @@ -88,6 +97,8 @@ async function downloadRelease(version: string): Promise { version, fileName ); + process.stdout.write("Downloading archive: " + downloadUrl + os.EOL); + let downloadPath: string | null = null; try { downloadPath = await tc.downloadTool(downloadUrl); @@ -125,8 +136,19 @@ function getFileName(version: string): string { } // Retrieve a list of versions scraping tags from the Github API -async function fetchVersions(includePreReleases: boolean): Promise { - let rest: restm.RestClient = new restm.RestClient("setup-protoc"); +async function fetchVersions( + includePreReleases: boolean, + repoToken: string +): Promise { + let rest: restm.RestClient; + if (repoToken != "") { + rest = new restm.RestClient("setup-protoc", "", [], { + headers: { Authorization: "Bearer " + repoToken } + }); + } else { + rest = new restm.RestClient("setup-protoc"); + } + let tags: IProtocRelease[] = (await rest.get( "https://api.github.com/repos/protocolbuffers/protobuf/releases" @@ -141,7 +163,8 @@ async function fetchVersions(includePreReleases: boolean): Promise { // Compute an actual version starting from the `version` configuration param. async function computeVersion( version: string, - includePreReleases: boolean + includePreReleases: boolean, + repoToken: string ): Promise { // strip leading `v` char (will be re-added later) if (version.startsWith("v")) { @@ -153,7 +176,7 @@ async function computeVersion( version = version.slice(0, version.length - 2); } - const allVersions = await fetchVersions(includePreReleases); + const allVersions = await fetchVersions(includePreReleases, repoToken); const validVersions = allVersions.filter(v => semver.valid(v)); const possibleVersions = validVersions.filter(v => v.startsWith(version)); diff --git a/src/main.ts b/src/main.ts index 8b9d5903..b70341a4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,8 @@ async function run() { let includePreReleases = convertToBoolean( core.getInput("include-pre-releases") ); - await installer.getProtoc(version, includePreReleases); + let repoToken = core.getInput("repo-token"); + await installer.getProtoc(version, includePreReleases, repoToken); } catch (error) { core.setFailed(error.message); }