Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Report error if a file glob doesn't match anything #63

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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