Skip to content

Commit

Permalink
fix: file labels in GitLab releases, to ensure they're unique.
Browse files Browse the repository at this point in the history
Previously GitLab lables were just the basename for files uploaded as
part of the release. This is problematic because GitLab doesn't allow
conflicting labels -- a condition that could be caused by uploading a
release with two files by the same name in different directories. This
would generate a 409 Conflict error.

This patches changes the labels for files uploaded as part of a release
to the name relative to pkgRoot, or the package.

A project may look like this

  pkg
  pkg \ foo \ baz
  pkg \ bar \ baz

This used to creating two conflicting labels of 'baz'. Now you would
have {"foo/baz", "bar/baz"} with no conflict.

GitHub issues: semantic-release#263, semantic-release#158
  • Loading branch information
EvanCarroll committed Jul 29, 2021
1 parent 2671c06 commit e3aebfe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions lib/glob-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const dirGlob = require('dir-glob');
const globby = require('globby');
const debug = require('debug')('semantic-release:gitlab');

module.exports = async ({cwd}, assets) =>
uniqWith(
module.exports = async ({pkgRoot,cwd}, assets) => {
return uniqWith(
[]
.concat(
...(await Promise.all(
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = async ({cwd}, assets) =>
// - `filepath` ignored (also to avoid duplicates)
// - other properties of the original asset definition
const {filepath, ...others} = asset;
return globbed.map(file => ({...others, path: file, label: basename(file)}));
return globbed.map(file => ({...others, path: file, label: path.relative(pkgRoot || ".", file)}));
}

// If asset is an Object, output an Object definition with:
Expand All @@ -66,3 +66,4 @@ module.exports = async ({cwd}, assets) =>
// Compare `path` property if Object definition, value itself if String
(a, b) => path.resolve(cwd, isPlainObject(a) ? a.path : a) === path.resolve(cwd, isPlainObject(b) ? b.path : b)
);
}
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = async (pluginConfig, context) => {
debug('milestones: %o', milestones);

if (assets && assets.length > 0) {
const globbedAssets = await getAssets(context, assets);
const globbedAssets = await getAssets({cwd: context.cwd, pkgRoot: pluginConfig.pkgRoot}, assets);
debug('globbed assets: %o', globbedAssets);

await Promise.all(
Expand Down
34 changes: 17 additions & 17 deletions lib/resolve-config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
const {castArray, isNil} = require('lodash');
const urlJoin = require('url-join');

module.exports = (
{gitlabUrl, gitlabApiPathPrefix, assets, milestones},
{
envCi: {service} = {},
env: {
CI_PROJECT_URL,
CI_PROJECT_PATH,
CI_API_V4_URL,
GL_TOKEN,
GITLAB_TOKEN,
GL_URL,
GITLAB_URL,
GL_PREFIX,
GITLAB_PREFIX,
},
}
) => {
module.exports = (pluginConfig, context) => {
const {gitlabUrl, gitlabApiPathPrefix, assets, milestones, pkgRoot} = pluginConfig;
// Not sure wht the history is here...
const service = undefined;
const {
CI_PROJECT_URL,
CI_PROJECT_PATH,
CI_API_V4_URL,
GL_TOKEN,
GITLAB_TOKEN,
GL_URL,
GITLAB_URL,
GL_PREFIX,
GITLAB_PREFIX,
} = context.env;

const userGitlabApiPathPrefix = isNil(gitlabApiPathPrefix)
? isNil(GL_PREFIX)
? GITLAB_PREFIX
Expand All @@ -31,6 +30,7 @@ module.exports = (
: 'https://gitlab.com');

return {
pkgRoot,
gitlabToken: GL_TOKEN || GITLAB_TOKEN,
gitlabUrl: defaultedGitlabUrl,
gitlabApiUrl:
Expand Down

0 comments on commit e3aebfe

Please sign in to comment.