From f491e136d162da2bfbae2183225bb4830e3c3160 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 5 Jul 2022 16:58:56 +0300 Subject: [PATCH] Sequential uploads to GitHub should work now #13 --- src/publishing/github/github-publisher.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/publishing/github/github-publisher.ts b/src/publishing/github/github-publisher.ts index fd4fbe6..2d80a4c 100644 --- a/src/publishing/github/github-publisher.ts +++ b/src/publishing/github/github-publisher.ts @@ -34,10 +34,22 @@ export default class GitHubPublisher extends ModPublisher { protected async publishMod(_id: string, token: string, name: string, version: string, channel: string, _loaders: string[], _gameVersions: string[], _java: string[], changelog: string, files: File[], _dependencies: Dependency[], options: Record): Promise { const repo = github.context.repo; const octokit = github.getOctokit(token); + const environmentTag = getEnvironmentTag(); + let tag = mapStringInput(options.tag, null); - let releaseId = tag ? await this.getReleaseIdByTag(tag, token) : github.context.payload.release?.id; + let releaseId = 0; + if (tag) { + releaseId = await this.getReleaseIdByTag(tag, token); + } else if (github.context.payload.release?.id) { + releaseId = github.context.payload.release?.id; + } else if (environmentTag) { + releaseId = await this.getReleaseIdByTag(environmentTag, token); + } else if (version) { + releaseId = await this.getReleaseIdByTag(version, token); + } + const generated = !releaseId; - if (!releaseId && (tag ??= getEnvironmentTag() ?? version)) { + if (generated && (tag ??= environmentTag ?? version)) { const generateChangelog = mapBooleanInput(options.generateChangelog, !changelog); const draft = mapBooleanInput(options.draft, false); const prerelease = mapBooleanInput(options.prerelease, channel !== VersionType.Release); @@ -46,7 +58,7 @@ export default class GitHubPublisher extends ModPublisher { releaseId = await this.createRelease(tag, name, changelog, generateChangelog, draft, prerelease, commitish, discussion, token); } if (!releaseId) { - throw new Error(`Cannot find or create release #${options.tag || releaseId}`); + throw new Error(`Cannot find or create release ${tag || `#${releaseId}`}`); } const existingAssets = generated ? [] : (await octokit.rest.repos.listReleaseAssets({ ...repo, release_id: releaseId })).data;