From 7df651f416c12131983333d8b1d657802b6f106a Mon Sep 17 00:00:00 2001 From: Eyal <109809+eyal0@users.noreply.github.com> Date: Tue, 5 Jan 2021 16:15:36 -0700 Subject: [PATCH] fix: report error if a file glob doesn't match anything This fixes #62 --- .../src/uploadReleaseArtifacts.ts | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/packages/automatic-releases/src/uploadReleaseArtifacts.ts b/packages/automatic-releases/src/uploadReleaseArtifacts.ts index 70f0a4c6..e2182656 100644 --- a/packages/automatic-releases/src/uploadReleaseArtifacts.ts +++ b/packages/automatic-releases/src/uploadReleaseArtifacts.ts @@ -7,35 +7,40 @@ import md5File from 'md5-file'; export const uploadReleaseArtifacts = async (client: github.GitHub, uploadUrl: string, files: string[]) => { core.startGroup('Uploading release artifacts'); - const paths = await globby(files); + for (const fileGlob of files) { + const paths = await globby(fileGlob); + if (paths.length == 0) { + core.error(`${fileGlob} doesn't match any files`); + } - for (const filePath of paths) { - core.info(`Uploading: ${filePath}`); - const nameWithExt = path.basename(filePath); - const uploadArgs = { - url: uploadUrl, - headers: { - 'content-length': lstatSync(filePath).size, - 'content-type': 'application/octet-stream', - }, - name: nameWithExt, - file: readFileSync(filePath), - }; + for (const filePath of paths) { + core.info(`Uploading: ${filePath}`); + const nameWithExt = path.basename(filePath); + const uploadArgs = { + url: uploadUrl, + headers: { + 'content-length': lstatSync(filePath).size, + 'content-type': 'application/octet-stream', + }, + name: nameWithExt, + file: readFileSync(filePath), + }; - try { - await client.repos.uploadReleaseAsset(uploadArgs); - } catch (err) { - core.info( - `Problem uploading ${filePath} as a release asset (${err.message}). Will retry with the md5 hash appended to the filename.`, - ); - const hash = await md5File(filePath); - const basename = path.basename(filePath, path.extname(filePath)); - const ext = path.extname(filePath); - const newName = ext ? `${basename}-${hash}.${ext}` : `${basename}-${hash}`; - await client.repos.uploadReleaseAsset({ - ...uploadArgs, - name: newName, - }); + try { + await client.repos.uploadReleaseAsset(uploadArgs); + } catch (err) { + core.info( + `Problem uploading ${filePath} as a release asset (${err.message}). Will retry with the md5 hash appended to the filename.`, + ); + const hash = await md5File(filePath); + const basename = path.basename(filePath, path.extname(filePath)); + const ext = path.extname(filePath); + const newName = ext ? `${basename}-${hash}.${ext}` : `${basename}-${hash}`; + await client.repos.uploadReleaseAsset({ + ...uploadArgs, + name: newName, + }); + } } } core.endGroup();