Skip to content

fix: allow custom package name when uploading generic_package assets #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

phuocnb
Copy link

@phuocnb phuocnb commented Sep 28, 2023

The current generic_package upload does not allow to set a custom package name. It's always release.

According to gitlab url format:
/projects/:id/packages/generic/:package_name/:package_version/:file_name?status=:status

What i did:
I add packageName as a new option of asset that allows to set a custom package name instead of release. It will use release as package name if the option is not defined.

@phuocnb
Copy link
Author

phuocnb commented Sep 28, 2023

It actually does not correct if the configuration provide a regex path (may match multiple files to upload).
I will update the file_name to take the basename of actual uploading file instead of using label.

Copy link
Contributor

@JonasSchubert JonasSchubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the option to configure the package name is a good idea.
But I would only provide this configuration option and would not change other functionalities.
Unit tests should be added, too.

lib/publish.js Outdated
@@ -88,11 +88,14 @@ export default async (pluginConfig, context) => {

if (target === "generic_package") {
// Upload generic packages
const encodedLabel = encodeURIComponent(label);
const { major, minor, patch } = semver.parse(version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand that correct, this renders it impossible to use prereleases (alpha, beta).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this does not look correct. GitLab allows much more:

The package version. The following regex validates this: \A(.?[\w+-]+.?)+\z. You can test your version strings on Rubular.

@phuocnb
Copy link
Author

phuocnb commented Sep 29, 2023

IMO the option to configure the package name is a good idea. But I would only provide this configuration option and would not change other functionalities. Unit tests should be added, too.

I would update the implementation and add unit tests later when the implementation has been approved.

@phuocnb phuocnb marked this pull request as draft September 29, 2023 02:16
@fgreinacher
Copy link
Contributor

fgreinacher commented Oct 5, 2023

IMO the option to configure the package name is a good idea. But I would only provide this configuration option and would not change other functionalities. Unit tests should be added, too.

I would update the implementation and add unit tests later when the implementation has been approved.

@phuocnb Feel free to go on and ping me if you're stuck somewhere!

@phuocnb
Copy link
Author

phuocnb commented Nov 4, 2023

IMO the option to configure the package name is a good idea. But I would only provide this configuration option and would not change other functionalities. Unit tests should be added, too.

I would update the implementation and add unit tests later when the implementation has been approved.

@phuocnb Feel free to go on and ping me if you're stuck somewhere!

I were so busy in the last 2 months.
I'm back to this today.

@phuocnb
Copy link
Author

phuocnb commented Nov 8, 2023

@fgreinacher @JonasSchubert
Depends on a testing project on gitlab, i'm pretty sure that this label config will not work in case of using generic_package

"@semantic-release/gitlab",
{
        "gitlabUrl": "https://gitlab.com",
        "assets": [
	        {
		        "path": "assets/single-file.md",
		        "label": "Single Label",
		        "target": "generic_package"
	        }
        ]
}

The upload request actually return a 400 HTTP Error code.

This is the full job log
failed-job.txt


After running the above job, the result is:

  • A new tag has been created
  • No release is created
  • Nothing is uploaded to generic package

Changing the label value to match the filename and the job would be succeeded.

"@semantic-release/gitlab",
{
        "gitlabUrl": "https://gitlab.com",
        "assets": [
	        {
		        "path": "assets/single-file.md",
		        "label": "single-file.md",
		        "target": "generic_package"
	        }
        ]
}

In the publish.js:

line 98-103

uploadEndpoint = urlJoin(
              gitlabApiUrl,
              `/projects/${encodedRepoId}/packages/generic/release/${encodedVersion}/${encodedLabel}?${
                status ? `status=${status}&` : ""
              }select=package_file`
            );

line 115-118

const url = urlJoin(
              gitlabApiUrl,
              `/projects/${encodedRepoId}/packages/generic/release/${encodedVersion}/${encodedLabel}`
            );

I believe that encodedLabel should be changed to encodedFilename (which is calculated from file path).

This is the original issue that i want to commit a fix on this PR.

Anyway, i still working on this issue (on another branch).
Since the PR does not allow me to change the source branch, do you have any suggestion to let me do it?

@fgreinacher fgreinacher marked this pull request as ready for review December 3, 2024 11:05
@fgreinacher fgreinacher marked this pull request as draft December 3, 2024 11:05
@Rechem
Copy link

Rechem commented Jul 29, 2025

Any updates on this ? I really need this feature for my workflow too

@phuocnb phuocnb requested a review from JonasSchubert August 6, 2025 04:24
@phuocnb phuocnb requested a review from fgreinacher August 6, 2025 07:17
@phuocnb phuocnb changed the title fix: use channel as package name for generic_package upload fix: allow custom package name for generic_package Aug 6, 2025
@phuocnb phuocnb changed the title fix: allow custom package name for generic_package fix: allow custom package name when uploading generic_package assets Aug 6, 2025
henryaw added 2 commits August 6, 2025 14:48
same filenames may exist in different directories
@phuocnb phuocnb marked this pull request as ready for review August 6, 2025 08:40
@fgreinacher
Copy link
Contributor

Thanks for getting back to this @phuocnb! The implementation looks fine at a first sight. Would you please update the PR description to match the implementation? Just to not confuse users that end up here from the changelog 😀 Thansk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants