Skip to content

Commit b31db93

Browse files
committed
added option to configure path to go.work
1 parent 348e69a commit b31db93

File tree

7 files changed

+180
-6
lines changed

7 files changed

+180
-6
lines changed

__snapshots__/go-workspace.js

+43
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,49 @@ Release notes for path: packages/goB, releaseType: go
7373
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
7474
`
7575

76+
exports['GoWorkspace plugin run uses go-work-file config value 1'] = `
77+
:robot: I have created a release *beep* *boop*
78+
---
79+
80+
81+
<details><summary>example.com/packages/goA: 1.1.2</summary>
82+
83+
Release notes for path: packages/goA, releaseType: go
84+
</details>
85+
86+
<details><summary>example.com/packages/goB/v2: 2.2.3</summary>
87+
88+
### Dependencies
89+
90+
* The following workspace dependencies were updated
91+
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
92+
</details>
93+
94+
<details><summary>example.com/packages/goC: 3.3.4</summary>
95+
96+
### Dependencies
97+
98+
* The following workspace dependencies were updated
99+
* example.com/packages/goB/v2 bumped from 2.2.2 to 2.2.3
100+
</details>
101+
102+
<details><summary>example.com/packages/goD: 4.4.5</summary>
103+
104+
Release notes for path: packages/goD, releaseType: go
105+
</details>
106+
107+
<details><summary>example.com/packages/goE: 3.3.4</summary>
108+
109+
### Dependencies
110+
111+
* The following workspace dependencies were updated
112+
* example.com/packages/goA bumped from 1.1.1 to 1.1.2
113+
</details>
114+
115+
---
116+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
117+
`
118+
76119
exports['GoWorkspace plugin run walks dependency tree and updates previously untouched packages 1'] = `
77120
:robot: I have created a release *beep* *boop*
78121
---

docs/manifest-releaser.md

+16
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,22 @@ all modules in a workspace and updates any modules that depends
542542
(directly or transitively) on the changed module. The workspace dependencies in
543543
`go.mod` files are updated accordingly.
544544

545+
#### go.work in a non-default location
546+
547+
By default, the `go.work` file is expected to be in the root. Set `"goWorkFile"`
548+
to a custom path to use a file in a different location.
549+
550+
```
551+
{
552+
"plugins": [
553+
{
554+
"type": "go-workspace",
555+
"goWorkFile": "/path/to/filename"
556+
}
557+
]
558+
}
559+
```
560+
545561
### maven-workspace
546562

547563
The `maven-workspace` plugin operates similarly to the `node-workspace` plugin,

schemas/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@
367367
"updatePeerDependencies": {
368368
"description": "Also bump peer dependency versions if they are modified. Defaults to `false`.",
369369
"type": "boolean"
370+
},
371+
"goWorkFile": {
372+
"description": "Path to the go.work file. Defaults to `go.work`.",
373+
"type": "string"
370374
}
371375
}
372376
},

src/factories/plugin-factory.ts

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export interface PluginFactoryOptions {
4949
updateAllPackages?: boolean;
5050
considerAllArtifacts?: boolean;
5151

52+
// go options
53+
goWorkFile?: string;
54+
5255
logger?: Logger;
5356
}
5457

src/manifest.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ export interface WorkspacePluginConfig extends ConfigurablePluginType {
234234
export interface NodeWorkspacePluginConfig extends WorkspacePluginConfig {
235235
updatePeerDependencies?: boolean;
236236
}
237+
export interface GoWorkspacePluginConfig extends WorkspacePluginConfig {
238+
goWorkFile?: string;
239+
}
237240
export interface GroupPriorityPluginConfig extends ConfigurablePluginType {
238241
groups: string[];
239242
}
@@ -244,7 +247,8 @@ export type PluginType =
244247
| LinkedVersionPluginConfig
245248
| SentenceCasePluginConfig
246249
| WorkspacePluginConfig
247-
| NodeWorkspacePluginConfig;
250+
| NodeWorkspacePluginConfig
251+
| GoWorkspacePluginConfig;
248252

249253
/**
250254
* This is the schema of the manifest config json
@@ -332,6 +336,7 @@ export class Manifest {
332336
* plugin
333337
* @param {boolean} manifestOptions.updatePeerDependencies Option for the node-workspace
334338
* plugin
339+
* @param {string} manifestOptions.goWorkFile Option for the go-workspace plugin
335340
* @param {boolean} manifestOptions.separatePullRequests If true, create separate pull
336341
* requests instead of a single manifest release pull request
337342
* @param {PluginType[]} manifestOptions.plugins Any plugins to use for this repository
@@ -450,6 +455,7 @@ export class Manifest {
450455
* plugin
451456
* @param {boolean} manifestOptions.updatePeerDependencies Option for the node-workspace
452457
* plugin
458+
* @param {string} manifestOptions.goWorkFile Option for the go-workspace plugin
453459
* @param {boolean} manifestOptions.separatePullRequests If true, create separate pull
454460
* requests instead of a single manifest release pull request
455461
* @param {PluginType[]} manifestOptions.plugins Any plugins to use for this repository

src/plugins/go-workspace.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ interface GoModInfo {
6767
modContent: string;
6868
}
6969

70+
interface GoWorkspaceOptions extends WorkspacePluginOptions {
71+
goWorkFile?: string;
72+
}
73+
7074
/**
7175
* The plugin analyzes a go workspace and will bump dependencies
7276
* of managed packages if those dependencies are being updated.
@@ -78,16 +82,18 @@ export class GoWorkspace extends WorkspacePlugin<GoModInfo> {
7882
private strategiesByPath: Record<string, Strategy> = {};
7983
private releasesByPath: Record<string, Release> = {};
8084
private readonly releaseManifestPath: string;
85+
private readonly goWorkPath: string;
8186

8287
constructor(
8388
github: GitHub,
8489
targetBranch: string,
8590
repositoryConfig: RepositoryConfig,
86-
options: WorkspacePluginOptions = {}
91+
options: GoWorkspaceOptions = {}
8792
) {
8893
super(github, targetBranch, repositoryConfig, options);
8994
this.releaseManifestPath =
9095
options.manifestPath ?? DEFAULT_RELEASE_PLEASE_MANIFEST;
96+
this.goWorkPath = options.goWorkFile || 'go.work';
9197
}
9298

9399
protected bumpVersion(pkg: GoModInfo): Version {
@@ -256,14 +262,12 @@ export class GoWorkspace extends WorkspacePlugin<GoModInfo> {
256262
candidatesByPackage: Record<string, CandidateReleasePullRequest>;
257263
}> {
258264
const goWorkspaceContent = await this.github.getFileContentsOnBranch(
259-
'go.work',
265+
this.goWorkPath,
260266
this.targetBranch
261267
);
262268
const goWorkspace = parseGoWorkspace(goWorkspaceContent.parsedContent);
263269
if (!goWorkspace?.members) {
264-
this.logger.warn(
265-
"go-workspace plugin used, but could not find use directive(s) 'go.work' file"
266-
);
270+
this.logger.warn('go-workspace plugin used, but found no use directives');
267271
return {allPackages: [], candidatesByPackage: {}};
268272
}
269273

test/plugins/go-workspace.ts

+98
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,103 @@ describe('GoWorkspace plugin', () => {
342342
assertHasUpdate(updates, 'packages/goB/go.mod', RawContent);
343343
snapshot(dateSafe(goCandidate!.pullRequest.body.toString()));
344344
});
345+
it('uses go-work-file config value', async () => {
346+
const options = {goWorkFile: 'some/go.work.file'};
347+
plugin = new GoWorkspace(
348+
github,
349+
'main',
350+
{
351+
'packages/goA': {
352+
releaseType: 'go',
353+
},
354+
'packages/goB': {
355+
releaseType: 'go',
356+
},
357+
'packages/goC': {
358+
releaseType: 'go',
359+
},
360+
'packages/goD': {
361+
releaseType: 'go',
362+
},
363+
},
364+
options
365+
);
366+
367+
const candidates: CandidateReleasePullRequest[] = [
368+
buildMockCandidatePullRequest('packages/goA', 'go', '1.1.2', {
369+
component: 'example.com/packages/goA',
370+
updates: [
371+
buildMockPackageUpdate(
372+
'packages/goA/go.mod',
373+
'packages/goA/go.mod',
374+
'1.1.1'
375+
),
376+
],
377+
}),
378+
buildMockCandidatePullRequest('packages/goD', 'go', '4.4.5', {
379+
component: 'example.com/packages/goD',
380+
updates: [
381+
buildMockPackageUpdate(
382+
'packages/goD/go.mod',
383+
'packages/goD/go.mod',
384+
'4.4.4'
385+
),
386+
],
387+
}),
388+
];
389+
390+
stubFilesFromFixtures({
391+
sandbox,
392+
github,
393+
fixturePath: fixturesPath,
394+
files: [
395+
'.release-please-manifest.json',
396+
'packages/goA/go.mod',
397+
'packages/goA/CHANGELOG.md',
398+
'packages/goB/go.mod',
399+
'packages/goB/CHANGELOG.md',
400+
'packages/goC/go.mod',
401+
'packages/goC/CHANGELOG.md',
402+
'packages/goD/go.mod',
403+
'packages/goD/CHANGELOG.md',
404+
'packages/goE/go.mod',
405+
'packages/goE/CHANGELOG.md',
406+
],
407+
inlineFiles: [
408+
[
409+
'some/go.work.file',
410+
'go 1.23.1\nuse ./packages/goA\n\nuse ./packages/goB\nuse ./packages/goC\nuse ./packages/goD\nuse ./packages/goE\n',
411+
],
412+
],
413+
flatten: false,
414+
targetBranch: 'main',
415+
});
416+
sandbox
417+
.stub(github, 'findFilesByGlobAndRef')
418+
.withArgs('packages/goA', 'main')
419+
.resolves(['packages/goA'])
420+
.withArgs('packages/goB', 'main')
421+
.resolves(['packages/goB'])
422+
.withArgs('packages/goC', 'main')
423+
.resolves(['packages/goC'])
424+
.withArgs('packages/goD', 'main')
425+
.resolves(['packages/goD'])
426+
.withArgs('packages/goE', 'main')
427+
.resolves(['packages/goE']);
428+
const newCandidates = await plugin.run(candidates);
429+
expect(newCandidates).lengthOf(1);
430+
const goCandidate = newCandidates.find(
431+
candidate => candidate.config.releaseType === 'go'
432+
);
433+
expect(goCandidate).to.not.be.undefined;
434+
const updates = goCandidate!.pullRequest.updates;
435+
// Check that transitive dependencies are updated
436+
assertHasUpdate(updates, 'packages/goA/go.mod', RawContent);
437+
assertHasUpdate(updates, 'packages/goB/go.mod', RawContent);
438+
assertHasUpdate(updates, 'packages/goC/go.mod', RawContent);
439+
assertHasUpdate(updates, 'packages/goD/go.mod', RawContent);
440+
assertHasUpdate(updates, 'packages/goE/go.mod', RawContent);
441+
snapshot(dateSafe(goCandidate!.pullRequest.body.toString()));
442+
});
345443
});
346444
});

0 commit comments

Comments
 (0)