Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #25: Support ARM64 and other platforms #44

Merged
merged 6 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ 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"],
["protoc-3.20.2-win64.zip", "win32", "x64"],
["protoc-3.20.2-win32.zip", "win32", "x32"]
];
adamchalmers marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down
61 changes: 51 additions & 10 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function getProtoc(

async function downloadRelease(version: string): Promise<string> {
// 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,
Expand All @@ -114,7 +114,48 @@ async function downloadRelease(version: string): Promise<string> {
return await tc.cacheDir(extPath, "protoc", version);
}

function getFileName(version: string): string {
/**
*
* @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 {
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.
*
*/
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);
Expand All @@ -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
Expand All @@ -151,11 +192,11 @@ async function fetchVersions(

let tags: IProtocRelease[] = [];
for (let pageNum = 1, morePages = true; morePages; pageNum++) {
let nextPage: IProtocRelease[] =
(await rest.get<IProtocRelease[]>(
"https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
pageNum
)).result || [];
let p = await rest.get<IProtocRelease[]>(
"https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
pageNum
);
let nextPage: IProtocRelease[] = p.result || [];
if (nextPage.length > 0) {
tags = tags.concat(nextPage);
} else {
Expand Down