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

fix: Support generic updater #2227

Merged
merged 2 commits into from
Mar 11, 2024
Merged
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
15 changes: 15 additions & 0 deletions docs/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ You can annotate a block by starting with a line containing:
and close the block with a line containing `x-release-please-end`. Within
the block, we will attempt to replace version values.

Default updaters are applied depending on the file extension. If you want to
force the [Generic](/src/updaters/generic.ts) updater, you must use type
`"generic"`.

```json
{
"extra-files": [
{
"type": "generic",
"path": "path/to/file.yml"
}
]
}
```

## Updating arbitrary JSON files

For files with the `.xml` extension, the `version` property is updated.
Expand Down
6 changes: 6 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ import {
import {signoffCommitMessage} from './util/signoff-commit-message';
import {CommitExclude} from './util/commit-exclude';

type ExtraGenericFile = {
type: 'generic';
path: string;
glob?: boolean;
};
type ExtraJsonFile = {
type: 'json';
path: string;
Expand Down Expand Up @@ -79,6 +84,7 @@ type ExtraTomlFile = {
};
export type ExtraFile =
| string
| ExtraGenericFile
| ExtraJsonFile
| ExtraYamlFile
| ExtraXmlFile
Expand Down
7 changes: 7 additions & 0 deletions src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ export abstract class BaseStrategy implements Strategy {
const paths = await this.extraFilePaths(extraFile);
for (const path of paths) {
switch (extraFile.type) {
case 'generic':
extraFileUpdates.push({
path: this.addPath(path),
createIfMissing: false,
updater: new Generic({version, versionsMap}),
});
break;
case 'json':
extraFileUpdates.push({
path: this.addPath(path),
Expand Down
17 changes: 17 additions & 0 deletions test/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ describe('Strategy', () => {
expect(updates).to.be.an('array');
assertHasUpdates(updates!, 'pom.xml', GenericXml, Generic);
});
it('updates extra generic files', async () => {
const strategy = new TestStrategy({
targetBranch: 'main',
github,
component: 'google-cloud-automl',
extraFiles: ['0', {type: 'generic', path: '/1.yml'}],
});
const pullRequest = await strategy.buildReleasePullRequest(
buildMockConventionalCommit('fix: a bugfix'),
undefined
);
expect(pullRequest).to.exist;
const updates = pullRequest?.updates;
expect(updates).to.be.an('array');
assertHasUpdate(updates!, '0', Generic);
assertHasUpdate(updates!, '1.yml', Generic);
});
it('updates extra JSON files', async () => {
const strategy = new TestStrategy({
targetBranch: 'main',
Expand Down
Loading