From 32933e7dc67567331da7951eb6b6dda3785f43dd Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 7 Sep 2020 23:18:04 +0800 Subject: [PATCH] fix: continue publish event if release binary to gh failed --- src/pre-publish.ts | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/pre-publish.ts b/src/pre-publish.ts index ac1de592..4e2ecdd2 100644 --- a/src/pre-publish.ts +++ b/src/pre-publish.ts @@ -85,14 +85,21 @@ export class PrePublishCommand extends Command { ) if (!this.isDryRun) { const putasset = require('putasset') - const downloadUrl = await putasset(process.env.GITHUB_TOKEN, { - owner, - repo, - tag: pkgInfo.tag, - filename: dstPath, - }) - console.info(`${chalk.green(dstPath)} upload success`) - console.info(`Download url: ${chalk.blueBright(downloadUrl)}`) + try { + const downloadUrl = await putasset(process.env.GITHUB_TOKEN, { + owner, + repo, + tag: pkgInfo.tag, + filename: dstPath, + }) + console.info(`${chalk.green(dstPath)} upload success`) + console.info(`Download url: ${chalk.blueBright(downloadUrl)}`) + } catch (e) { + debug( + `Param: ${{ owner, repo, tag: pkgInfo.tag, filename: dstPath }}`, + ) + console.error(e) + } } } } @@ -101,6 +108,8 @@ export class PrePublishCommand extends Command { const headCommit = (await spawn('git log -1 --pretty=%B')) .toString('utf8') .trim() + + debug(`Github repository: ${process.env.GITHUB_REPOSITORY}`) const [owner, repo] = process.env.GITHUB_REPOSITORY!.split('/') const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN, @@ -129,11 +138,16 @@ export class PrePublishCommand extends Command { } } if (!this.isDryRun) { - await octokit.repos.createRelease({ - owner, - repo, - tag_name: pkgInfo.tag, - }) + try { + await octokit.repos.createRelease({ + owner, + repo, + tag_name: pkgInfo.tag, + }) + } catch (e) { + debug(`Params: ${{ owner, repo, tag_name: pkgInfo.tag }}`) + console.error(e) + } } return { owner, repo, pkgInfo } }