release-it 17.10.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 +46 -20
- package/package.json +17 -17
- package/schema/gitlab.json +8 -0
- package/test/gitlab.js +27 -0
- package/test/stub/gitlab.js +9 -0
- 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
|
|
|
@@ -165,9 +165,13 @@ class GitLab extends Release {
|
|
|
165
165
|
const url = `${baseUrl}/${endpoint}${options.searchParams ? `?${new URLSearchParams(options.searchParams)}` : ''}`;
|
|
166
166
|
const headers = {
|
|
167
167
|
'user-agent': 'webpro/release-it',
|
|
168
|
-
'Content-Type': typeof options.json !== 'undefined' ? 'application/json' : 'text/plain',
|
|
169
168
|
[tokenHeader]: this.token
|
|
170
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
|
+
}
|
|
171
175
|
const requestOptions = {
|
|
172
176
|
method,
|
|
173
177
|
headers,
|
|
@@ -253,25 +257,47 @@ class GitLab extends Release {
|
|
|
253
257
|
|
|
254
258
|
async uploadAsset(filePath) {
|
|
255
259
|
const name = path.basename(filePath);
|
|
256
|
-
const { useIdsForUrls } = this.options;
|
|
257
|
-
const { id, origin, repo } = this.getContext();
|
|
258
|
-
const endpoint =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
+
}
|
|
275
301
|
}
|
|
276
302
|
}
|
|
277
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
|
|
|
@@ -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 = {
|
package/test/stub/gitlab.js
CHANGED
|
@@ -52,3 +52,12 @@ export let interceptAsset = ({ host = 'https://gitlab.com', owner = 'user', proj
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
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'
|
|
62
|
+
};
|
|
63
|
+
});
|
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
|
|