-
Notifications
You must be signed in to change notification settings - Fork 80
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
fix: file labels in GitLab releases, to ensure they're unique. #267
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
const path = require('path'); | ||
const {basename} = require('path'); | ||
const {isPlainObject, castArray, uniqWith, uniq} = require('lodash'); | ||
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( | ||
|
@@ -42,7 +41,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)})); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider this a breaking change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fgreinacher I wouldn't unless generating duplicate labels was support somewhere and things depended o nit. Honestly don't know. Seems weird. Imagine creating a listing of files in multiple directories and losing the directory they were in, that was the old behavior. So the labels would collide and the SCM would reject the operation. |
||
} | ||
|
||
// If asset is an Object, output an Object definition with: | ||
|
@@ -66,3 +65,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) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
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; | ||
const {service} = context.envCi || {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 | ||
|
@@ -31,6 +29,7 @@ module.exports = ( | |
: 'https://gitlab.com'); | ||
|
||
return { | ||
pkgRoot, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you are mirroring the NPM plugin here, but the concept of a package does not really exist for the GitLab plugin. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also please add some documentation 🙇 |
||
gitlabToken: GL_TOKEN || GITLAB_TOKEN, | ||
gitlabUrl: defaultedGitlabUrl, | ||
gitlabApiUrl: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ test('Returns user config', t => { | |
gitlabApiUrl: urlJoin(gitlabUrl, gitlabApiPathPrefix), | ||
assets, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
}); | ||
}); | ||
|
||
|
@@ -35,6 +36,7 @@ test('Returns user config via environment variables', t => { | |
gitlabApiUrl: urlJoin(gitlabUrl, gitlabApiPathPrefix), | ||
assets, | ||
milestones, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
|
@@ -53,6 +55,7 @@ test('Returns user config via alternative environment variables', t => { | |
gitlabApiUrl: urlJoin(gitlabUrl, gitlabApiPathPrefix), | ||
assets, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
|
@@ -68,6 +71,7 @@ test('Returns default config', t => { | |
gitlabApiUrl: urlJoin('https://gitlab.com', '/api/v4'), | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
}); | ||
|
||
t.deepEqual(resolveConfig({gitlabApiPathPrefix}, {env: {GL_TOKEN: gitlabToken}}), { | ||
|
@@ -76,6 +80,7 @@ test('Returns default config', t => { | |
gitlabApiUrl: urlJoin('https://gitlab.com', gitlabApiPathPrefix), | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
}); | ||
|
||
t.deepEqual(resolveConfig({gitlabUrl}, {env: {GL_TOKEN: gitlabToken}}), { | ||
|
@@ -84,6 +89,7 @@ test('Returns default config', t => { | |
gitlabApiUrl: urlJoin(gitlabUrl, '/api/v4'), | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
}); | ||
}); | ||
|
||
|
@@ -107,6 +113,7 @@ test('Returns default config via GitLab CI/CD environment variables', t => { | |
gitlabApiUrl: CI_API_V4_URL, | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
|
@@ -134,6 +141,7 @@ test('Returns user config over GitLab CI/CD environment variables', t => { | |
gitlabApiUrl: urlJoin(gitlabUrl, gitlabApiPathPrefix), | ||
assets, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
|
@@ -167,6 +175,7 @@ test('Returns user config via environment variables over GitLab CI/CD environmen | |
gitlabApiUrl: urlJoin(gitlabUrl, gitlabApiPathPrefix), | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
|
@@ -200,6 +209,7 @@ test('Returns user config via alternative environment variables over GitLab CI/C | |
gitlabApiUrl: urlJoin(gitlabUrl, gitlabApiPathPrefix), | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
|
@@ -224,6 +234,7 @@ test('Ignore GitLab CI/CD environment variables if not running on GitLab CI/CD', | |
gitlabApiUrl: urlJoin('https://gitlab.com', '/api/v4'), | ||
assets: undefined, | ||
milestones: undefined, | ||
pkgRoot: undefined, | ||
} | ||
); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some test cases for the new option? Especially weird cases like when the asset is not within the base/root path or when the base/root path is somehow malformed/does not exist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can stay an arrow function, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fgreinacher I'm confused. It's still an arrow function