release-it 17.9.0 → 17.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/config/release-it.json +2 -0
- package/lib/plugin/GitBase.js +1 -1
- package/lib/plugin/gitlab/GitLab.js +74 -35
- package/package.json +17 -17
- package/schema/gitlab.json +8 -0
- package/test/gitlab.js +30 -3
- package/test/stub/gitlab.js +21 -3
- package/test/tasks.js +1 -1
- package/types/config.d.ts +6 -0
package/README.md
CHANGED
package/config/release-it.json
CHANGED
package/lib/plugin/GitBase.js
CHANGED
|
@@ -27,7 +27,7 @@ class GitBase extends Plugin {
|
|
|
27
27
|
|
|
28
28
|
getLatestVersion() {
|
|
29
29
|
const { tagTemplate, latestTag } = this.config.getContext();
|
|
30
|
-
const prefix = tagTemplate.replace(/\$\{version\}/, '');
|
|
30
|
+
const prefix = format(tagTemplate.replace(/\$\{version\}/, ''), this.config.getContext());
|
|
31
31
|
return latestTag ? latestTag.replace(prefix, '').replace(/^v/, '') : null;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -167,24 +167,40 @@ class GitLab extends Release {
|
|
|
167
167
|
'user-agent': 'webpro/release-it',
|
|
168
168
|
[tokenHeader]: this.token
|
|
169
169
|
};
|
|
170
|
+
// When using fetch() with FormData bodies, we should not set the Content-Type header.
|
|
171
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects#sending_files_using_a_formdata_object
|
|
172
|
+
if (!(options.body instanceof FormData)) {
|
|
173
|
+
headers['Content-Type'] = typeof options.json !== 'undefined' ? 'application/json' : 'text/plain';
|
|
174
|
+
}
|
|
170
175
|
const requestOptions = {
|
|
171
176
|
method,
|
|
172
177
|
headers,
|
|
173
178
|
...this.certificateAuthorityOption
|
|
174
179
|
};
|
|
175
180
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
181
|
+
try {
|
|
182
|
+
const response = await fetch(
|
|
183
|
+
url,
|
|
184
|
+
options.json || options.body
|
|
185
|
+
? {
|
|
186
|
+
...requestOptions,
|
|
187
|
+
body: options.json ? JSON.stringify(options.json) : options.body
|
|
188
|
+
}
|
|
189
|
+
: requestOptions
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
const body = await response.json();
|
|
194
|
+
throw new Error(body.error);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const body = await response.json();
|
|
198
|
+
this.debug(body);
|
|
199
|
+
return body;
|
|
200
|
+
} catch (err) {
|
|
201
|
+
this.debug(err);
|
|
202
|
+
throw err;
|
|
203
|
+
}
|
|
188
204
|
}
|
|
189
205
|
|
|
190
206
|
async createRelease() {
|
|
@@ -195,7 +211,7 @@ class GitLab extends Release {
|
|
|
195
211
|
const name = format(releaseName, this.config.getContext());
|
|
196
212
|
const tagMessage = format(tagAnnotation, this.config.getContext());
|
|
197
213
|
const description = releaseNotes || '-';
|
|
198
|
-
const releaseUrl = `${origin}/${repo.repository}/-/releases`;
|
|
214
|
+
const releaseUrl = `${origin}/${repo.repository}/-/releases/${tagName}`;
|
|
199
215
|
const releaseMilestones = this.getReleaseMilestones();
|
|
200
216
|
|
|
201
217
|
this.log.exec(`gitlab releases#createRelease "${name}" (${tagName})`, { isDryRun });
|
|
@@ -227,10 +243,11 @@ class GitLab extends Release {
|
|
|
227
243
|
}
|
|
228
244
|
|
|
229
245
|
try {
|
|
230
|
-
await this.request(endpoint, options);
|
|
246
|
+
const body = await this.request(endpoint, options);
|
|
247
|
+
const releaseUrlSelf = body._links?.self ?? releaseUrl;
|
|
231
248
|
this.log.verbose('gitlab releases#createRelease: done');
|
|
232
|
-
this.setContext({ isReleased: true, releaseUrl });
|
|
233
|
-
this.config.setContext({ isReleased: true, releaseUrl });
|
|
249
|
+
this.setContext({ isReleased: true, releaseUrl: releaseUrlSelf });
|
|
250
|
+
this.config.setContext({ isReleased: true, releaseUrl: releaseUrlSelf });
|
|
234
251
|
return true;
|
|
235
252
|
} catch (err) {
|
|
236
253
|
this.debug(err);
|
|
@@ -240,25 +257,47 @@ class GitLab extends Release {
|
|
|
240
257
|
|
|
241
258
|
async uploadAsset(filePath) {
|
|
242
259
|
const name = path.basename(filePath);
|
|
243
|
-
const { useIdsForUrls } = this.options;
|
|
244
|
-
const { id, origin, repo } = this.getContext();
|
|
245
|
-
const endpoint =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
const { useIdsForUrls, useGenericPackageRepositoryForAssets, genericPackageRepositoryName } = this.options;
|
|
261
|
+
const { id, origin, repo, version, baseUrl } = this.getContext();
|
|
262
|
+
const endpoint = useGenericPackageRepositoryForAssets
|
|
263
|
+
? `projects/${id}/packages/generic/${genericPackageRepositoryName}/${version}/${name}`
|
|
264
|
+
: `projects/${id}/uploads`;
|
|
265
|
+
if (useGenericPackageRepositoryForAssets) {
|
|
266
|
+
const options = {
|
|
267
|
+
method: 'PUT',
|
|
268
|
+
body: await fs.promises.readFile(filePath)
|
|
269
|
+
};
|
|
270
|
+
try {
|
|
271
|
+
const body = await this.request(endpoint, options);
|
|
272
|
+
if (!(body.message && body.message == '201 Created')) {
|
|
273
|
+
throw new Error(`GitLab asset upload failed`);
|
|
274
|
+
}
|
|
275
|
+
this.log.verbose(`gitlab releases#uploadAsset: done (${endpoint})`);
|
|
276
|
+
this.assets.push({
|
|
277
|
+
name,
|
|
278
|
+
url: `${baseUrl}/${endpoint}`
|
|
279
|
+
});
|
|
280
|
+
} catch (err) {
|
|
281
|
+
this.debug(err);
|
|
282
|
+
throw err;
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
const body = new FormData();
|
|
286
|
+
const rawData = await fs.promises.readFile(filePath);
|
|
287
|
+
body.set('file', new Blob([rawData]), name);
|
|
288
|
+
const options = { body };
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
const body = await this.request(endpoint, options);
|
|
292
|
+
this.log.verbose(`gitlab releases#uploadAsset: done (${body.url})`);
|
|
293
|
+
this.assets.push({
|
|
294
|
+
name,
|
|
295
|
+
url: useIdsForUrls ? `${origin}${body.full_path}` : `${origin}/${repo.repository}${body.url}`
|
|
296
|
+
});
|
|
297
|
+
} catch (err) {
|
|
298
|
+
this.debug(err);
|
|
299
|
+
throw err;
|
|
300
|
+
}
|
|
262
301
|
}
|
|
263
302
|
}
|
|
264
303
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "release-it",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.11.0",
|
|
4
4
|
"description": "Generic CLI tool to automate versioning and package publishing-related tasks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"build",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"@iarna/toml": "2.2.5",
|
|
82
82
|
"@octokit/rest": "20.1.1",
|
|
83
83
|
"async-retry": "1.3.3",
|
|
84
|
-
"chalk": "5.
|
|
85
|
-
"ci-info": "^4.
|
|
84
|
+
"chalk": "5.4.1",
|
|
85
|
+
"ci-info": "^4.1.0",
|
|
86
86
|
"cosmiconfig": "9.0.0",
|
|
87
87
|
"execa": "8.0.0",
|
|
88
88
|
"git-url-parse": "14.0.0",
|
|
@@ -93,41 +93,41 @@
|
|
|
93
93
|
"mime-types": "2.1.35",
|
|
94
94
|
"new-github-release-url": "2.0.0",
|
|
95
95
|
"open": "10.1.0",
|
|
96
|
-
"ora": "8.1.
|
|
96
|
+
"ora": "8.1.1",
|
|
97
97
|
"os-name": "5.1.0",
|
|
98
|
-
"proxy-agent": "6.
|
|
98
|
+
"proxy-agent": "6.5.0",
|
|
99
99
|
"semver": "7.6.3",
|
|
100
100
|
"shelljs": "0.8.5",
|
|
101
101
|
"update-notifier": "7.3.1",
|
|
102
102
|
"url-join": "5.0.0",
|
|
103
|
-
"wildcard-match": "5.1.
|
|
103
|
+
"wildcard-match": "5.1.4",
|
|
104
104
|
"yargs-parser": "21.1.1"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@eslint/compat": "1.2.
|
|
108
|
-
"@eslint/eslintrc": "3.
|
|
109
|
-
"@eslint/js": "9.
|
|
107
|
+
"@eslint/compat": "1.2.4",
|
|
108
|
+
"@eslint/eslintrc": "3.2.0",
|
|
109
|
+
"@eslint/js": "9.17.0",
|
|
110
110
|
"@octokit/request-error": "5.1.0",
|
|
111
111
|
"@types/node": "20.14.10",
|
|
112
|
-
"ava": "6.
|
|
113
|
-
"eslint": "9.
|
|
112
|
+
"ava": "6.2.0",
|
|
113
|
+
"eslint": "9.17.0",
|
|
114
114
|
"eslint-config-prettier": "9.1.0",
|
|
115
115
|
"eslint-plugin-ava": "15.0.1",
|
|
116
|
-
"eslint-plugin-import-x": "4.
|
|
116
|
+
"eslint-plugin-import-x": "4.6.1",
|
|
117
117
|
"eslint-plugin-prettier": "5.2.1",
|
|
118
118
|
"fs-monkey": "1.0.6",
|
|
119
|
-
"globals": "15.
|
|
119
|
+
"globals": "15.14.0",
|
|
120
120
|
"installed-check": "9.3.0",
|
|
121
|
-
"knip": "5.
|
|
122
|
-
"memfs": "4.
|
|
121
|
+
"knip": "5.41.1",
|
|
122
|
+
"memfs": "4.15.1",
|
|
123
123
|
"mock-stdio": "1.0.3",
|
|
124
124
|
"nock": "14.0.0-beta.8",
|
|
125
|
-
"prettier": "3.
|
|
125
|
+
"prettier": "3.4.2",
|
|
126
126
|
"remark-cli": "12.0.1",
|
|
127
127
|
"remark-preset-webpro": "1.1.1",
|
|
128
128
|
"sinon": "19.0.2",
|
|
129
129
|
"strip-ansi": "7.1.0",
|
|
130
|
-
"typescript": "5.
|
|
130
|
+
"typescript": "5.7.2"
|
|
131
131
|
},
|
|
132
132
|
"overrides": {
|
|
133
133
|
"pac-resolver": "7.0.1",
|
package/schema/gitlab.json
CHANGED
|
@@ -56,6 +56,14 @@
|
|
|
56
56
|
"type": "boolean",
|
|
57
57
|
"default": false
|
|
58
58
|
},
|
|
59
|
+
"useGenericPackageRepositoryForAssets": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"default": false
|
|
62
|
+
},
|
|
63
|
+
"genericPackageRepositoryName": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"default": "release-it"
|
|
66
|
+
},
|
|
59
67
|
"origin": {
|
|
60
68
|
"type": "string",
|
|
61
69
|
"default": null
|
package/test/gitlab.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
interceptCollaborator,
|
|
11
11
|
interceptPublish,
|
|
12
12
|
interceptAsset,
|
|
13
|
+
interceptAssetGeneric,
|
|
13
14
|
interceptMilestones
|
|
14
15
|
} from './stub/gitlab.js';
|
|
15
16
|
|
|
@@ -114,7 +115,7 @@ test.serial('should upload assets and release', async t => {
|
|
|
114
115
|
t.is(gitlab.assets[0].url, `${pushRepo}/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/file-v2.0.1.txt`);
|
|
115
116
|
const { isReleased, releaseUrl } = gitlab.getContext();
|
|
116
117
|
t.true(isReleased);
|
|
117
|
-
t.is(releaseUrl, `${pushRepo}/-/releases`);
|
|
118
|
+
t.is(releaseUrl, `${pushRepo}/-/releases/2.0.1`);
|
|
118
119
|
});
|
|
119
120
|
|
|
120
121
|
test.serial('should upload assets with ID-based URLs too', async t => {
|
|
@@ -142,6 +143,32 @@ test.serial('should upload assets with ID-based URLs too', async t => {
|
|
|
142
143
|
t.is(gitlab.assets[0].url, `${host}/-/project/1234/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/file-v2.0.1.txt`);
|
|
143
144
|
});
|
|
144
145
|
|
|
146
|
+
test.serial('should upload assets to generic repo', async t => {
|
|
147
|
+
const host = 'https://gitlab.com';
|
|
148
|
+
const pushRepo = `${host}/user/repo`;
|
|
149
|
+
const options = {
|
|
150
|
+
git: { pushRepo },
|
|
151
|
+
gitlab: {
|
|
152
|
+
tokenRef,
|
|
153
|
+
release: true,
|
|
154
|
+
assets: 'test/resources/file-v${version}.txt',
|
|
155
|
+
useGenericPackageRepositoryForAssets: true,
|
|
156
|
+
genericPackageRepositoryName: 'release-it'
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const gitlab = factory(GitLab, { options });
|
|
160
|
+
sinon.stub(gitlab, 'getLatestVersion').resolves('2.0.0');
|
|
161
|
+
|
|
162
|
+
interceptUser();
|
|
163
|
+
interceptCollaborator();
|
|
164
|
+
interceptAssetGeneric();
|
|
165
|
+
interceptPublish();
|
|
166
|
+
|
|
167
|
+
await runTasks(gitlab);
|
|
168
|
+
|
|
169
|
+
t.is(gitlab.assets[0].url, `${host}/api/v4/projects/user%2Frepo/packages/generic/release-it/2.0.1/file-v2.0.1.txt`);
|
|
170
|
+
});
|
|
171
|
+
|
|
145
172
|
test.serial('should throw when release milestone is missing', async t => {
|
|
146
173
|
const pushRepo = 'https://gitlab.com/user/repo';
|
|
147
174
|
const options = {
|
|
@@ -211,7 +238,7 @@ test.serial('should release to sub-grouped repo', async t => {
|
|
|
211
238
|
|
|
212
239
|
const { isReleased, releaseUrl } = gitlab.getContext();
|
|
213
240
|
t.true(isReleased);
|
|
214
|
-
t.
|
|
241
|
+
t.regex(releaseUrl, /https:\/\/gitlab.com\/group\/sub-group\/repo\/-\/releases\//);
|
|
215
242
|
});
|
|
216
243
|
|
|
217
244
|
test.serial('should throw for unauthenticated user', async t => {
|
|
@@ -265,7 +292,7 @@ test('should not make requests in dry run', async t => {
|
|
|
265
292
|
t.is(gitlab.log.exec.args[2][0], 'gitlab releases#uploadAssets');
|
|
266
293
|
t.is(gitlab.log.exec.args[3][0], 'gitlab releases#createRelease "R" (1.0.1)');
|
|
267
294
|
t.true(isReleased);
|
|
268
|
-
t.is(releaseUrl, `${pushRepo}/-/releases`);
|
|
295
|
+
t.is(releaseUrl, `${pushRepo}/-/releases/1.0.1`);
|
|
269
296
|
});
|
|
270
297
|
|
|
271
298
|
test('should skip checks', async t => {
|
package/test/stub/gitlab.js
CHANGED
|
@@ -12,7 +12,13 @@ export let interceptCollaborator = (
|
|
|
12
12
|
.reply(200, { id: userId, username: owner, access_level: 30 });
|
|
13
13
|
|
|
14
14
|
export let interceptPublish = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', body } = {}, options) =>
|
|
15
|
-
nock(host, options)
|
|
15
|
+
nock(host, options)
|
|
16
|
+
.post(`/api/v4/projects/${owner}%2F${project}/releases`, body)
|
|
17
|
+
.reply(200, {
|
|
18
|
+
_links: {
|
|
19
|
+
self: `https://gitlab.com/${owner}/${project}/-/releases/${body?.tag_name ?? '1.0.0'}`
|
|
20
|
+
}
|
|
21
|
+
});
|
|
16
22
|
|
|
17
23
|
export let interceptMilestones = (
|
|
18
24
|
{ host = 'https://gitlab.com', owner = 'user', project = 'repo', query = {}, milestones = [] } = {},
|
|
@@ -34,12 +40,24 @@ export let interceptAsset = ({ host = 'https://gitlab.com', owner = 'user', proj
|
|
|
34
40
|
nock(host)
|
|
35
41
|
.post(`/api/v4/projects/${owner}%2F${project}/uploads`)
|
|
36
42
|
.query(true)
|
|
37
|
-
.reply(200,
|
|
43
|
+
.reply(200, (_, requestBody) => {
|
|
38
44
|
const [, name] = requestBody.match(/filename="([^"]+)/);
|
|
39
45
|
return {
|
|
40
46
|
alt: name,
|
|
41
47
|
url: `/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name}`,
|
|
42
48
|
full_path: `/-/project/1234/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name}`,
|
|
43
|
-
markdown: `[${name}](/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name})
|
|
49
|
+
markdown: `[${name}](/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name})`,
|
|
50
|
+
_links: {
|
|
51
|
+
self: `https://gitlab.com/${owner}/${project}/-/releases/${name}`
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export let interceptAssetGeneric = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo' } = {}) =>
|
|
57
|
+
nock(host)
|
|
58
|
+
.put(`/api/v4/projects/${owner}%2F${project}/packages/generic/release-it/2.0.1/file-v2.0.1.txt`)
|
|
59
|
+
.reply(200, () => {
|
|
60
|
+
return {
|
|
61
|
+
message: '201 Created'
|
|
44
62
|
};
|
|
45
63
|
});
|
package/test/tasks.js
CHANGED
|
@@ -339,7 +339,7 @@ test.serial('should release all the things (pre-release, github, gitlab)', async
|
|
|
339
339
|
t.true(log.obtrusive.firstCall.args[0].endsWith(`release ${pkgName} (1.0.0...1.1.0-alpha.0)`));
|
|
340
340
|
t.true(log.log.firstCall.args[0].endsWith(`https://www.npmjs.com/package/${pkgName}`));
|
|
341
341
|
t.true(log.log.secondCall.args[0].endsWith(`https://github.com/${owner}/${project}/releases/tag/v1.1.0-alpha.0`));
|
|
342
|
-
t.true(log.log.thirdCall.args[0].endsWith(`${project}/-/releases`));
|
|
342
|
+
t.true(log.log.thirdCall.args[0].endsWith(`${project}/-/releases/v1.1.0-alpha.0`));
|
|
343
343
|
t.regex(log.log.lastCall.args[0], /Done \(in [0-9]+s\.\)/);
|
|
344
344
|
|
|
345
345
|
exec.restore();
|
package/types/config.d.ts
CHANGED
|
@@ -190,6 +190,12 @@ export interface Config {
|
|
|
190
190
|
/** @default false */
|
|
191
191
|
useIdsForUrls?: boolean;
|
|
192
192
|
|
|
193
|
+
/** @default false */
|
|
194
|
+
useGenericPackageRepositoryForAssets?: boolean;
|
|
195
|
+
|
|
196
|
+
/** @default "release-it" */
|
|
197
|
+
genericPackageRepositoryName?: string;
|
|
198
|
+
|
|
193
199
|
/** @default null */
|
|
194
200
|
origin?: any;
|
|
195
201
|
|