Skip to content

Commit f03a4fc

Browse files
committed
fix: parallel release creation with keygen publisher
1 parent b45a6db commit f03a4fc

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

.changeset/mighty-otters-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
Fix issue where, upon publishing a new release, electron-builder would attempt to create the same release for each artifact in parallel, resulting in conflict errors.

packages/app-builder-lib/src/publish/KeygenPublisher.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,25 @@ export class KeygenPublisher extends HttpPublisher {
181181

182182
private async getOrCreateRelease(): Promise<{ data?: KeygenRelease; errors?: KeygenError[] }> {
183183
try {
184+
// First, we'll attempt to fetch the release.
184185
return await this.getRelease()
185186
} catch (e) {
186-
if (e.statusCode === 404) {
187-
return this.createRelease()
187+
if (e.statusCode !== 404) {
188+
throw e
188189
}
189190

190-
throw e
191+
try {
192+
// Next, if the release doesn't exist, we'll attempt to create it.
193+
return await this.createRelease()
194+
} catch (e) {
195+
if (e.statusCode !== 409 && e.statusCode !== 422) {
196+
throw e
197+
}
198+
199+
// Lastly, when a conflict occurs (in the case of parallel uploads),
200+
// we'll try to fetch it one last time.
201+
return this.getRelease()
202+
}
191203
}
192204
}
193205

test/src/ArtifactPublisherTest.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function versionNumber() {
3232
//noinspection SpellCheckingInspection
3333
const token = Buffer.from("Y2Y5NDdhZDJhYzJlMzg1OGNiNzQzYzcwOWZhNGI0OTk2NWQ4ZDg3Yg==", "base64").toString()
3434
const iconPath = path.join(__dirname, "..", "fixtures", "test-app", "build", "icon.icns")
35+
const icoPath = path.join(__dirname, "..", "fixtures", "test-app", "build", "icon.ico")
3536

3637
const publishContext: PublishContext = {
3738
cancellationToken: new CancellationToken(),
@@ -138,7 +139,12 @@ test.ifEnv(process.env.KEYGEN_TOKEN)("Keygen upload", async () => {
138139
} as KeygenOptions,
139140
versionNumber()
140141
)
141-
const releaseId = await publisher.upload({ file: iconPath, arch: Arch.x64 })
142+
const [releaseId] = await Promise.all([
143+
publisher.upload({ file: iconPath, arch: Arch.x64 }),
144+
// test parallel artifact uploads for the same release
145+
publisher.upload({ file: icoPath, arch: Arch.x64 }),
146+
])
147+
142148
await publisher.deleteRelease(releaseId)
143149
})
144150

0 commit comments

Comments
 (0)