Skip to content

Commit dd1eeb5

Browse files
authored
Add pagination logic when checking for versions (#1)
* 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.
1 parent 7ad700d commit dd1eeb5

File tree

16 files changed

+40915
-20937
lines changed

16 files changed

+40915
-20937
lines changed

__tests__/main.test.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ describe("installer tests", () => {
4949
describe("Gets the latest release of protoc", () => {
5050
beforeEach(() => {
5151
nock("https://api.github.com")
52-
.get("/repos/protocolbuffers/protobuf/releases")
53-
.replyWithFile(200, path.join(dataDir, "releases.json"));
52+
.get("/repos/protocolbuffers/protobuf/releases?page=1")
53+
.replyWithFile(200, path.join(dataDir, "releases-1.json"));
54+
55+
nock("https://api.github.com")
56+
.get("/repos/protocolbuffers/protobuf/releases?page=2")
57+
.replyWithFile(200, path.join(dataDir, "releases-2.json"));
58+
59+
60+
nock("https://api.github.com")
61+
.get("/repos/protocolbuffers/protobuf/releases?page=3")
62+
.replyWithFile(200, path.join(dataDir, "releases-3.json"));
5463
});
5564

5665
afterEach(() => {
@@ -74,7 +83,7 @@ describe("installer tests", () => {
7483

7584
it("Gets latest version of protoc using 3.x and no matching version is installed", async () => {
7685
await installer.getProtoc("3.x", true, GITHUB_TOKEN);
77-
const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch());
86+
const protocDir = path.join(toolDir, "protoc", "3.12.4", os.arch());
7887

7988
expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
8089
if (IS_WINDOWS) {
@@ -90,9 +99,18 @@ describe("installer tests", () => {
9099
describe("Gets the latest release of protoc with broken latest rc tag", () => {
91100
beforeEach(() => {
92101
nock("https://api.github.com")
93-
.get("/repos/protocolbuffers/protobuf/releases")
102+
.get("/repos/protocolbuffers/protobuf/releases?page=1")
94103
.replyWithFile(200, path.join(dataDir, "releases-broken-rc-tag.json"));
95-
});
104+
105+
nock("https://api.github.com")
106+
.get("/repos/protocolbuffers/protobuf/releases?page=2")
107+
.replyWithFile(200, path.join(dataDir, "releases-2.json"));
108+
109+
110+
nock("https://api.github.com")
111+
.get("/repos/protocolbuffers/protobuf/releases?page=3")
112+
.replyWithFile(200, path.join(dataDir, "releases-3.json"));
113+
});
96114

97115
afterEach(() => {
98116
nock.cleanAll();

__tests__/testdata/releases-1.json

Lines changed: 26455 additions & 0 deletions
Large diffs are not rendered by default.

__tests__/testdata/releases-2.json

Lines changed: 14392 additions & 0 deletions
Large diffs are not rendered by default.

__tests__/testdata/releases-3.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
3+
]

__tests__/testdata/releases.json

Lines changed: 0 additions & 20907 deletions
This file was deleted.

lib/installer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@ function fetchVersions(includePreReleases, repoToken) {
133133
else {
134134
rest = new restm.RestClient("setup-protoc");
135135
}
136-
let tags = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases")).result || [];
136+
let tags = [];
137+
for (let pageNum = 1, morePages = true; morePages; pageNum++) {
138+
let nextPage = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + pageNum)).result || [];
139+
if (nextPage.length > 0) {
140+
tags = tags.concat(nextPage);
141+
}
142+
else {
143+
morePages = false;
144+
}
145+
}
137146
return tags
138147
.filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g))
139148
.filter(tag => includePrerelease(tag.prerelease, includePreReleases))

node_modules/@actions/core/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/io/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/tool-cache/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/semver/package.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/tunnel/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/typed-rest-client/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/underscore/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/uuid/package.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/installer.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,17 @@ async function fetchVersions(
149149
rest = new restm.RestClient("setup-protoc");
150150
}
151151

152-
let tags: IProtocRelease[] =
153-
(await rest.get<IProtocRelease[]>(
154-
"https://api.github.com/repos/protocolbuffers/protobuf/releases"
152+
let tags: IProtocRelease[] = [];
153+
for (let pageNum=1,morePages=true; morePages; pageNum++) {
154+
let nextPage: IProtocRelease[] = (await rest.get<IProtocRelease[]>(
155+
"https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + pageNum
155156
)).result || [];
157+
if (nextPage.length > 0) {
158+
tags = tags.concat(nextPage);
159+
} else {
160+
morePages = false;
161+
}
162+
}
156163

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

0 commit comments

Comments
 (0)