Skip to content

Commit 5fada6a

Browse files
authored
refactor: scope Chromium releases in fetch (#143)
1 parent b378dcd commit 5fada6a

File tree

3 files changed

+48
-121
lines changed

3 files changed

+48
-121
lines changed

src/chromium-handler.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Octokit } from '@octokit/rest';
1111

1212
type BranchItem = ReposGetBranchResponseItem | ReposListBranchesResponseItem;
1313

14-
async function rollReleaseBranch(github: Octokit, branch: BranchItem, chromiumReleases: Release[]) {
14+
async function rollReleaseBranch(github: Octokit, branch: BranchItem) {
1515
const d = debug(`roller/chromium:rollReleaseBranch('${branch.name}')`);
1616

1717
d(`Fetching DEPS for ${branch.name}`);
@@ -37,15 +37,9 @@ async function rollReleaseBranch(github: Octokit, branch: BranchItem, chromiumRe
3737
}
3838

3939
d(`Computing latest upstream version for Chromium ${chromiumMajorVersion}`);
40-
const upstreamVersions = chromiumReleases
41-
.filter(
42-
(r) =>
43-
['Win32', 'Windows', 'Linux', 'Mac'].includes(r.platform) &&
44-
r.milestone === chromiumMajorVersion,
45-
)
46-
.sort((a, b) => a.time - b.time)
47-
.map((r) => r.version);
48-
const latestUpstreamVersion = upstreamVersions[upstreamVersions.length - 1];
40+
const chromiumReleases = await getChromiumReleases({ milestone: chromiumMajorVersion });
41+
const latestUpstreamVersion = chromiumReleases[chromiumReleases.length - 1];
42+
4943
if (
5044
latestUpstreamVersion &&
5145
compareChromiumVersions(latestUpstreamVersion, chromiumVersion) > 0
@@ -67,7 +61,7 @@ async function rollReleaseBranch(github: Octokit, branch: BranchItem, chromiumRe
6761
}
6862
}
6963

70-
async function rollMainBranch(github: Octokit, chromiumReleases: Release[]) {
64+
async function rollMainBranch(github: Octokit) {
7165
const d = debug('roller/chromium:rollMainBranch()');
7266

7367
d(`Fetching ${MAIN_BRANCH} branch for electron/electron`);
@@ -102,13 +96,8 @@ async function rollMainBranch(github: Octokit, chromiumReleases: Release[]) {
10296
throw new Error(`${MAIN_BRANCH} roll failed: ${currentVersion} is not a valid version number`);
10397
}
10498

105-
const upstreamVersions = chromiumReleases
106-
.filter(
107-
(r) => ['Windows', 'Win32', 'Linux', 'Mac'].includes(r.platform) && r.channel === 'Canary',
108-
)
109-
.sort((a, b) => a.time - b.time)
110-
.map((r) => r.version);
111-
const latestUpstreamVersion = upstreamVersions[upstreamVersions.length - 1];
99+
const chromiumReleases = await getChromiumReleases({ channel: 'Canary' });
100+
const latestUpstreamVersion = chromiumReleases[chromiumReleases.length - 1];
112101

113102
if (latestUpstreamVersion && currentVersion !== latestUpstreamVersion) {
114103
d(`Updating ${MAIN_BRANCH} from ${currentVersion} to ${latestUpstreamVersion}`);
@@ -129,30 +118,25 @@ async function rollMainBranch(github: Octokit, chromiumReleases: Release[]) {
129118
export async function handleChromiumCheck(target?: string): Promise<void> {
130119
const d = debug('roller/chromium:handleChromiumCheck()');
131120

132-
d('Fetching Chromium releases');
133-
const chromiumReleases = await getChromiumReleases();
134-
135121
const github = await getOctokit();
136122

137123
let failed = false;
138124
if (target) {
139125
if (target !== 'main') {
140126
try {
141-
const { data: branch }: { data: ReposGetBranchResponseItem } = await github.repos.getBranch(
142-
{
143-
...REPOS.electron,
144-
branch: target,
145-
},
146-
);
147-
148-
await rollReleaseBranch(github, branch, chromiumReleases);
127+
const { data: branch } = await github.repos.getBranch({
128+
...REPOS.electron,
129+
branch: target,
130+
});
131+
132+
await rollReleaseBranch(github, branch);
149133
} catch (e) {
150134
d(`Failed to roll ${target}: ${e.message}`);
151135
failed = true;
152136
}
153137
} else {
154138
try {
155-
await rollMainBranch(github, chromiumReleases);
139+
await rollMainBranch(github);
156140
} catch (e) {
157141
d(`Failed to roll ${MAIN_BRANCH}: ${e.message}`);
158142
failed = true;
@@ -174,15 +158,15 @@ export async function handleChromiumCheck(target?: string): Promise<void> {
174158
// Roll all non-main release branches.
175159
for (const branch of releaseBranches) {
176160
try {
177-
await rollReleaseBranch(github, branch, chromiumReleases);
161+
await rollReleaseBranch(github, branch);
178162
} catch (e) {
179163
failed = true;
180164
continue;
181165
}
182166
}
183167

184168
try {
185-
await rollMainBranch(github, chromiumReleases);
169+
await rollMainBranch(github);
186170
} catch (e) {
187171
failed = true;
188172
}

src/utils/get-chromium-tags.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,35 @@ function getJSON(url: string): Promise<any> {
2222
return get(url).then((s) => JSON.parse(s.slice(s.indexOf('{'))));
2323
}
2424

25+
type ReleaseType = 'Extended' | 'Stable' | 'Beta' | 'Dev' | 'Canary';
26+
27+
export type ReleaseParams = {
28+
channel?: ReleaseType;
29+
milestone?: number;
30+
};
31+
2532
export type Release = {
26-
platform: 'Android' | 'Linux' | 'Mac' | 'Webview' | 'Win32' | 'Windows' | 'iOS';
27-
channel: 'Extended' | 'Stable' | 'Beta' | 'Dev' | 'Canary';
33+
platform: 'Linux' | 'Mac' | 'Win32' | 'Windows';
34+
channel: ReleaseType;
2835
milestone: number;
2936
time: number;
3037
version: string;
3138
};
3239

33-
export function getChromiumReleases(): Promise<Release[]> {
34-
return get('https://chromiumdash.appspot.com/fetch_releases').then((s) => JSON.parse(s));
40+
export async function getChromiumReleases({
41+
channel,
42+
milestone,
43+
}: ReleaseParams): Promise<string[]> {
44+
const url = new URL('https://chromiumdash.appspot.com/fetch_releases');
45+
46+
url.searchParams.set('platform', 'Win32,Windows,Linux,Mac');
47+
url.searchParams.set('num', '10');
48+
49+
if (channel) url.searchParams.set('channel', channel);
50+
if (milestone) url.searchParams.set('milestone', milestone.toString());
51+
52+
const releases = await get(url.toString()).then((s) => JSON.parse(s));
53+
return releases.sort((a, b) => a.time - b.time).map((r) => r.version);
3554
}
3655

3756
export interface ChromiumCommit {

tests/handlers.spec.ts

Lines changed: 9 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,11 @@ describe('handleChromiumCheck()', () => {
6060
sha: '1234',
6161
},
6262
});
63-
vi.mocked(getChromiumReleases).mockResolvedValue([
64-
{
65-
time: 1577869261000,
66-
version: '1.1.0.0',
67-
milestone: 1,
68-
channel: 'Stable',
69-
platform: 'Windows',
70-
},
71-
{
72-
time: 1577869261003,
73-
version: '2.1.0.0',
74-
milestone: 2,
75-
channel: 'Beta',
76-
platform: 'Windows',
77-
},
78-
{
79-
time: 1577869261002,
80-
version: '1.2.0.0',
81-
milestone: 1,
82-
channel: 'Stable',
83-
platform: 'Mac',
84-
},
85-
]);
8663
});
8764

8865
it('properly fetches supported versions of Electron to roll against', async () => {
66+
vi.mocked(getChromiumReleases).mockResolvedValue(['1.1.0.0', '1.2.0.0', '2.1.0.0']);
67+
8968
mockOctokit.paginate.mockReturnValue([
9069
{
9170
name: '10-x-y',
@@ -155,6 +134,8 @@ describe('handleChromiumCheck()', () => {
155134
});
156135

157136
it('rolls with latest versions from release tags', async () => {
137+
vi.mocked(getChromiumReleases).mockResolvedValue(['1.1.0.0', '1.2.0.0']);
138+
158139
await handleChromiumCheck();
159140

160141
expect(roll).toHaveBeenCalledWith(
@@ -175,6 +156,8 @@ describe('handleChromiumCheck()', () => {
175156
});
176157

177158
it('takes no action if no new minor/build/patch available', async () => {
159+
vi.mocked(getChromiumReleases).mockResolvedValue([]);
160+
178161
mockOctokit.repos.getContent.mockReturnValue({
179162
data: {
180163
content: Buffer.from(`${ROLL_TARGETS.chromium.depsKey}':\n '1.5.0.0',`),
@@ -226,29 +209,7 @@ describe('handleChromiumCheck()', () => {
226209
});
227210

228211
it('updates to main', async () => {
229-
vi.mocked(getChromiumReleases).mockResolvedValue([
230-
{
231-
time: 1577869261000,
232-
version: '1.1.0.0',
233-
milestone: 1,
234-
channel: 'Stable',
235-
platform: 'Windows',
236-
},
237-
{
238-
time: 1577869261003,
239-
version: '2.1.0.0',
240-
milestone: 2,
241-
channel: 'Canary',
242-
platform: 'Windows',
243-
},
244-
{
245-
time: 1577869261002,
246-
version: '1.2.0.0',
247-
milestone: 1,
248-
channel: 'Stable',
249-
platform: 'Mac',
250-
},
251-
]);
212+
vi.mocked(getChromiumReleases).mockResolvedValue(['1.1.0.0', '1.2.0.0', '2.1.0.0']);
252213

253214
await handleChromiumCheck();
254215

@@ -261,22 +222,7 @@ describe('handleChromiumCheck()', () => {
261222
});
262223

263224
it('takes no action if main is already in DEPS', async () => {
264-
vi.mocked(getChromiumReleases).mockResolvedValue([
265-
{
266-
time: 1577869261000,
267-
version: '1.1.0.0',
268-
milestone: 1,
269-
channel: 'Canary',
270-
platform: 'Windows',
271-
},
272-
{
273-
time: 1577869261001,
274-
version: '1.1.0.0',
275-
milestone: 1,
276-
channel: 'Canary',
277-
platform: 'Mac',
278-
},
279-
]);
225+
vi.mocked(getChromiumReleases).mockResolvedValue(['1.1.0.0', '1.1.0.0']);
280226

281227
await handleChromiumCheck();
282228

@@ -300,29 +246,7 @@ describe('handleChromiumCheck()', () => {
300246
sha: '1234',
301247
},
302248
});
303-
vi.mocked(getChromiumReleases).mockResolvedValue([
304-
{
305-
time: 1577869261000,
306-
version: '1.1.0.0',
307-
milestone: 1,
308-
channel: 'Stable',
309-
platform: 'Windows',
310-
},
311-
{
312-
time: 1577869261003,
313-
version: '2.1.0.0',
314-
milestone: 2,
315-
channel: 'Beta',
316-
platform: 'Windows',
317-
},
318-
{
319-
time: 1577869261002,
320-
version: '1.2.0.0',
321-
milestone: 1,
322-
channel: 'Stable',
323-
platform: 'Mac',
324-
},
325-
]);
249+
vi.mocked(getChromiumReleases).mockResolvedValue(['1.1.0.0', '1.2.0.0', '2.1.0.0']);
326250

327251
vi.mocked(roll).mockImplementationOnce(() => {
328252
throw new Error('');

0 commit comments

Comments
 (0)