Skip to content

Commit

Permalink
Add pagination logic when checking for versions (#1)
Browse files Browse the repository at this point in the history
* Add pagination logic when checking for versions

This prevents older versions from no longer being considered
installable if they are on page2+ of the github releases API.
  • Loading branch information
Sodman authored Jul 29, 2020
1 parent 7ad700d commit dd1eeb5
Show file tree
Hide file tree
Showing 16 changed files with 40,915 additions and 20,937 deletions.
28 changes: 23 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ describe("installer tests", () => {
describe("Gets the latest release of protoc", () => {
beforeEach(() => {
nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases")
.replyWithFile(200, path.join(dataDir, "releases.json"));
.get("/repos/protocolbuffers/protobuf/releases?page=1")
.replyWithFile(200, path.join(dataDir, "releases-1.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(() => {
Expand All @@ -74,7 +83,7 @@ describe("installer tests", () => {

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

expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
Expand All @@ -90,9 +99,18 @@ describe("installer tests", () => {
describe("Gets the latest release of protoc with broken latest rc tag", () => {
beforeEach(() => {
nock("https://api.github.com")
.get("/repos/protocolbuffers/protobuf/releases")
.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();
Expand Down
26,455 changes: 26,455 additions & 0 deletions __tests__/testdata/releases-1.json

Large diffs are not rendered by default.

14,392 changes: 14,392 additions & 0 deletions __tests__/testdata/releases-2.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions __tests__/testdata/releases-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[

]
20,907 changes: 0 additions & 20,907 deletions __tests__/testdata/releases.json

This file was deleted.

11 changes: 10 additions & 1 deletion lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ function fetchVersions(includePreReleases, repoToken) {
else {
rest = new restm.RestClient("setup-protoc");
}
let tags = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases")).result || [];
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 || [];
if (nextPage.length > 0) {
tags = tags.concat(nextPage);
}
else {
morePages = false;
}
}
return tags
.filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g))
.filter(tag => includePrerelease(tag.prerelease, includePreReleases))
Expand Down
4 changes: 2 additions & 2 deletions node_modules/@actions/core/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/@actions/exec/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/@actions/io/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/@actions/tool-cache/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions node_modules/semver/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/tunnel/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/typed-rest-client/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/underscore/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions node_modules/uuid/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,17 @@ async function fetchVersions(
rest = new restm.RestClient("setup-protoc");
}

let tags: IProtocRelease[] =
(await rest.get<IProtocRelease[]>(
"https://api.github.com/repos/protocolbuffers/protobuf/releases"
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 || [];
if (nextPage.length > 0) {
tags = tags.concat(nextPage);
} else {
morePages = false;
}
}

return tags
.filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g))
Expand Down

0 comments on commit dd1eeb5

Please sign in to comment.