Skip to content

Commit

Permalink
support new protobuf versioning scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed May 29, 2023
1 parent 81936f9 commit 825fbe0
Show file tree
Hide file tree
Showing 11 changed files with 97,742 additions and 54,398 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ jobs:
- windows-latest
- macos-latest
version:
- input: 3.x
expected: "libprotoc 3.20.3"
- input: 3.17.x
expected: "libprotoc 3.17.3"
- input: 3.17.2
expected: "libprotoc 3.17.2"
- input: v22.x
expected: "libprotoc 22.5"
- input: v22.5
expected: "libprotoc 22.5"

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run action, using protoc minor version wildcard
- name: Run action, using protoc patch version wildcard
uses: ./
with:
version: '${{ matrix.version.input }}'
Expand All @@ -80,7 +78,7 @@ jobs:
continue-on-error: true
uses: ./
with:
version: 2.42.x
version: v10.x

- name: Fail the job if the action run succeeded
if: steps.setup-task.outcome == 'success'
Expand Down
83 changes: 30 additions & 53 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ 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"],
["protoc-23.2-linux-x86_32.zip", "linux", ""],
["protoc-23.2-linux-x86_64.zip", "linux", "x64"],
["protoc-23.2-linux-aarch_64.zip", "linux", "arm64"],
["protoc-23.2-linux-ppcle_64.zip", "linux", "ppc64"],
["protoc-23.2-linux-s390_64.zip", "linux", "s390x"],
["protoc-23.2-osx-aarch_64.zip", "darwin", "arm64"],
["protoc-23.2-osx-x86_64.zip", "darwin", "x64"],
["protoc-23.2-win64.zip", "win32", "x64"],
["protoc-23.2-win32.zip", "win32", "x32"]
];
it(`Downloads all expected versions correctly`, () => {
for (const [expected, plat, arch] of tests) {
const actual = installer.getFileName("3.20.2", plat, arch);
const actual = installer.getFileName("23.2", plat, arch);
expect(expected).toBe(actual);
}
});
Expand All @@ -52,8 +52,8 @@ describe("installer tests", () => {
});

it("Downloads version of protoc if no matching version is installed", async () => {
await installer.getProtoc("3.9.0", true, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", "3.9.0", os.arch());
await installer.getProtoc("v23.0", true, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", "v23.0", os.arch());

expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);

Expand All @@ -79,30 +79,28 @@ describe("installer tests", () => {
nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=3")
.replyWithFile(200, path.join(dataDir, "releases-3.json"));

nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=4")
.replyWithFile(200, path.join(dataDir, "releases-4.json"));

nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=5")
.replyWithFile(200, path.join(dataDir, "releases-5.json"));

nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=6")
.replyWithFile(200, path.join(dataDir, "releases-6.json"));
});

afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});

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, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", "3.7.1", os.arch());

expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(protocDir, "bin", "protoc.exe"))).toBe(
true
);
} else {
expect(fs.existsSync(path.join(protocDir, "bin", "protoc"))).toBe(true);
}
}, 100000);

it("Gets latest version of protoc using 3.x and no matching version is installed", async () => {
await installer.getProtoc("3.x", true, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", "3.12.4", os.arch());
it("Gets the latest v23.1 version of protoc using v23.1 and no matching version is installed", async () => {
await installer.getProtoc("v23.1", true, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", "v23.1", os.arch());

expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
Expand All @@ -113,31 +111,10 @@ describe("installer tests", () => {
expect(fs.existsSync(path.join(protocDir, "bin", "protoc"))).toBe(true);
}
}, 100000);
});

describe("Gets the latest release of protoc with broken latest rc tag", () => {
beforeEach(() => {
nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=1")
.replyWithFile(200, path.join(dataDir, "releases-broken-rc-tag.json"));

nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=2")
.replyWithFile(200, path.join(dataDir, "releases-2.json"));

nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases?page=3")
.replyWithFile(200, path.join(dataDir, "releases-3.json"));
});

afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});

it("Gets latest version of protoc using 3.x with a broken rc tag, filtering pre-releases", async () => {
await installer.getProtoc("3.x", false, "");
const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch());
it("Gets latest version of protoc using v22.x and no matching version is installed", async () => {
await installer.getProtoc("v22.x", true, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", "v22.5", os.arch());

expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
Expand Down
Loading

0 comments on commit 825fbe0

Please sign in to comment.