Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plugin for go workspace #2409

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Release Please automates releases for the following flavors of repositories:
| `bazel` | [A Bazel module, with a MODULE.bazel and a CHANGELOG.md](https://bazel.build/external/module) |
| `dart` | A repository with a pubspec.yaml and a CHANGELOG.md |
| `elixir` | A repository with a mix.exs and a CHANGELOG.md |
| `go` | A repository with a CHANGELOG.md |
| `go` | A repository with a CHANGELOG.md or a go.work (note that workspaces require a [manifest driven release](https://github.com/googleapis/release-please/blob/main/docs/manifest-releaser.md) and the "go-workspace" plugin) |
| `helm` | A repository with a Chart.yaml and a CHANGELOG.md |
| `java` | [A strategy that generates SNAPSHOT version after each release](docs/java.md) |
| `krm-blueprint` | [A kpt package, with 1 or more KRM files and a CHANGELOG.md](https://github.com/GoogleCloudPlatform/blueprints/tree/main/catalog/project) |
Expand Down
13 changes: 13 additions & 0 deletions __snapshots__/go-mod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports['go.mod updateContent updates dependencies 1'] = `
module example.com/hello/world

go 1.23.0

replace example.com/foo/bar/v2 => ../../foo/bar

require (
\texample.com/foo/bar/v2 v2.1.3
\texample.com/foo/baz v1.2.3
)

`
160 changes: 160 additions & 0 deletions __snapshots__/go-workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
exports['GoWorkspace plugin run appends dependency notes to an updated module 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>example.com/packages/goA: 1.1.2</summary>

Release notes for path: packages/goA, releaseType: go
</details>

<details><summary>example.com/packages/goB: 2.2.3</summary>

### Dependencies

* update dependency foo/bar to 1.2.3
* The following workspace dependencies were updated
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
</details>

<details><summary>example.com/packages/goC: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goB/v2 bumped from 2.2.2 to 2.2.3
</details>

<details><summary>example.com/packages/goE: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['GoWorkspace plugin run handles a single go package and normalizes path 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>example.com/packages/goA: 1.1.2</summary>

Release notes for path: packages/goA, releaseType: go
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['GoWorkspace plugin run skips component if not touched 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>example.com/packages/goB: 2.3.0</summary>

Release notes for path: packages/goB, releaseType: go
</details>

<details><summary>example.com/packages/goC: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goB/v2 bumped from 2.2.2 to 2.3.0
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['GoWorkspace plugin run uses go-work-file config value 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>example.com/packages/goA: 1.1.2</summary>

Release notes for path: packages/goA, releaseType: go
</details>

<details><summary>example.com/packages/goB/v2: 2.2.3</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
</details>

<details><summary>example.com/packages/goC: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goB/v2 bumped from 2.2.2 to 2.2.3
</details>

<details><summary>example.com/packages/goD: 4.4.5</summary>

Release notes for path: packages/goD, releaseType: go
</details>

<details><summary>example.com/packages/goE: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['GoWorkspace plugin run walks dependency tree and updates previously untouched packages 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>example.com/packages/goA: 1.1.2</summary>

Release notes for path: packages/goA, releaseType: go
</details>

<details><summary>example.com/packages/goB/v2: 2.2.3</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
</details>

<details><summary>example.com/packages/goC: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goB/v2 bumped from 2.2.2 to 2.2.3
</details>

<details><summary>example.com/packages/goD: 4.4.5</summary>

Release notes for path: packages/goD, releaseType: go
</details>

<details><summary>example.com/packages/goE: 3.3.4</summary>

### Dependencies

* The following workspace dependencies were updated
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`
26 changes: 25 additions & 1 deletion docs/manifest-releaser.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ defaults (those are documented in comments)

// see Plugins section below
// absence defaults to [] (i.e. no plugins)
"plugins": ["node-workspace", "cargo-workspace"],
"plugins": ["node-workspace", "cargo-workspace", "go-workspace"],

// optional top-level defaults that can be overridden per package:

Expand Down Expand Up @@ -541,6 +541,30 @@ does _not_ update the dependencies, and the `cargo-workspace` plug-in must be
used to update dependencies and bump all dependents — this is the recommended
way of managing a Rust monorepo with release-please.

### go-workspace

The `go-workspace` plugin operates similarly to the `node-workspace` and
`cargo-workspace` plugins, but on a Go workspace. It builds a dependency graph of
all modules in a workspace and updates any modules that depends
(directly or transitively) on the changed module. The workspace dependencies in
`go.mod` files are updated accordingly.

#### go.work in a non-default location

By default, the `go.work` file is expected to be in the root. Set `"goWorkFile"`
to a custom path to use a file in a different location.

```
{
"plugins": [
{
"type": "go-workspace",
"goWorkFile": "/path/to/filename"
}
]
}
```

### maven-workspace

The `maven-workspace` plugin operates similarly to the `node-workspace` plugin,
Expand Down
7 changes: 6 additions & 1 deletion schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@
"type": "string",
"enum": [
"cargo-workspace",
"maven-workspace"
"maven-workspace",
"go-workspace"
]
},
"updateAllPackages": {
Expand Down Expand Up @@ -370,6 +371,10 @@
"updatePeerDependencies": {
"description": "Also bump peer dependency versions if they are modified. Defaults to `false`.",
"type": "boolean"
},
"goWorkFile": {
"description": "Path to the go.work file. Defaults to `go.work`.",
"type": "string"
}
}
},
Expand Down
17 changes: 17 additions & 0 deletions src/factories/plugin-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {GitHub} from '../github';
import {ManifestPlugin} from '../plugin';
import {LinkedVersions} from '../plugins/linked-versions';
import {CargoWorkspace} from '../plugins/cargo-workspace';
import {GoWorkspace} from '../plugins/go-workspace';
import {NodeWorkspace} from '../plugins/node-workspace';
import {VersioningStrategyType} from './versioning-strategy-factory';
import {MavenWorkspace} from '../plugins/maven-workspace';
Expand All @@ -48,6 +49,9 @@ export interface PluginFactoryOptions {
updateAllPackages?: boolean;
considerAllArtifacts?: boolean;

// go options
goWorkFile?: string;

logger?: Logger;
}

Expand Down Expand Up @@ -81,6 +85,19 @@ const pluginFactories: Record<string, PluginBuilder> = {
!options.separatePullRequests,
}
),
'go-workspace': options =>
new GoWorkspace(
options.github,
options.targetBranch,
options.repositoryConfig,
{
...options,
...(options.type as WorkspacePluginOptions),
merge:
(options.type as WorkspacePluginOptions).merge ??
!options.separatePullRequests,
}
),
'node-workspace': options =>
new NodeWorkspace(
options.github,
Expand Down
8 changes: 7 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export interface WorkspacePluginConfig extends ConfigurablePluginType {
export interface NodeWorkspacePluginConfig extends WorkspacePluginConfig {
updatePeerDependencies?: boolean;
}
export interface GoWorkspacePluginConfig extends WorkspacePluginConfig {
goWorkFile?: string;
}
export interface GroupPriorityPluginConfig extends ConfigurablePluginType {
groups: string[];
}
Expand All @@ -245,7 +248,8 @@ export type PluginType =
| LinkedVersionPluginConfig
| SentenceCasePluginConfig
| WorkspacePluginConfig
| NodeWorkspacePluginConfig;
| NodeWorkspacePluginConfig
| GoWorkspacePluginConfig;

/**
* This is the schema of the manifest config json
Expand Down Expand Up @@ -335,6 +339,7 @@ export class Manifest {
* plugin
* @param {boolean} manifestOptions.updatePeerDependencies Option for the node-workspace
* plugin
* @param {string} manifestOptions.goWorkFile Option for the go-workspace plugin
* @param {boolean} manifestOptions.separatePullRequests If true, create separate pull
* requests instead of a single manifest release pull request
* @param {boolean} manifestOptions.alwaysUpdate If true, always updates pull requests instead of
Expand Down Expand Up @@ -456,6 +461,7 @@ export class Manifest {
* plugin
* @param {boolean} manifestOptions.updatePeerDependencies Option for the node-workspace
* plugin
* @param {string} manifestOptions.goWorkFile Option for the go-workspace plugin
* @param {boolean} manifestOptions.separatePullRequests If true, create separate pull
* requests instead of a single manifest release pull request
* @param {PluginType[]} manifestOptions.plugins Any plugins to use for this repository
Expand Down
Loading