From 5275a4978319fa41f0e986ab18ec7ea628d694e7 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Mon, 26 Sep 2022 19:27:56 -0500 Subject: [PATCH 1/6] fix #25: Support ARM64 and other platforms --- __tests__/main.test.ts | 18 +++++++++++++++ src/installer.ts | 51 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b8370bea..fc0e9f39 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -14,6 +14,24 @@ process.env["RUNNER_TEMP"] = tempDir; process.env["RUNNER_TOOL_CACHE"] = toolDir; import * as installer from "../src/installer"; +describe("filename tests", () => { + const tests = [ + ["protoc-3.20.2-linux-x86_32.zip", "linux", ""], + ["protoc-3.20.2-linux-x86_64.zip", "linux", "x64"], + ["protoc-3.20.2-linux-aarch_64.zip", "linux", "arm64"], + ["protoc-3.20.2-linux-ppcle_64.zip", "linux", "ppc64"], + ["protoc-3.20.2-linux-s390_64.zip", "linux", "s390x"], + ["protoc-3.20.2-osx-aarch_64.zip", "darwin", "arm64"], + ["protoc-3.20.2-osx-x86_64.zip", "darwin", "x64"] + ]; + for (const [expected, plat, arch] of tests) { + it(`downloads ${expected} correctly`, () => { + const actual = installer.getFileName("3.20.2", plat, arch); + expect(expected).toBe(actual); + }); + } +}); + describe("installer tests", () => { beforeEach(async function() { await io.rmRF(toolDir); diff --git a/src/installer.ts b/src/installer.ts index b0515273..adeb1bea 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -91,7 +91,7 @@ export async function getProtoc( async function downloadRelease(version: string): Promise { // Download - let fileName: string = getFileName(version); + let fileName: string = getFileName(version, osPlat, osArch); let downloadUrl: string = util.format( "https://github.com/protocolbuffers/protobuf/releases/download/%s/%s", version, @@ -114,7 +114,48 @@ async function downloadRelease(version: string): Promise { return await tc.cacheDir(extPath, "protoc", version); } -function getFileName(version: string): string { +/** + * + * @param osArch - A string identifying the operating system platform for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osplatform for possible values. + * @returns Suffix for the protoc filename. + */ +function fileNameSuffix(osArch: string): string { + switch (osArch) { + case "x64": { + return "x86_64"; + } + case "arm64": { + return "aarch_64"; + } + case "s390x": { + return "s390_64"; + } + case "ppc64": { + return "ppcle_64"; + } + default: { + return "x86_32"; + } + } +} + +/** + * Returns the filename of the protobuf compiler. + * + * @param version - The version to download + * @param osPlat - The operating system platform for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osplatform for more. + * @param osArch - The operating system CPU architecture for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osplatform for more. + * @returns The filename of the protocol buffer for the given release, platform and architecture. + * + */ +export function getFileName( + version: string, + osPlat: string, + osArch: string +): string { // to compose the file name, strip the leading `v` char if (version.startsWith("v")) { version = version.slice(1, version.length); @@ -126,13 +167,13 @@ function getFileName(version: string): string { return util.format("protoc-%s-win%s.zip", version, arch); } - const arch: string = osArch == "x64" ? "x86_64" : "x86_32"; + const suffix = fileNameSuffix(osArch); if (osPlat == "darwin") { - return util.format("protoc-%s-osx-%s.zip", version, arch); + return util.format("protoc-%s-osx-%s.zip", version, suffix); } - return util.format("protoc-%s-linux-%s.zip", version, arch); + return util.format("protoc-%s-linux-%s.zip", version, suffix); } // Retrieve a list of versions scraping tags from the Github API From 129bc081f20c4cc7efa6fb6df45912e733637892 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 19 May 2023 09:49:47 -0700 Subject: [PATCH 2/6] Update __tests__/main.test.ts Co-authored-by: Alessio Perugini --- __tests__/main.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index fc0e9f39..57d1b818 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -23,6 +23,9 @@ describe("filename tests", () => { ["protoc-3.20.2-linux-s390_64.zip", "linux", "s390x"], ["protoc-3.20.2-osx-aarch_64.zip", "darwin", "arm64"], ["protoc-3.20.2-osx-x86_64.zip", "darwin", "x64"] + ["protoc-3.20.2-osx-x86_64.zip", "darwin", "x64"], + ["protoc-3.20.2-win64.zip", "win32", "x64"], + ["protoc-3.20.2-win32.zip", "win32", "x32"], ]; for (const [expected, plat, arch] of tests) { it(`downloads ${expected} correctly`, () => { From ca53c5dacae0c9dd800e378b5c4bf0bb0bfc605a Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 19 May 2023 09:50:00 -0700 Subject: [PATCH 3/6] Update src/installer.ts Co-authored-by: per1234 --- src/installer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer.ts b/src/installer.ts index adeb1bea..d563fe79 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -147,7 +147,7 @@ function fileNameSuffix(osArch: string): string { * @param osPlat - The operating system platform for which the Node.js binary was compiled. * See https://nodejs.org/api/os.html#osplatform for more. * @param osArch - The operating system CPU architecture for which the Node.js binary was compiled. - * See https://nodejs.org/api/os.html#osplatform for more. + * See https://nodejs.org/api/os.html#osarch for more. * @returns The filename of the protocol buffer for the given release, platform and architecture. * */ From 517c6cf2527e46b1d02c0bbe4dfe4eae8689a275 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 19 May 2023 09:50:09 -0700 Subject: [PATCH 4/6] Update src/installer.ts Co-authored-by: per1234 --- src/installer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index d563fe79..f506e974 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -116,8 +116,8 @@ async function downloadRelease(version: string): Promise { /** * - * @param osArch - A string identifying the operating system platform for which the Node.js binary was compiled. - * See https://nodejs.org/api/os.html#osplatform for possible values. + * @param osArch - A string identifying operating system CPU architecture for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osarch for possible values. * @returns Suffix for the protoc filename. */ function fileNameSuffix(osArch: string): string { From 1676c3e86681167805420623e39bc996ba997e84 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 19 May 2023 09:55:43 -0700 Subject: [PATCH 5/6] Run formatter --- __tests__/main.test.ts | 3 +-- src/installer.ts | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 57d1b818..982234fe 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -22,10 +22,9 @@ describe("filename tests", () => { ["protoc-3.20.2-linux-ppcle_64.zip", "linux", "ppc64"], ["protoc-3.20.2-linux-s390_64.zip", "linux", "s390x"], ["protoc-3.20.2-osx-aarch_64.zip", "darwin", "arm64"], - ["protoc-3.20.2-osx-x86_64.zip", "darwin", "x64"] ["protoc-3.20.2-osx-x86_64.zip", "darwin", "x64"], ["protoc-3.20.2-win64.zip", "win32", "x64"], - ["protoc-3.20.2-win32.zip", "win32", "x32"], + ["protoc-3.20.2-win32.zip", "win32", "x32"] ]; for (const [expected, plat, arch] of tests) { it(`downloads ${expected} correctly`, () => { diff --git a/src/installer.ts b/src/installer.ts index f506e974..36732cef 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -192,11 +192,11 @@ async function fetchVersions( let tags: IProtocRelease[] = []; for (let pageNum = 1, morePages = true; morePages; pageNum++) { - let nextPage: IProtocRelease[] = - (await rest.get( - "https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + - pageNum - )).result || []; + let p = await rest.get( + "https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + + pageNum + ); + let nextPage: IProtocRelease[] = p.result || []; if (nextPage.length > 0) { tags = tags.concat(nextPage); } else { From f92bd142217d9e181358711f79986ee63f3d928c Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Mon, 22 May 2023 13:08:39 -0700 Subject: [PATCH 6/6] npm run build --- lib/installer.js | 52 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 99e6aec9..503fd50c 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -88,7 +88,7 @@ exports.getProtoc = getProtoc; function downloadRelease(version) { return __awaiter(this, void 0, void 0, function* () { // Download - let fileName = getFileName(version); + let fileName = getFileName(version, osPlat, osArch); 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; @@ -105,7 +105,43 @@ function downloadRelease(version) { return yield tc.cacheDir(extPath, "protoc", version); }); } -function getFileName(version) { +/** + * + * @param osArch - A string identifying operating system CPU architecture for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osarch for possible values. + * @returns Suffix for the protoc filename. + */ +function fileNameSuffix(osArch) { + switch (osArch) { + case "x64": { + return "x86_64"; + } + case "arm64": { + return "aarch_64"; + } + case "s390x": { + return "s390_64"; + } + case "ppc64": { + return "ppcle_64"; + } + default: { + return "x86_32"; + } + } +} +/** + * Returns the filename of the protobuf compiler. + * + * @param version - The version to download + * @param osPlat - The operating system platform for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osplatform for more. + * @param osArch - The operating system CPU architecture for which the Node.js binary was compiled. + * See https://nodejs.org/api/os.html#osarch for more. + * @returns The filename of the protocol buffer for the given release, platform and architecture. + * + */ +function getFileName(version, osPlat, osArch) { // to compose the file name, strip the leading `v` char if (version.startsWith("v")) { version = version.slice(1, version.length); @@ -115,12 +151,13 @@ function getFileName(version) { const arch = osArch == "x64" ? "64" : "32"; return util.format("protoc-%s-win%s.zip", version, arch); } - const arch = osArch == "x64" ? "x86_64" : "x86_32"; + const suffix = fileNameSuffix(osArch); if (osPlat == "darwin") { - return util.format("protoc-%s-osx-%s.zip", version, arch); + return util.format("protoc-%s-osx-%s.zip", version, suffix); } - return util.format("protoc-%s-linux-%s.zip", version, arch); + return util.format("protoc-%s-linux-%s.zip", version, suffix); } +exports.getFileName = getFileName; // Retrieve a list of versions scraping tags from the Github API function fetchVersions(includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { @@ -135,8 +172,9 @@ function fetchVersions(includePreReleases, repoToken) { } let tags = []; for (let pageNum = 1, morePages = true; morePages; pageNum++) { - let nextPage = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + - pageNum)).result || []; + let p = yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + + pageNum); + let nextPage = p.result || []; if (nextPage.length > 0) { tags = tags.concat(nextPage); }