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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support only the new protobuf versioning scheme #78

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.3
expected: "libprotoc 22.3"

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
119 changes: 46 additions & 73 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import io = require("@actions/io");
import path = require("path");
import os = require("os");
import fs = require("fs");
import nock = require("nock");
import * as io from "@actions/io";
import * as path from "path";
import * as os from "os";
import * as fs from "fs";
import nock from "nock";

const toolDir = path.join(__dirname, "runner", "tools");
const tempDir = path.join(__dirname, "runner", "temp");
Expand All @@ -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,74 +79,47 @@ describe("installer tests", () => {
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 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());

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);
});

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"));
.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=2")
.replyWithFile(200, path.join(dataDir, "releases-2.json"));
.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=3")
.replyWithFile(200, path.join(dataDir, "releases-3.json"));
.get("/repos/protocolbuffers/protobuf/releases?page=6")
.replyWithFile(200, path.join(dataDir, "releases-6.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());

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);
const tests = [
["v23.1", "v23.1"],
["v22.x", "v22.5"],
["v23.0-rc2", "v23.0-rc2"],
];
tests.forEach(function (testCase) {
const [input, expected] = testCase;
it(`Gets latest version of protoc using ${input} and no matching version is installed`, async () => {
await installer.getProtoc(input, true, GITHUB_TOKEN);
const protocDir = path.join(toolDir, "protoc", expected, 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);
});
});
});