Skip to content

Commit cd9e33b

Browse files
fix(generic-package): fix issues when uploading multiple assets (#491)
Fixes #490 Co-authored-by: Jonas Schubert <[email protected]>
1 parent 96bb3e9 commit cd9e33b

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
3535
"gitlabUrl": "https://custom.gitlab.com",
3636
"assets": [
3737
{ "path": "dist/asset.min.css", "label": "CSS distribution" },
38-
{ "path": "dist/asset.min.js", "label": "JS distribution", "type": "generic_package" },
38+
{ "path": "dist/asset.min.js", "label": "JS distribution", "target": "generic_package" },
3939
{ "path": "dist/asset.min.js", "label": "v${nextRelease.version}.js" },
4040
{ "url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md" }
4141
]

lib/publish.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createReadStream } from "fs";
1+
import { createReadStream, readFileSync } from "fs";
22
import pathlib from "path";
33
import fs from "fs-extra";
44
import { isPlainObject, template } from "lodash-es";
@@ -80,10 +80,6 @@ export default async (pluginConfig, context) => {
8080
debug("file target: %o", target);
8181
debug("file status: %o", status);
8282

83-
// Uploaded assets to the project
84-
const form = new FormData();
85-
form.append("file", createReadStream(file));
86-
8783
let uploadEndpoint;
8884
let response;
8985

@@ -100,15 +96,15 @@ export default async (pluginConfig, context) => {
10096
debug("PUT-ing the file %s to %s", file, uploadEndpoint);
10197

10298
try {
103-
response = await got.put(uploadEndpoint, { ...apiOptions, body: form }).json();
99+
response = await got.put(uploadEndpoint, { ...apiOptions, ...proxy, body: readFileSync(file) }).json();
104100
} catch (error) {
105101
logger.error("An error occurred while uploading %s to the GitLab generics package API:\n%O", file, error);
106102
throw error;
107103
}
108104

109105
const { url } = response.file;
110106

111-
assetsList.push({ label, alt: "release", url, type: "package", filepath });
107+
assetsList.push({ label, alt: "release", url, type: "package", filepath, target });
112108

113109
logger.log("Uploaded file: %s", url);
114110
} else {
@@ -118,6 +114,8 @@ export default async (pluginConfig, context) => {
118114
debug("POST-ing the file %s to %s", file, uploadEndpoint);
119115

120116
try {
117+
const form = new FormData();
118+
form.append("file", createReadStream(file));
121119
response = await got.post(uploadEndpoint, { ...apiOptions, ...proxy, body: form }).json();
122120
} catch (error) {
123121
logger.error("An error occurred while uploading %s to the GitLab project uploads API:\n%O", file, error);
@@ -126,7 +124,7 @@ export default async (pluginConfig, context) => {
126124

127125
const { url, alt } = response;
128126

129-
assetsList.push({ label, alt, url, type, filepath });
127+
assetsList.push({ label, alt, url, type, filepath, target });
130128

131129
logger.log("Uploaded file: %s", url);
132130
}
@@ -145,10 +143,10 @@ export default async (pluginConfig, context) => {
145143
description: notes && notes.trim() ? notes : gitTag,
146144
milestones,
147145
assets: {
148-
links: assetsList.map(({ label, alt, url, type, filepath, rawUrl }) => {
146+
links: assetsList.map(({ label, alt, url, type, filepath, rawUrl, target }) => {
149147
return {
150148
name: label || alt,
151-
url: rawUrl || urlJoin(gitlabUrl, repoId, url),
149+
url: rawUrl || (target === "generic_package" ? url : urlJoin(gitlabUrl, repoId, url)),
152150
link_type: type,
153151
filepath,
154152
};

test/publish.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test.serial("Publish a release with generics", async (t) => {
104104
links: [
105105
{
106106
name: "Style package",
107-
url: `https://gitlab.com/${owner}/${repo}${uploaded.file.url}`,
107+
url: uploaded.file.url,
108108
link_type: "package",
109109
},
110110
],
@@ -114,7 +114,7 @@ test.serial("Publish a release with generics", async (t) => {
114114
const gitlabUpload = authenticate(env)
115115
.put(
116116
`/projects/${encodedRepoId}/packages/generic/release/${encodedGitTag}/${encodedLabel}?status=${generic.status}&select=package_file`,
117-
/filename="file.css"/gm
117+
/\.test\s\{\}/gm
118118
)
119119
.reply(200, uploaded);
120120

0 commit comments

Comments
 (0)