Skip to content

Commit

Permalink
fix: parallel release creation with keygen publisher (#6989)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg authored Jul 6, 2022
1 parent b45a6db commit 7ad5101
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-otters-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

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.
18 changes: 15 additions & 3 deletions packages/app-builder-lib/src/publish/KeygenPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,25 @@ export class KeygenPublisher extends HttpPublisher {

private async getOrCreateRelease(): Promise<{ data?: KeygenRelease; errors?: KeygenError[] }> {
try {
// First, we'll attempt to fetch the release.
return await this.getRelease()
} catch (e) {
if (e.statusCode === 404) {
return this.createRelease()
if (e.statusCode !== 404) {
throw e
}

throw e
try {
// Next, if the release doesn't exist, we'll attempt to create it.
return await this.createRelease()
} catch (e) {
if (e.statusCode !== 409 && e.statusCode !== 422) {
throw e
}

// Lastly, when a conflict occurs (in the case of parallel uploads),
// we'll try to fetch it one last time.
return this.getRelease()
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion test/src/ArtifactPublisherTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function versionNumber() {
//noinspection SpellCheckingInspection
const token = Buffer.from("Y2Y5NDdhZDJhYzJlMzg1OGNiNzQzYzcwOWZhNGI0OTk2NWQ4ZDg3Yg==", "base64").toString()
const iconPath = path.join(__dirname, "..", "fixtures", "test-app", "build", "icon.icns")
const icoPath = path.join(__dirname, "..", "fixtures", "test-app", "build", "icon.ico")

const publishContext: PublishContext = {
cancellationToken: new CancellationToken(),
Expand Down Expand Up @@ -138,7 +139,12 @@ test.ifEnv(process.env.KEYGEN_TOKEN)("Keygen upload", async () => {
} as KeygenOptions,
versionNumber()
)
const releaseId = await publisher.upload({ file: iconPath, arch: Arch.x64 })
const [releaseId] = await Promise.all([
publisher.upload({ file: iconPath, arch: Arch.x64 }),
// test parallel artifact uploads for the same release
publisher.upload({ file: icoPath, arch: Arch.x64 }),
])

await publisher.deleteRelease(releaseId)
})

Expand Down

0 comments on commit 7ad5101

Please sign in to comment.