Skip to content

Commit e8cdb9d

Browse files
authored
feat: update macOS asset matching (#169)
* fix: support latest electron builder default macOS release names Signed-off-by: Adam Setch <[email protected]> * fix: support latest electron builder default macOS release names Signed-off-by: Adam Setch <[email protected]> * fix: update regex to match end of line Signed-off-by: Adam Setch <[email protected]> * fix: update regex to match end of line Signed-off-by: Adam Setch <[email protected]> * fix: support latest electron builder default macOS release names Signed-off-by: Adam Setch <[email protected]> * fix: support latest electron builder default macOS release names Signed-off-by: Adam Setch <[email protected]> * feat: add log statement Signed-off-by: Adam Setch <[email protected]> * feat: change where logic guard is for latest universal substitution Signed-off-by: Adam Setch <[email protected]> * feat: change where logic guard is for latest universal substitution Signed-off-by: Adam Setch <[email protected]> * feat: change where logic guard is for latest universal substitution Signed-off-by: Adam Setch <[email protected]> * test: add unit tests for universal upgrade Signed-off-by: Adam Setch <[email protected]> * test: add unit tests for universal upgrade Signed-off-by: Adam Setch <[email protected]> * incorporate PR feedback on asset matching Signed-off-by: Adam Setch <[email protected]> * incorporate PR feedback on asset matching Signed-off-by: Adam Setch <[email protected]> * incorporate PR feedback on asset matching Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent 356086d commit e8cdb9d

File tree

5 files changed

+161
-37
lines changed

5 files changed

+161
-37
lines changed

src/asset-platform.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const { PLATFORM_ARCH } = require("./constants");
22

33
const assetPlatform = (fileName) => {
4-
if (/.*(mac|darwin|osx).*(-arm).*\.zip/i.test(fileName)) {
5-
return PLATFORM_ARCH.DARWIN_ARM64;
6-
}
4+
if (/.*-(mac|darwin|osx).*\.zip$/i.test(fileName)) {
5+
if (/-arm64/.test(fileName)) return PLATFORM_ARCH.DARWIN_ARM64;
6+
if (/-universal/.test(fileName)) return PLATFORM_ARCH.DARWIN_UNIVERSAL;
77

8-
if (/.*(mac|darwin|osx).*\.zip/i.test(fileName) && !/arm64/.test(fileName)) {
98
return PLATFORM_ARCH.DARWIN_X64;
109
}
1110

src/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const PLATFORM = {
66
const PLATFORM_ARCH = {
77
DARWIN_X64: "darwin-x64",
88
DARWIN_ARM64: "darwin-arm64",
9+
DARWIN_UNIVERSAL: "darwin-universal",
910
WIN_X64: "win32-x64",
1011
WIN_IA32: "win32-ia32",
1112
WIN_ARM64: "win32-arm64",

src/updates.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,33 @@ class Updates {
9595
}
9696

9797
async handleUpdate(res, account, repository, platform, version) {
98-
const latest = await this.cachedGetLatest(
98+
let latest = await this.cachedGetLatest(
9999
account,
100100
repository,
101101
platform,
102102
version
103103
);
104104

105+
if (platform.includes(PLATFORM.DARWIN)) {
106+
const latestUniversal = await this.cachedGetLatest(
107+
account,
108+
repository,
109+
PLATFORM_ARCH.DARWIN_UNIVERSAL,
110+
version
111+
);
112+
113+
if (
114+
latestUniversal &&
115+
semver.gt(latestUniversal.version, latest.version)
116+
) {
117+
log.info("Falling back to universal build for darwin");
118+
latest = latestUniversal;
119+
}
120+
}
121+
105122
if (!latest) {
106123
const message = platform.includes(PLATFORM.DARWIN)
107-
? "No updates found (needs asset matching *(mac|darwin|osx).*(-arm).*.zip in public repository)"
124+
? "No updates found (needs asset matching .*-(mac|darwin|osx).*.zip in public repository)"
108125
: "No updates found (needs asset containing win32-{x64,ia32,arm64} or .exe in public repository)";
109126
notFound(res, message);
110127
} else if (semver.lte(latest.version, version)) {

test/asset-platform.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ test("assetPlatform() matches the right platform", (t) => {
3232
name: "Electron.Fiddle-darwin-x64-0.27.3.zip",
3333
platform: PLATFORM_ARCH.DARWIN_X64,
3434
},
35+
{
36+
name: "Electron-Builder-1.2.3-mac.zip",
37+
platform: PLATFORM_ARCH.DARWIN_X64,
38+
},
39+
{
40+
name: "Electron-Builder-1.2.3-universal-mac.zip",
41+
platform: PLATFORM_ARCH.DARWIN_UNIVERSAL,
42+
},
43+
{
44+
name: "Electron-Builder-1.2.3-arm64-mac.zip",
45+
platform: PLATFORM_ARCH.DARWIN_ARM64,
46+
},
47+
{
48+
name: "Electron.Builder-1.2.3-mac.zip.blockmap",
49+
platform: false,
50+
},
51+
{
52+
name: "mac.zip",
53+
platform: false,
54+
},
55+
{
56+
name: "darwin.zip",
57+
platform: false,
58+
},
59+
{
60+
name: "osx.zip",
61+
platform: false,
62+
},
3563
];
3664

3765
for (const release of releases) {

test/update.test.js

+110-31
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ nock("https://api.github.com")
1818
body: "notes",
1919
assets: [
2020
{
21-
name: "mac.zip",
22-
browser_download_url: "mac.zip",
21+
name: "app-mac.zip",
22+
browser_download_url: "app-mac.zip",
2323
},
2424
{
25-
name: "mac-arm64.zip",
26-
browser_download_url: "mac-arm64.zip",
25+
name: "app-mac-arm64.zip",
26+
browser_download_url: "app-mac-arm64.zip",
27+
},
28+
{
29+
name: "app-universal-mac.zip",
30+
browser_download_url: "app-universal-mac.zip",
2731
},
2832
{
2933
name: "electron-fiddle-1.0.0-win32-x64-setup.exe",
@@ -48,12 +52,12 @@ nock("https://api.github.com")
4852
body: "notes",
4953
assets: [
5054
{
51-
name: "mac.zip",
52-
browser_download_url: "mac.zip",
55+
name: "app-mac.zip",
56+
browser_download_url: "app-mac.zip",
5357
},
5458
{
55-
name: "mac-arm64.zip",
56-
browser_download_url: "mac-arm64.zip",
59+
name: "app-mac-arm64.zip",
60+
browser_download_url: "app-mac-arm64.zip",
5761
},
5862
],
5963
},
@@ -70,12 +74,49 @@ nock("https://api.github.com")
7074
body: "notes",
7175
assets: [
7276
{
73-
name: "darwin.zip",
74-
browser_download_url: "darwin.zip",
77+
name: "app-darwin.zip",
78+
browser_download_url: "app-darwin.zip",
79+
},
80+
{
81+
name: "app-darwin-arm64.zip",
82+
browser_download_url: "app-darwin-arm64.zip",
7583
},
7684
{
77-
name: "darwin-arm64.zip",
78-
browser_download_url: "darwin-arm64.zip",
85+
name: "app-universal-mac.zip",
86+
browser_download_url: "app-universal-mac.zip",
87+
},
88+
],
89+
},
90+
])
91+
.get("/repos/owner/repo-universal/releases?per_page=100")
92+
.reply(200, [
93+
{
94+
name: "name",
95+
tag_name: "v2.0.0",
96+
body: "notes",
97+
assets: [
98+
{
99+
name: "app-universal-mac.zip",
100+
browser_download_url: "app-universal-mac.zip",
101+
},
102+
{
103+
name: "app-arm64-mac.zip",
104+
browser_download_url: "app-arm64-mac.zip",
105+
},
106+
],
107+
},
108+
{
109+
name: "name",
110+
tag_name: "v1.0.0",
111+
body: "notes",
112+
assets: [
113+
{
114+
name: "app-mac.zip",
115+
browser_download_url: "app-mac.zip",
116+
},
117+
{
118+
name: "app-arm64-mac.zip",
119+
browser_download_url: "app-arm64-mac.zip",
79120
},
80121
],
81122
},
@@ -154,12 +195,12 @@ nock("https://api.github.com")
154195
body: "notes",
155196
assets: [
156197
{
157-
name: "mac.zip",
158-
browser_download_url: "mac.zip",
198+
name: "app-mac.zip",
199+
browser_download_url: "app-mac.zip",
159200
},
160201
{
161-
name: "mac-arm64.zip",
162-
browser_download_url: "mac-arm64.zip",
202+
name: "app-mac-arm64.zip",
203+
browser_download_url: "app-mac-arm64.zip",
163204
},
164205
{
165206
name: "electron-fiddle-0.36.0-win32-x64-setup.exe",
@@ -184,12 +225,12 @@ nock("https://api.github.com")
184225
body: "notes",
185226
assets: [
186227
{
187-
name: "mac.zip",
188-
browser_download_url: "mac.zip",
228+
name: "app-mac.zip",
229+
browser_download_url: "app-mac.zip",
189230
},
190231
{
191-
name: "mac-arm64.zip",
192-
browser_download_url: "mac-arm64.zip",
232+
name: "app-mac-arm64.zip",
233+
browser_download_url: "app-mac-arm64.zip",
193234
},
194235
{
195236
name: "electron-fiddle-1.0.0-win32-x64-setup.exe",
@@ -243,7 +284,7 @@ test("Updates", async (t) => {
243284
const body = await res.json();
244285
t.same(body, {
245286
name: "name",
246-
url: "mac.zip",
287+
url: "app-mac.zip",
247288
notes: "notes",
248289
});
249290
}
@@ -309,32 +350,44 @@ test("Updates", async (t) => {
309350
let res = await fetch(`${address}/owner/repo/darwin-x64/0.0.0`);
310351
t.equal(res.status, 200);
311352
let body = await res.json();
312-
t.equal(body.url, "mac.zip");
353+
t.equal(body.url, "app-mac.zip");
313354

314355
res = await fetch(`${address}/owner/repo/darwin-arm64/0.0.0`);
315356
t.equal(res.status, 200);
316357
body = await res.json();
317-
t.equal(body.url, "mac-arm64.zip");
358+
t.equal(body.url, "app-mac-arm64.zip");
318359

319360
res = await fetch(`${address}/owner/repo/darwin/0.0.0`);
320361
t.equal(res.status, 200);
321362
body = await res.json();
322-
t.equal(body.url, "mac.zip");
363+
t.equal(body.url, "app-mac.zip");
364+
365+
res = await fetch(`${address}/owner/repo/darwin-universal/0.0.0`);
366+
t.equal(res.status, 200);
367+
body = await res.json();
368+
t.equal(body.url, "app-universal-mac.zip");
323369

324370
res = await fetch(`${address}/owner/repo-darwin/darwin-x64/0.0.0`);
325371
t.equal(res.status, 200);
326372
body = await res.json();
327-
t.match(body.url, "darwin.zip");
373+
t.match(body.url, "app-darwin.zip");
328374

329375
res = await fetch(`${address}/owner/repo-darwin/darwin-arm64/0.0.0`);
330376
t.equal(res.status, 200);
331377
body = await res.json();
332-
t.match(body.url, "darwin-arm64.zip");
378+
t.match(body.url, "app-darwin-arm64.zip");
333379

334380
res = await fetch(`${address}/owner/repo-darwin/darwin/0.0.0`);
335381
t.equal(res.status, 200);
336382
body = await res.json();
337-
t.match(body.url, "darwin.zip");
383+
t.match(body.url, "app-darwin.zip");
384+
385+
res = await fetch(
386+
`${address}/owner/repo-darwin/darwin-universal/0.0.0`
387+
);
388+
t.equal(res.status, 200);
389+
body = await res.json();
390+
t.match(body.url, "app-universal-mac.zip");
338391
}
339392
});
340393

@@ -346,15 +399,41 @@ test("Updates", async (t) => {
346399
let body = await res.text();
347400
t.equal(
348401
body,
349-
"No updates found (needs asset matching *(mac|darwin|osx).*(-arm).*.zip in public repository)"
402+
"No updates found (needs asset matching .*-(mac|darwin|osx).*.zip in public repository)"
350403
);
351404

352405
res = await fetch(`${address}/owner/repo-win32-zip/darwin/0.0.0`);
353406
t.equal(res.status, 404);
354407
body = await res.text();
355408
t.equal(
356409
body,
357-
"No updates found (needs asset matching *(mac|darwin|osx).*(-arm).*.zip in public repository)"
410+
"No updates found (needs asset matching .*-(mac|darwin|osx).*.zip in public repository)"
411+
);
412+
});
413+
414+
await t.test("darwin universal assets", async (t) => {
415+
await t.test(
416+
"use universal asset if platform-specific asset not available",
417+
async (t) => {
418+
let res = await fetch(
419+
`${address}/owner/repo-universal/darwin-x64/0.0.0`
420+
);
421+
t.equal(res.status, 200);
422+
let body = await res.json();
423+
t.match(body.url, "app-universal-mac.zip");
424+
}
425+
);
426+
427+
await t.test(
428+
"skip universal asset if platform-specific asset available",
429+
async (t) => {
430+
let res = await fetch(
431+
`${address}/owner/repo-universal/darwin-arm64/0.0.0`
432+
);
433+
t.equal(res.status, 200);
434+
let body = await res.json();
435+
t.match(body.url, "app-arm64-mac.zip");
436+
}
358437
);
359438
});
360439
});
@@ -491,7 +570,7 @@ test("Updates", async (t) => {
491570
const body = await res.text();
492571
t.equal(
493572
body,
494-
'Unsupported platform: "linux". Supported: darwin-x64, darwin-arm64, win32-x64, win32-ia32, win32-arm64.'
573+
'Unsupported platform: "linux". Supported: darwin-x64, darwin-arm64, darwin-universal, win32-x64, win32-ia32, win32-arm64.'
495574
);
496575
});
497576
});
@@ -503,7 +582,7 @@ test("Updates", async (t) => {
503582
const body = await res.text();
504583
t.equal(
505584
body,
506-
'Unsupported platform: "os". Supported: darwin-x64, darwin-arm64, win32-x64, win32-ia32, win32-arm64.'
585+
'Unsupported platform: "os". Supported: darwin-x64, darwin-arm64, darwin-universal, win32-x64, win32-ia32, win32-arm64.'
507586
);
508587
});
509588
});

0 commit comments

Comments
 (0)