release-please 14.4.0 → 14.5.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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  [1]: https://www.npmjs.com/package/release-please?activeTab=versions
6
6
 
7
+ ## [14.5.0](https://github.com/googleapis/release-please/compare/v14.4.0...v14.5.0) (2022-09-07)
8
+
9
+
10
+ ### Features
11
+
12
+ * Allow specifying glob option for extra-files ([#1621](https://github.com/googleapis/release-please/issues/1621)) ([d0fbd90](https://github.com/googleapis/release-please/commit/d0fbd90659f14b975ba56570712b8a4b1ed59e25)), closes [#1619](https://github.com/googleapis/release-please/issues/1619)
13
+
7
14
  ## [14.4.0](https://github.com/googleapis/release-please/compare/v14.3.1...v14.4.0) (2022-09-07)
8
15
 
9
16
 
@@ -248,6 +248,30 @@ export declare class GitHub {
248
248
  * @throws {GitHubAPIError} on an API error
249
249
  */
250
250
  findFilesByFilenameAndRef: (filename: string, ref: string, prefix?: string | undefined) => Promise<string[]>;
251
+ /**
252
+ * Returns a list of paths to all files matching a glob pattern.
253
+ *
254
+ * If a prefix is specified, only return paths that match
255
+ * the provided prefix.
256
+ *
257
+ * @param glob The glob to match
258
+ * @param prefix Optional path prefix used to filter results
259
+ * @returns {string[]} List of file paths
260
+ * @throws {GitHubAPIError} on an API error
261
+ */
262
+ findFilesByGlob(glob: string, prefix?: string): Promise<string[]>;
263
+ /**
264
+ * Returns a list of paths to all files matching a glob pattern.
265
+ *
266
+ * If a prefix is specified, only return paths that match
267
+ * the provided prefix.
268
+ *
269
+ * @param glob The glob to match
270
+ * @param ref Git reference to search files in
271
+ * @param prefix Optional path prefix used to filter results
272
+ * @throws {GitHubAPIError} on an API error
273
+ */
274
+ findFilesByGlobAndRef: (glob: string, ref: string, prefix?: string | undefined) => Promise<string[]>;
251
275
  /**
252
276
  * Open a pull request
253
277
  *
@@ -110,6 +110,24 @@ class GitHub {
110
110
  this.logger.debug(`finding files by filename: ${filename}, ref: ${ref}, prefix: ${prefix}`);
111
111
  return await this.fileCache.findFilesByFilename(filename, ref, prefix);
112
112
  });
113
+ /**
114
+ * Returns a list of paths to all files matching a glob pattern.
115
+ *
116
+ * If a prefix is specified, only return paths that match
117
+ * the provided prefix.
118
+ *
119
+ * @param glob The glob to match
120
+ * @param ref Git reference to search files in
121
+ * @param prefix Optional path prefix used to filter results
122
+ * @throws {GitHubAPIError} on an API error
123
+ */
124
+ this.findFilesByGlobAndRef = wrapAsync(async (glob, ref, prefix) => {
125
+ if (prefix) {
126
+ prefix = normalizePrefix(prefix);
127
+ }
128
+ this.logger.debug(`finding files by glob: ${glob}, ref: ${ref}, prefix: ${prefix}`);
129
+ return await this.fileCache.findFilesByGlob(glob, ref, prefix);
130
+ });
113
131
  this.createPullRequest = wrapAsync(async (pullRequest, targetBranch, message, updates, options) => {
114
132
  // Update the files for the release if not already supplied
115
133
  const changes = await this.buildChangeSet(updates, targetBranch);
@@ -903,6 +921,20 @@ class GitHub {
903
921
  async findFilesByFilename(filename, prefix) {
904
922
  return this.findFilesByFilenameAndRef(filename, this.repository.defaultBranch, prefix);
905
923
  }
924
+ /**
925
+ * Returns a list of paths to all files matching a glob pattern.
926
+ *
927
+ * If a prefix is specified, only return paths that match
928
+ * the provided prefix.
929
+ *
930
+ * @param glob The glob to match
931
+ * @param prefix Optional path prefix used to filter results
932
+ * @returns {string[]} List of file paths
933
+ * @throws {GitHubAPIError} on an API error
934
+ */
935
+ async findFilesByGlob(glob, prefix) {
936
+ return this.findFilesByGlobAndRef(glob, this.repository.defaultBranch, prefix);
937
+ }
906
938
  /**
907
939
  * Open a pull request
908
940
  *
@@ -10,20 +10,24 @@ declare type ExtraJsonFile = {
10
10
  type: 'json';
11
11
  path: string;
12
12
  jsonpath: string;
13
+ glob?: boolean;
13
14
  };
14
15
  declare type ExtraYamlFile = {
15
16
  type: 'yaml';
16
17
  path: string;
17
18
  jsonpath: string;
19
+ glob?: boolean;
18
20
  };
19
21
  declare type ExtraXmlFile = {
20
22
  type: 'xml';
21
23
  path: string;
22
24
  xpath: string;
25
+ glob?: boolean;
23
26
  };
24
27
  declare type ExtraPomFile = {
25
28
  type: 'pom';
26
29
  path: string;
30
+ glob?: boolean;
27
31
  };
28
32
  export declare type ExtraFile = string | ExtraJsonFile | ExtraYamlFile | ExtraXmlFile | ExtraPomFile;
29
33
  /**
@@ -109,7 +109,8 @@ export declare abstract class BaseStrategy implements Strategy {
109
109
  * open a pull request.
110
110
  */
111
111
  buildReleasePullRequest(commits: Commit[], latestRelease?: Release, draft?: boolean, labels?: string[]): Promise<ReleasePullRequest | undefined>;
112
- protected extraFileUpdates(version: Version, versionsMap: VersionsMap): Update[];
112
+ private extraFilePaths;
113
+ protected extraFileUpdates(version: Version, versionsMap: VersionsMap): Promise<Update[]>;
113
114
  protected changelogEmpty(changelogEntry: string): boolean;
114
115
  protected updateVersionsMap(versionsMap: VersionsMap, conventionalCommits: ConventionalCommit[], _newVersion: Version): Promise<VersionsMap>;
115
116
  protected buildNewVersion(conventionalCommits: ConventionalCommit[], latestRelease?: Release): Promise<Version>;
@@ -165,7 +165,7 @@ class BaseStrategy {
165
165
  versionsMap,
166
166
  latestVersion: latestRelease === null || latestRelease === void 0 ? void 0 : latestRelease.tag.version,
167
167
  });
168
- const updatesWithExtras = (0, composite_1.mergeUpdates)(updates.concat(...this.extraFileUpdates(newVersion, versionsMap)));
168
+ const updatesWithExtras = (0, composite_1.mergeUpdates)(updates.concat(...(await this.extraFileUpdates(newVersion, versionsMap))));
169
169
  const pullRequestBody = await this.buildPullRequestBody(component, newVersion, releaseNotesBody, conventionalCommits, latestRelease, this.pullRequestHeader);
170
170
  return {
171
171
  title: pullRequestTitle,
@@ -177,44 +177,77 @@ class BaseStrategy {
177
177
  draft: draft !== null && draft !== void 0 ? draft : false,
178
178
  };
179
179
  }
180
- extraFileUpdates(version, versionsMap) {
181
- return this.extraFiles.map(extraFile => {
180
+ // Helper to convert extra files with globs to the file paths to add
181
+ async extraFilePaths(extraFile) {
182
+ if (typeof extraFile !== 'object') {
183
+ return [extraFile];
184
+ }
185
+ if (!extraFile.glob) {
186
+ return [extraFile.path];
187
+ }
188
+ if (extraFile.path.startsWith('/')) {
189
+ // glob is relative to root, strip the leading `/` for glob matching
190
+ // and re-add the leading `/` to make the file relative to the root
191
+ return (await this.github.findFilesByGlobAndRef(extraFile.path.slice(1), this.targetBranch)).map(file => `/${file}`);
192
+ }
193
+ else if (this.path === manifest_1.ROOT_PROJECT_PATH) {
194
+ // root component, ignore path prefix
195
+ return this.github.findFilesByGlobAndRef(extraFile.path, this.targetBranch);
196
+ }
197
+ else {
198
+ // glob is relative to current path
199
+ return this.github.findFilesByGlobAndRef(extraFile.path, this.targetBranch, this.path);
200
+ }
201
+ }
202
+ async extraFileUpdates(version, versionsMap) {
203
+ const extraFileUpdates = [];
204
+ for (const extraFile of this.extraFiles) {
182
205
  if (typeof extraFile === 'object') {
183
- switch (extraFile.type) {
184
- case 'json':
185
- return {
186
- path: this.addPath(extraFile.path),
187
- createIfMissing: false,
188
- updater: new generic_json_1.GenericJson(extraFile.jsonpath, version),
189
- };
190
- case 'yaml':
191
- return {
192
- path: this.addPath(extraFile.path),
193
- createIfMissing: false,
194
- updater: new generic_yaml_1.GenericYaml(extraFile.jsonpath, version),
195
- };
196
- case 'xml':
197
- return {
198
- path: this.addPath(extraFile.path),
199
- createIfMissing: false,
200
- updater: new generic_xml_1.GenericXml(extraFile.xpath, version),
201
- };
202
- case 'pom':
203
- return {
204
- path: this.addPath(extraFile.path),
205
- createIfMissing: false,
206
- updater: new pom_xml_1.PomXml(version),
207
- };
208
- default:
209
- throw new Error(`unsupported extraFile type: ${extraFile.type}`);
206
+ const paths = await this.extraFilePaths(extraFile);
207
+ for (const path of paths) {
208
+ switch (extraFile.type) {
209
+ case 'json':
210
+ extraFileUpdates.push({
211
+ path: this.addPath(path),
212
+ createIfMissing: false,
213
+ updater: new generic_json_1.GenericJson(extraFile.jsonpath, version),
214
+ });
215
+ break;
216
+ case 'yaml':
217
+ extraFileUpdates.push({
218
+ path: this.addPath(path),
219
+ createIfMissing: false,
220
+ updater: new generic_yaml_1.GenericYaml(extraFile.jsonpath, version),
221
+ });
222
+ break;
223
+ case 'xml':
224
+ extraFileUpdates.push({
225
+ path: this.addPath(path),
226
+ createIfMissing: false,
227
+ updater: new generic_xml_1.GenericXml(extraFile.xpath, version),
228
+ });
229
+ break;
230
+ case 'pom':
231
+ extraFileUpdates.push({
232
+ path: this.addPath(path),
233
+ createIfMissing: false,
234
+ updater: new pom_xml_1.PomXml(version),
235
+ });
236
+ break;
237
+ default:
238
+ throw new Error(`unsupported extraFile type: ${extraFile.type}`);
239
+ }
210
240
  }
211
241
  }
212
- return {
213
- path: this.addPath(extraFile),
214
- createIfMissing: false,
215
- updater: new generic_1.Generic({ version, versionsMap }),
216
- };
217
- });
242
+ else {
243
+ extraFileUpdates.push({
244
+ path: this.addPath(extraFile),
245
+ createIfMissing: false,
246
+ updater: new generic_1.Generic({ version, versionsMap }),
247
+ });
248
+ }
249
+ }
250
+ return extraFileUpdates;
218
251
  }
219
252
  changelogEmpty(changelogEntry) {
220
253
  return changelogEntry.split('\n').length <= 1;
@@ -94,7 +94,7 @@ class Java extends base_1.BaseStrategy {
94
94
  changelogEntry: notes,
95
95
  isSnapshot: true,
96
96
  });
97
- const updatesWithExtras = (0, composite_1.mergeUpdates)(updates.concat(...this.extraFileUpdates(newVersion, versionsMap)));
97
+ const updatesWithExtras = (0, composite_1.mergeUpdates)(updates.concat(...(await this.extraFileUpdates(newVersion, versionsMap))));
98
98
  return {
99
99
  title: pullRequestTitle,
100
100
  body: pullRequestBody,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-please",
3
- "version": "14.4.0",
3
+ "version": "14.5.0",
4
4
  "description": "generate release PRs based on the conventionalcommits.org spec",
5
5
  "main": "./build/src/index.js",
6
6
  "bin": "./build/src/bin/release-please.js",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "dependencies": {
70
70
  "@conventional-commits/parser": "^0.4.1",
71
- "@google-automations/git-file-utils": "^1.1.0",
71
+ "@google-automations/git-file-utils": "^1.2.0",
72
72
  "@iarna/toml": "^2.2.5",
73
73
  "@lerna/collect-updates": "^4.0.0",
74
74
  "@lerna/package": "^4.0.0",
@@ -132,6 +132,10 @@
132
132
  "description": "The path to the file.",
133
133
  "type": "string"
134
134
  },
135
+ "glob": {
136
+ "description": "Whether to treat the path as a glob. Defaults to `false`.",
137
+ "type": "boolean"
138
+ },
135
139
  "jsonpath": {
136
140
  "description": "The jsonpath to the version entry in the file.",
137
141
  "type": "string"
@@ -151,6 +155,10 @@
151
155
  "description": "The path to the file.",
152
156
  "type": "string"
153
157
  },
158
+ "glob": {
159
+ "description": "Whether to treat the path as a glob. Defaults to `false`.",
160
+ "type": "boolean"
161
+ },
154
162
  "xpath": {
155
163
  "description": "The xpath to the version entry in the file.",
156
164
  "type": "string"
@@ -169,6 +177,10 @@
169
177
  "path": {
170
178
  "description": "The path to the file.",
171
179
  "type": "string"
180
+ },
181
+ "glob": {
182
+ "description": "Whether to treat the path as a glob. Defaults to `false`.",
183
+ "type": "boolean"
172
184
  }
173
185
  },
174
186
  "required": ["type", "path"]