From 517c31cf3f808e0f03c351f0c151f6566450134a Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Wed, 1 Feb 2023 11:18:38 +0100 Subject: [PATCH 1/7] fix(generic-packages): fix URL if gitlabApiUrl is set --- lib/publish.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/publish.js b/lib/publish.js index b081dfa9..49d401d1 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -108,7 +108,7 @@ export default async (pluginConfig, context) => { 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 { @@ -126,7 +126,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); } @@ -145,10 +145,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, }; From 0a03468fed69ad3d062f2db99e419555654459f0 Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Wed, 1 Feb 2023 11:18:58 +0100 Subject: [PATCH 2/7] fix(generic-packages): add missing proxy --- lib/publish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/publish.js b/lib/publish.js index 49d401d1..0e46c037 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -100,7 +100,7 @@ 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: form }).json(); } catch (error) { logger.error("An error occurred while uploading %s to the GitLab generics package API:\n%O", file, error); throw error; From 24fda1e3b7b775e7aaa382d6bf0001d2e89351af Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Wed, 1 Feb 2023 11:22:36 +0100 Subject: [PATCH 3/7] docs(generic-packages): set correct example in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa26ae6b..208eb7f2 100644 --- a/README.md +++ b/README.md @@ -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" } ] From 91c58b7a57c70df27b44d8b38e3587982b62e6ba Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Wed, 1 Feb 2023 11:36:38 +0100 Subject: [PATCH 4/7] test(generic-packages): set correct URL --- test/publish.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/publish.test.js b/test/publish.test.js index 4e15ebed..c4684248 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -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", }, ], From ca2c4e6d43e40a36ac1786a8eb0e4fea78a0782e Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Wed, 1 Feb 2023 11:44:50 +0100 Subject: [PATCH 5/7] fix(generic-packages): use stream to fix content #490 --- lib/publish.js | 9 +++++---- test/publish.test.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/publish.js b/lib/publish.js index 0e46c037..b5dfbb30 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -80,9 +80,8 @@ 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)); + // Create the file stream + const stream = createReadStream(file); let uploadEndpoint; let response; @@ -100,7 +99,7 @@ export default async (pluginConfig, context) => { debug("PUT-ing the file %s to %s", file, uploadEndpoint); try { - response = await got.put(uploadEndpoint, { ...apiOptions, ...proxy, body: form }).json(); + response = await got.put(uploadEndpoint, { ...apiOptions, ...proxy, body: stream }).json(); } catch (error) { logger.error("An error occurred while uploading %s to the GitLab generics package API:\n%O", file, error); throw error; @@ -118,6 +117,8 @@ export default async (pluginConfig, context) => { debug("POST-ing the file %s to %s", file, uploadEndpoint); try { + const form = new FormData(); + form.append("file", stream); 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); diff --git a/test/publish.test.js b/test/publish.test.js index c4684248..40371fe5 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -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); From 70299f40f0a9d6de0ea63c7b50bc9a69ba383c6b Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Wed, 1 Feb 2023 11:45:40 +0100 Subject: [PATCH 6/7] chore(lint): use correct quotes --- lib/publish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/publish.js b/lib/publish.js index b5dfbb30..ffc91c98 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -149,7 +149,7 @@ export default async (pluginConfig, context) => { links: assetsList.map(({ label, alt, url, type, filepath, rawUrl, target }) => { return { name: label || alt, - url: rawUrl || (target === 'generic_package' ? url : urlJoin(gitlabUrl, repoId, url)), + url: rawUrl || (target === "generic_package" ? url : urlJoin(gitlabUrl, repoId, url)), link_type: type, filepath, }; From 0f9c772c86db670e9165907245d7b248b46952bd Mon Sep 17 00:00:00 2001 From: Jonas Schubert Date: Thu, 2 Feb 2023 07:38:43 +0100 Subject: [PATCH 7/7] fix(generic-package): use readFileSync instead of stream to avoid issues uploading multiple assets #490 --- lib/publish.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/publish.js b/lib/publish.js index ffc91c98..56c69027 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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"; @@ -80,9 +80,6 @@ export default async (pluginConfig, context) => { debug("file target: %o", target); debug("file status: %o", status); - // Create the file stream - const stream = createReadStream(file); - let uploadEndpoint; let response; @@ -99,7 +96,7 @@ export default async (pluginConfig, context) => { debug("PUT-ing the file %s to %s", file, uploadEndpoint); try { - response = await got.put(uploadEndpoint, { ...apiOptions, ...proxy, body: stream }).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; @@ -118,7 +115,7 @@ export default async (pluginConfig, context) => { try { const form = new FormData(); - form.append("file", stream); + 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);