Skip to content

Commit

Permalink
fix: report error if a file glob doesn't match anything
Browse files Browse the repository at this point in the history
This fixes marvinpinto#62
  • Loading branch information
eyal0 committed Mar 23, 2021
1 parent cc033a0 commit 7df651f
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions packages/automatic-releases/src/uploadReleaseArtifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7df651f

Please sign in to comment.