release-please 13.0.2 → 13.1.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
+ ## [13.1.0](https://www.github.com/googleapis/release-please/compare/v13.0.2...v13.1.0) (2021-12-29)
8
+
9
+
10
+ ### Features
11
+
12
+ * introduce generic updater ([#1157](https://www.github.com/googleapis/release-please/issues/1157)) ([c97598c](https://www.github.com/googleapis/release-please/commit/c97598c137b5018c76f5d62137e277b991f4bfa3)), closes [#435](https://www.github.com/googleapis/release-please/issues/435) [#305](https://www.github.com/googleapis/release-please/issues/305) [#1139](https://www.github.com/googleapis/release-please/issues/1139) [#1174](https://www.github.com/googleapis/release-please/issues/1174)
13
+
7
14
  ### [13.0.2](https://www.github.com/googleapis/release-please/compare/v13.0.1...v13.0.2) (2021-12-29)
8
15
 
9
16
 
@@ -68,6 +68,7 @@ const allReleaseTypes = [
68
68
  const releasers = {
69
69
  go: options => new go_1.Go(options),
70
70
  'go-yoshi': options => new go_yoshi_1.GoYoshi(options),
71
+ 'java-yoshi': options => new java_yoshi_1.JavaYoshi(options),
71
72
  'krm-blueprint': options => new krm_blueprint_1.KRMBlueprint(options),
72
73
  node: options => new node_1.Node(options),
73
74
  ocaml: options => new ocaml_1.OCaml(options),
@@ -122,6 +123,7 @@ async function buildStrategy(options) {
122
123
  includeComponentInTag: options.includeComponentInTag,
123
124
  changelogNotes,
124
125
  pullRequestTitlePattern: options.pullRequestTitlePattern,
126
+ extraFiles: options.extraFiles,
125
127
  };
126
128
  switch (options.releaseType) {
127
129
  case 'ruby': {
@@ -136,23 +138,15 @@ async function buildStrategy(options) {
136
138
  versionFile: options.versionFile,
137
139
  });
138
140
  }
139
- case 'java-yoshi': {
140
- return new java_yoshi_1.JavaYoshi({
141
- ...strategyOptions,
142
- extraFiles: options.extraFiles,
143
- });
144
- }
145
141
  case 'java-backport': {
146
142
  return new java_yoshi_1.JavaYoshi({
147
143
  ...strategyOptions,
148
- extraFiles: options.extraFiles,
149
144
  versioningStrategy: new always_bump_patch_1.AlwaysBumpPatch(),
150
145
  });
151
146
  }
152
147
  case 'java-bom': {
153
148
  return new java_yoshi_1.JavaYoshi({
154
149
  ...strategyOptions,
155
- extraFiles: options.extraFiles,
156
150
  versioningStrategy: new dependency_manifest_1.DependencyManifest({
157
151
  bumpMinorPreMajor: options.bumpMinorPreMajor,
158
152
  bumpPatchForMinorPreMajor: options.bumpPatchForMinorPreMajor,
@@ -162,7 +156,6 @@ async function buildStrategy(options) {
162
156
  case 'java-lts': {
163
157
  return new java_yoshi_1.JavaYoshi({
164
158
  ...strategyOptions,
165
- extraFiles: options.extraFiles,
166
159
  versioningStrategy: new service_pack_1.ServicePackVersioningStrategy(),
167
160
  });
168
161
  }
@@ -31,36 +31,18 @@ class Merge extends plugin_1.ManifestPlugin {
31
31
  if (candidates.length < 1) {
32
32
  return candidates;
33
33
  }
34
- const updatesByPath = {};
35
34
  const releaseData = [];
36
35
  const labels = new Set();
36
+ let rawUpdates = [];
37
37
  for (const candidate of candidates) {
38
38
  const pullRequest = candidate.pullRequest;
39
- for (const update of pullRequest.updates) {
40
- if (updatesByPath[update.path]) {
41
- updatesByPath[update.path].push(update);
42
- }
43
- else {
44
- updatesByPath[update.path] = [update];
45
- }
46
- }
39
+ rawUpdates = rawUpdates.concat(...pullRequest.updates);
47
40
  for (const label of pullRequest.labels) {
48
41
  labels.add(label);
49
42
  }
50
43
  releaseData.push(...pullRequest.body.releaseData);
51
44
  }
52
- const updates = [];
53
- for (const path in updatesByPath) {
54
- const update = updatesByPath[path];
55
- const updaters = update.map(u => u.updater);
56
- updates.push({
57
- path,
58
- createIfMissing: update[0].createIfMissing,
59
- updater: updaters.length === 1
60
- ? updaters[0]
61
- : new composite_1.CompositeUpdater(...updaters),
62
- });
63
- }
45
+ const updates = composite_1.mergeUpdates(rawUpdates);
64
46
  const pullRequest = {
65
47
  title: pull_request_title_1.PullRequestTitle.ofTargetBranch(this.targetBranch, manifest_1.MANIFEST_PULL_REQUEST_TITLE_PATTERN),
66
48
  body: new pull_request_body_1.PullRequestBody(releaseData),
@@ -36,6 +36,7 @@ export interface BaseStrategyOptions {
36
36
  changelogNotes?: ChangelogNotes;
37
37
  includeComponentInTag?: boolean;
38
38
  pullRequestTitlePattern?: string;
39
+ extraFiles?: string[];
39
40
  }
40
41
  /**
41
42
  * A strategy is responsible for determining which files are
@@ -55,6 +56,7 @@ export declare abstract class BaseStrategy implements Strategy {
55
56
  private releaseAs?;
56
57
  private includeComponentInTag;
57
58
  private pullRequestTitlePattern?;
59
+ readonly extraFiles: string[];
58
60
  readonly changelogNotes: ChangelogNotes;
59
61
  protected changelogSections?: ChangelogSection[];
60
62
  constructor(options: BaseStrategyOptions);
@@ -90,6 +92,7 @@ export declare abstract class BaseStrategy implements Strategy {
90
92
  * open a pull request.
91
93
  */
92
94
  buildReleasePullRequest(commits: Commit[], latestRelease?: Release, draft?: boolean, labels?: string[]): Promise<ReleasePullRequest | undefined>;
95
+ private extraFileUpdates;
93
96
  protected changelogEmpty(changelogEntry: string): boolean;
94
97
  protected updateVersionsMap(versionsMap: VersionsMap, conventionalCommits: ConventionalCommit[]): Promise<VersionsMap>;
95
98
  protected buildNewVersion(conventionalCommits: ConventionalCommit[], latestRelease?: Release): Promise<Version>;
@@ -24,6 +24,8 @@ const logger_1 = require("../util/logger");
24
24
  const pull_request_title_1 = require("../util/pull-request-title");
25
25
  const branch_name_1 = require("../util/branch-name");
26
26
  const pull_request_body_1 = require("../util/pull-request-body");
27
+ const composite_1 = require("../updaters/composite");
28
+ const generic_1 = require("../updaters/generic");
27
29
  const DEFAULT_CHANGELOG_PATH = 'CHANGELOG.md';
28
30
  /**
29
31
  * A strategy is responsible for determining which files are
@@ -50,6 +52,7 @@ class BaseStrategy {
50
52
  options.changelogNotes || new default_2.DefaultChangelogNotes(options);
51
53
  this.includeComponentInTag = (_a = options.includeComponentInTag) !== null && _a !== void 0 ? _a : true;
52
54
  this.pullRequestTitlePattern = options.pullRequestTitlePattern;
55
+ this.extraFiles = options.extraFiles || [];
53
56
  }
54
57
  /**
55
58
  * Return the component for this strategy. This may be a computed field.
@@ -127,6 +130,7 @@ class BaseStrategy {
127
130
  versionsMap,
128
131
  latestVersion: latestRelease === null || latestRelease === void 0 ? void 0 : latestRelease.tag.version,
129
132
  });
133
+ const updatesWithExtras = composite_1.mergeUpdates(updates.concat(...this.extraFileUpdates(newVersion)));
130
134
  const pullRequestBody = new pull_request_body_1.PullRequestBody([
131
135
  {
132
136
  component,
@@ -137,13 +141,23 @@ class BaseStrategy {
137
141
  return {
138
142
  title: pullRequestTitle,
139
143
  body: pullRequestBody,
140
- updates,
144
+ updates: updatesWithExtras,
141
145
  labels,
142
146
  headRefName: branchName.toString(),
143
147
  version: newVersion,
144
148
  draft: draft !== null && draft !== void 0 ? draft : false,
145
149
  };
146
150
  }
151
+ extraFileUpdates(version) {
152
+ const genericUpdater = new generic_1.Generic({ version });
153
+ return this.extraFiles.map(path => {
154
+ return {
155
+ path,
156
+ createIfMissing: false,
157
+ updater: genericUpdater,
158
+ };
159
+ });
160
+ }
147
161
  changelogEmpty(changelogEntry) {
148
162
  return changelogEntry.split('\n').length <= 1;
149
163
  }
@@ -5,14 +5,10 @@ import { GitHubFileContents } from '../github';
5
5
  import { Commit, ConventionalCommit } from '../commit';
6
6
  import { Release } from '../release';
7
7
  import { ReleasePullRequest } from '../release-pull-request';
8
- interface JavaStrategyOptions extends BaseStrategyOptions {
9
- extraFiles?: string[];
10
- }
11
8
  export declare class JavaYoshi extends BaseStrategy {
12
- readonly extraFiles: string[];
13
9
  private versionsContent?;
14
10
  private snapshotVersioning;
15
- constructor(options: JavaStrategyOptions);
11
+ constructor(options: BaseStrategyOptions);
16
12
  buildReleasePullRequest(commits: Commit[], latestRelease?: Release, draft?: boolean, labels?: string[]): Promise<ReleasePullRequest | undefined>;
17
13
  private buildSnapshotPullRequest;
18
14
  private needsSnapshot;
@@ -22,4 +18,3 @@ export declare class JavaYoshi extends BaseStrategy {
22
18
  protected updateVersionsMap(versionsMap: VersionsMap, conventionalCommits: ConventionalCommit[]): Promise<VersionsMap>;
23
19
  protected initialReleaseVersion(): Version;
24
20
  }
25
- export {};
@@ -49,7 +49,6 @@ class JavaYoshi extends base_1.BaseStrategy {
49
49
  const parentVersioningStrategy = options.versioningStrategy || new default_1.DefaultVersioningStrategy();
50
50
  options.versioningStrategy = new java_snapshot_1.JavaSnapshot(parentVersioningStrategy);
51
51
  super(options);
52
- this.extraFiles = options.extraFiles || [];
53
52
  this.snapshotVersioning = new java_add_snapshot_1.JavaAddSnapshot(parentVersioningStrategy);
54
53
  }
55
54
  async buildReleasePullRequest(commits, latestRelease, draft, labels = []) {
@@ -1,10 +1,10 @@
1
- import { Updater } from '../update';
1
+ import { Updater, Update } from '../update';
2
2
  /**
3
3
  * The CompositeUpdater chains 0...n updaters and updates
4
4
  * the content in order.
5
5
  */
6
6
  export declare class CompositeUpdater implements Updater {
7
- updaters: Updater[];
7
+ readonly updaters: Updater[];
8
8
  /**
9
9
  * Instantiate a new CompositeUpdater
10
10
  * @param {Updater[]} updaters The updaters to chain together
@@ -17,3 +17,4 @@ export declare class CompositeUpdater implements Updater {
17
17
  */
18
18
  updateContent(content: string | undefined): string;
19
19
  }
20
+ export declare function mergeUpdates(updates: Update[]): Update[];
@@ -13,7 +13,7 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.CompositeUpdater = void 0;
16
+ exports.mergeUpdates = exports.CompositeUpdater = void 0;
17
17
  /**
18
18
  * The CompositeUpdater chains 0...n updaters and updates
19
19
  * the content in order.
@@ -39,4 +39,27 @@ class CompositeUpdater {
39
39
  }
40
40
  }
41
41
  exports.CompositeUpdater = CompositeUpdater;
42
+ function mergeUpdates(updates) {
43
+ const updatesByPath = {};
44
+ for (const update of updates) {
45
+ if (updatesByPath[update.path]) {
46
+ updatesByPath[update.path].push(update);
47
+ }
48
+ else {
49
+ updatesByPath[update.path] = [update];
50
+ }
51
+ }
52
+ const newUpdates = [];
53
+ for (const path in updatesByPath) {
54
+ const update = updatesByPath[path];
55
+ const updaters = update.map(u => u.updater);
56
+ newUpdates.push({
57
+ path,
58
+ createIfMissing: update[0].createIfMissing,
59
+ updater: updaters.length === 1 ? updaters[0] : new CompositeUpdater(...updaters),
60
+ });
61
+ }
62
+ return newUpdates;
63
+ }
64
+ exports.mergeUpdates = mergeUpdates;
42
65
  //# sourceMappingURL=composite.js.map
@@ -0,0 +1,32 @@
1
+ import { DefaultUpdater } from './default';
2
+ /**
3
+ * The Generic updater looks for well known patterns and replaces
4
+ * content. The well known patterns are:
5
+ *
6
+ * 1. `x-release-please-version` if this string is found on the line,
7
+ * then replace a semver-looking string on that line with the next
8
+ * version
9
+ * 2. `x-release-please-major` if this string is found on the line,
10
+ * then replace an integer looking value with the the next version's
11
+ * major
12
+ * 3. `x-release-please-minor` if this string is found on the line,
13
+ * then replace an integer looking value with the the next version's
14
+ * minor
15
+ * 4. `x-release-please-patch` if this string is found on the line,
16
+ * then replace an integer looking value with the the next version's
17
+ * patch
18
+ *
19
+ * You can also use a block-based replacement. Content between the
20
+ * opening `x-release-please-start-version` and `x-release-please-end` will
21
+ * be considered for version replacement. You can also open these blocks
22
+ * with `x-release-please-start-<major|minor|patch>` to replace single
23
+ * numbers
24
+ */
25
+ export declare class Generic extends DefaultUpdater {
26
+ /**
27
+ * Given initial file contents, return updated contents.
28
+ * @param {string} content The initial content
29
+ * @returns {string} The updated content
30
+ */
31
+ updateContent(content: string | undefined): string;
32
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ // Copyright 2021 Google LLC
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Generic = void 0;
17
+ const default_1 = require("./default");
18
+ const logger_1 = require("../util/logger");
19
+ const VERSION_REGEX = /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-(?<preRelease>[\w.]+))?(\+(?<build>[-\w.]+))?/;
20
+ const SINGLE_VERSION_REGEX = /\b\d+\b/;
21
+ const INLINE_UPDATE_REGEX = /x-release-please-(?<scope>major|minor|patch|version)/;
22
+ const BLOCK_START_REGEX = /x-release-please-start-(?<scope>major|minor|patch|version)/;
23
+ const BLOCK_END_REGEX = /x-release-please-end/;
24
+ /**
25
+ * The Generic updater looks for well known patterns and replaces
26
+ * content. The well known patterns are:
27
+ *
28
+ * 1. `x-release-please-version` if this string is found on the line,
29
+ * then replace a semver-looking string on that line with the next
30
+ * version
31
+ * 2. `x-release-please-major` if this string is found on the line,
32
+ * then replace an integer looking value with the the next version's
33
+ * major
34
+ * 3. `x-release-please-minor` if this string is found on the line,
35
+ * then replace an integer looking value with the the next version's
36
+ * minor
37
+ * 4. `x-release-please-patch` if this string is found on the line,
38
+ * then replace an integer looking value with the the next version's
39
+ * patch
40
+ *
41
+ * You can also use a block-based replacement. Content between the
42
+ * opening `x-release-please-start-version` and `x-release-please-end` will
43
+ * be considered for version replacement. You can also open these blocks
44
+ * with `x-release-please-start-<major|minor|patch>` to replace single
45
+ * numbers
46
+ */
47
+ class Generic extends default_1.DefaultUpdater {
48
+ /**
49
+ * Given initial file contents, return updated contents.
50
+ * @param {string} content The initial content
51
+ * @returns {string} The updated content
52
+ */
53
+ updateContent(content) {
54
+ if (!content) {
55
+ return '';
56
+ }
57
+ const newLines = [];
58
+ let blockScope;
59
+ function replaceVersion(line, scope, version) {
60
+ switch (scope) {
61
+ case 'major':
62
+ newLines.push(line.replace(SINGLE_VERSION_REGEX, `${version.major}`));
63
+ return;
64
+ case 'minor':
65
+ newLines.push(line.replace(SINGLE_VERSION_REGEX, `${version.minor}`));
66
+ return;
67
+ case 'patch':
68
+ newLines.push(line.replace(SINGLE_VERSION_REGEX, `${version.patch}`));
69
+ return;
70
+ case 'version':
71
+ newLines.push(line.replace(VERSION_REGEX, version.toString()));
72
+ return;
73
+ default:
74
+ logger_1.logger.warn(`unknown block scope: ${scope}`);
75
+ newLines.push(line);
76
+ }
77
+ }
78
+ content.split(/\r?\n/).forEach(line => {
79
+ var _a, _b;
80
+ let match = line.match(INLINE_UPDATE_REGEX);
81
+ if (match) {
82
+ // replace inline versions
83
+ replaceVersion(line, (((_a = match.groups) === null || _a === void 0 ? void 0 : _a.scope) || 'version'), this.version);
84
+ }
85
+ else if (blockScope) {
86
+ // in a block, so try to replace versions
87
+ replaceVersion(line, blockScope, this.version);
88
+ if (line.match(BLOCK_END_REGEX)) {
89
+ blockScope = undefined;
90
+ }
91
+ }
92
+ else {
93
+ // look for block start line
94
+ match = line.match(BLOCK_START_REGEX);
95
+ if (match) {
96
+ if ((_b = match.groups) === null || _b === void 0 ? void 0 : _b.scope) {
97
+ blockScope = match.groups.scope;
98
+ }
99
+ else {
100
+ blockScope = 'version';
101
+ }
102
+ }
103
+ newLines.push(line);
104
+ }
105
+ });
106
+ return newLines.join('\n');
107
+ }
108
+ }
109
+ exports.Generic = Generic;
110
+ //# sourceMappingURL=generic.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-please",
3
- "version": "13.0.2",
3
+ "version": "13.1.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",