Skip to content

Commit ef4d728

Browse files
chingor13Benjamin E. Coe
andauthored
feat: add maven-workspace plugin (#1446)
feat: PomXml updater can update dependency versions Co-authored-by: Benjamin E. Coe <bencoe@google.com>
1 parent c2cfc02 commit ef4d728

16 files changed

Lines changed: 1055 additions & 107 deletions

File tree

__snapshots__/maven-workspace.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
exports['MavenWorkspace plugin run appends to existing candidate 1'] = `
2+
:robot: I have created a release *beep* *boop*
3+
---
4+
5+
6+
<details><summary>maven3: 3.3.4</summary>
7+
8+
Release notes for path: maven3, releaseType: maven
9+
</details>
10+
11+
<details><summary>maven4: 4.4.5</summary>
12+
13+
### Dependencies
14+
15+
* Updated foo to v3
16+
* The following workspace dependencies were updated
17+
* com.google.example:maven3 bumped to 3.3.4
18+
</details>
19+
20+
---
21+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
22+
`
23+
24+
exports['MavenWorkspace plugin run handles a single maven package 1'] = `
25+
:robot: I have created a release *beep* *boop*
26+
---
27+
28+
29+
<details><summary>maven4: 4.4.5</summary>
30+
31+
Release notes for path: maven4, releaseType: maven
32+
</details>
33+
34+
---
35+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
36+
`
37+
38+
exports['MavenWorkspace plugin run skips pom files not configured for release 1'] = `
39+
:robot: I have created a release *beep* *boop*
40+
---
41+
42+
43+
<details><summary>maven1: 1.1.2</summary>
44+
45+
Release notes for path: maven1, releaseType: maven
46+
</details>
47+
48+
<details><summary>com.google.example:maven2: 2.2.3</summary>
49+
50+
### Dependencies
51+
52+
* The following workspace dependencies were updated
53+
* com.google.example:maven1 bumped to 1.1.2
54+
</details>
55+
56+
<details><summary>com.google.example:maven3: 3.3.4</summary>
57+
58+
### Dependencies
59+
60+
* The following workspace dependencies were updated
61+
* com.google.example:maven2 bumped to 2.2.3
62+
</details>
63+
64+
<details><summary>com.google.example:maven4: 4.4.5</summary>
65+
66+
### Dependencies
67+
68+
* The following workspace dependencies were updated
69+
* com.google.example:maven3 bumped to 3.3.4
70+
</details>
71+
72+
---
73+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
74+
`
75+
76+
exports['MavenWorkspace plugin run walks dependency tree and updates previously untouched packages 1'] = `
77+
:robot: I have created a release *beep* *boop*
78+
---
79+
80+
81+
<details><summary>maven1: 1.1.2</summary>
82+
83+
Release notes for path: maven1, releaseType: maven
84+
</details>
85+
86+
<details><summary>com.google.example:maven2: 2.2.3</summary>
87+
88+
### Dependencies
89+
90+
* The following workspace dependencies were updated
91+
* com.google.example:maven1 bumped to 1.1.2
92+
</details>
93+
94+
<details><summary>com.google.example:maven3: 3.3.4</summary>
95+
96+
### Dependencies
97+
98+
* The following workspace dependencies were updated
99+
* com.google.example:maven2 bumped to 2.2.3
100+
</details>
101+
102+
<details><summary>com.google.example:maven4: 4.4.5</summary>
103+
104+
### Dependencies
105+
106+
* The following workspace dependencies were updated
107+
* com.google.example:maven3 bumped to 3.3.4
108+
</details>
109+
110+
---
111+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
112+
`

__snapshots__/pom-xml.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1+
exports['PomXml updateContent updates dependencies 1'] = `
2+
<?xml version="1.0" encoding="UTF-8"?>
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.google.auth</groupId>
7+
<artifactId>google-auth-library-appengine</artifactId>
8+
<version>2.3.4</version><!-- {x-version-update:google-auth-library-parent:current} -->
9+
<name>Google Auth Library for Java - Google App Engine</name>
10+
11+
<distributionManagement>
12+
<snapshotRepository>
13+
<id>ossrh</id>
14+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
15+
</snapshotRepository>
16+
</distributionManagement>
17+
18+
<dependencyManagement>
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.google.http-client</groupId>
22+
<artifactId>google-http-client-jackson2</artifactId>
23+
<version>1.2.3</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.guava</groupId>
27+
<artifactId>guava</artifactId>
28+
<version>1.2.4</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.google.http-client</groupId>
32+
<artifactId>artifact4</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
</dependencyManagement>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>com.google.auth</groupId>
41+
<artifactId>google-auth-library-credentials</artifactId>
42+
<version>2.1.3</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.google.auth</groupId>
46+
<artifactId>google-auth-library-oauth2-http</artifactId>
47+
<version>1.2.3</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.google.http-client</groupId>
51+
<artifactId>google-http-client</artifactId>
52+
</dependency>
53+
</dependencies>
54+
</project>
55+
`
56+
157
exports['PomXml updateContent updates project.parent.version 1'] = `
258
<?xml version="1.0" encoding="UTF-8"?>
359
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

docs/manifest-releaser.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,10 @@ with the manifest releaser (`manifest-pr` / `manifest-release` commands), it
470470
does _not_ update the dependencies, and the `cargo-workspace` plug-in must be
471471
used to update dependencies and bump all dependents — this is the recommended
472472
way of managing a Rust monorepo with release-please.
473+
474+
### maven-workspace
475+
476+
The `maven-workspace` plugin operates similarly to the `node-workspace` plugin,
477+
but on a multi-artifact Maven workspace. It builds a dependency graph of all
478+
discovered `pom.xml` files that are configured in the manifest config and updates
479+
any packages that were directly bumped by release-please.

src/factories/plugin-factory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {LinkedVersions} from '../plugins/linked-versions';
2323
import {CargoWorkspace} from '../plugins/cargo-workspace';
2424
import {NodeWorkspace} from '../plugins/node-workspace';
2525
import {VersioningStrategyType} from './versioning-strategy-factory';
26+
import {MavenWorkspace} from '../plugins/maven-workspace';
2627

2728
export interface PluginFactoryOptions {
2829
type: PluginType;
@@ -63,6 +64,13 @@ const pluginFactories: Record<string, PluginBuilder> = {
6364
options.repositoryConfig,
6465
options
6566
),
67+
'maven-workspace': options =>
68+
new MavenWorkspace(
69+
options.github,
70+
options.targetBranch,
71+
options.repositoryConfig,
72+
options
73+
),
6674
};
6775

6876
export function buildPlugin(options: PluginFactoryOptions): ManifestPlugin {

src/plugins/cargo-workspace.ts

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414

1515
import {CandidateReleasePullRequest, ROOT_PROJECT_PATH} from '../manifest';
1616
import {logger} from '../util/logger';
17-
import {WorkspacePlugin, DependencyGraph, DependencyNode} from './workspace';
17+
import {
18+
WorkspacePlugin,
19+
DependencyGraph,
20+
DependencyNode,
21+
addPath,
22+
appendDependenciesSectionToChangelog,
23+
} from './workspace';
1824
import {
1925
CargoManifest,
2026
parseCargoManifest,
@@ -382,51 +388,3 @@ function getChangelogDepsNotes(
382388
}
383389
return '';
384390
}
385-
386-
const DEPENDENCY_HEADER = new RegExp('### Dependencies');
387-
function appendDependenciesSectionToChangelog(
388-
changelog: string,
389-
notes: string
390-
): string {
391-
if (!changelog) {
392-
return `### Dependencies\n\n${notes}`;
393-
}
394-
395-
const newLines: string[] = [];
396-
let seenDependenciesSection = false;
397-
let seenDependencySectionSpacer = false;
398-
let injected = false;
399-
for (const line of changelog.split('\n')) {
400-
if (seenDependenciesSection) {
401-
const trimmedLine = line.trim();
402-
if (
403-
seenDependencySectionSpacer &&
404-
!injected &&
405-
!trimmedLine.startsWith('*')
406-
) {
407-
newLines.push(changelog);
408-
injected = true;
409-
}
410-
if (trimmedLine === '') {
411-
seenDependencySectionSpacer = true;
412-
}
413-
}
414-
if (line.match(DEPENDENCY_HEADER)) {
415-
seenDependenciesSection = true;
416-
}
417-
newLines.push(line);
418-
}
419-
420-
if (injected) {
421-
return newLines.join('\n');
422-
}
423-
if (seenDependenciesSection) {
424-
return `${changelog}\n${notes}`;
425-
}
426-
427-
return `${changelog}\n\n\n### Dependencies\n\n${notes}`;
428-
}
429-
430-
function addPath(path: string, file: string): string {
431-
return path === ROOT_PROJECT_PATH ? file : `${path}/${file}`;
432-
}

0 commit comments

Comments
 (0)