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

Commit ba666c0

Browse files
eyal0marvinpinto
authored andcommittedMar 23, 2021
fix: report error if a file glob doesn't match anything
This fixes #62
1 parent cc033a0 commit ba666c0

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed
 

‎packages/automatic-releases/src/uploadReleaseArtifacts.ts

+32-27
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,40 @@ import md5File from 'md5-file';
77

88
export const uploadReleaseArtifacts = async (client: github.GitHub, uploadUrl: string, files: string[]) => {
99
core.startGroup('Uploading release artifacts');
10-
const paths = await globby(files);
10+
for (const fileGlob of files) {
11+
const paths = await globby(fileGlob);
12+
if (paths.length == 0) {
13+
core.error(`${fileGlob} doesn't match any files`);
14+
}
1115

12-
for (const filePath of paths) {
13-
core.info(`Uploading: ${filePath}`);
14-
const nameWithExt = path.basename(filePath);
15-
const uploadArgs = {
16-
url: uploadUrl,
17-
headers: {
18-
'content-length': lstatSync(filePath).size,
19-
'content-type': 'application/octet-stream',
20-
},
21-
name: nameWithExt,
22-
file: readFileSync(filePath),
23-
};
16+
for (const filePath of paths) {
17+
core.info(`Uploading: ${filePath}`);
18+
const nameWithExt = path.basename(filePath);
19+
const uploadArgs = {
20+
url: uploadUrl,
21+
headers: {
22+
'content-length': lstatSync(filePath).size,
23+
'content-type': 'application/octet-stream',
24+
},
25+
name: nameWithExt,
26+
file: readFileSync(filePath),
27+
};
2428

25-
try {
26-
await client.repos.uploadReleaseAsset(uploadArgs);
27-
} catch (err) {
28-
core.info(
29-
`Problem uploading ${filePath} as a release asset (${err.message}). Will retry with the md5 hash appended to the filename.`,
30-
);
31-
const hash = await md5File(filePath);
32-
const basename = path.basename(filePath, path.extname(filePath));
33-
const ext = path.extname(filePath);
34-
const newName = ext ? `${basename}-${hash}.${ext}` : `${basename}-${hash}`;
35-
await client.repos.uploadReleaseAsset({
36-
...uploadArgs,
37-
name: newName,
38-
});
29+
try {
30+
await client.repos.uploadReleaseAsset(uploadArgs);
31+
} catch (err) {
32+
core.info(
33+
`Problem uploading ${filePath} as a release asset (${err.message}). Will retry with the md5 hash appended to the filename.`,
34+
);
35+
const hash = await md5File(filePath);
36+
const basename = path.basename(filePath, path.extname(filePath));
37+
const ext = path.extname(filePath);
38+
const newName = ext ? `${basename}-${hash}.${ext}` : `${basename}-${hash}`;
39+
await client.repos.uploadReleaseAsset({
40+
...uploadArgs,
41+
name: newName,
42+
});
43+
}
3944
}
4045
}
4146
core.endGroup();

0 commit comments

Comments
 (0)
This repository has been archived.