Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
"gitlabUrl": "https://custom.gitlab.com",
"assets": [
{ "path": "dist/asset.min.css", "label": "CSS distribution" },
{ "path": "dist/asset.min.js", "label": "JS distribution", "type": "generic_package" },
{ "path": "dist/asset.min.js", "label": "JS distribution", "target": "generic_package" },
{ "path": "dist/asset.min.js", "label": "v${nextRelease.version}.js" },
{ "url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md" }
]
Expand Down
18 changes: 8 additions & 10 deletions lib/publish.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReadStream } from "fs";
import { createReadStream, readFileSync } from "fs";
import pathlib from "path";
import fs from "fs-extra";
import { isPlainObject, template } from "lodash-es";
Expand Down Expand Up @@ -80,10 +80,6 @@ export default async (pluginConfig, context) => {
debug("file target: %o", target);
debug("file status: %o", status);

// Uploaded assets to the project
const form = new FormData();
form.append("file", createReadStream(file));

let uploadEndpoint;
let response;

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

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

const { url } = response.file;

assetsList.push({ label, alt: "release", url, type: "package", filepath });
assetsList.push({ label, alt: "release", url, type: "package", filepath, target });

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

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

const { url, alt } = response;

assetsList.push({ label, alt, url, type, filepath });
assetsList.push({ label, alt, url, type, filepath, target });

logger.log("Uploaded file: %s", url);
}
Expand All @@ -145,10 +143,10 @@ export default async (pluginConfig, context) => {
description: notes && notes.trim() ? notes : gitTag,
milestones,
assets: {
links: assetsList.map(({ label, alt, url, type, filepath, rawUrl }) => {
links: assetsList.map(({ label, alt, url, type, filepath, rawUrl, target }) => {
return {
name: label || alt,
url: rawUrl || urlJoin(gitlabUrl, repoId, url),
url: rawUrl || (target === "generic_package" ? url : urlJoin(gitlabUrl, repoId, url)),
link_type: type,
filepath,
};
Expand Down
4 changes: 2 additions & 2 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test.serial("Publish a release with generics", async (t) => {
links: [
{
name: "Style package",
url: `https://gitlab.com/${owner}/${repo}${uploaded.file.url}`,
url: uploaded.file.url,
link_type: "package",
},
],
Expand All @@ -114,7 +114,7 @@ test.serial("Publish a release with generics", async (t) => {
const gitlabUpload = authenticate(env)
.put(
`/projects/${encodedRepoId}/packages/generic/release/${encodedGitTag}/${encodedLabel}?status=${generic.status}&select=package_file`,
/filename="file.css"/gm
/\.test\s\{\}/gm
)
.reply(200, uploaded);

Expand Down