Skip to content

Commit

Permalink
fix: allow forcing generic updater for extra-files (#2227)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
regseb and chingor13 committed Mar 11, 2024
1 parent 378367b commit 144c1fd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/customizing.md
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
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
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
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

0 comments on commit 144c1fd

Please sign in to comment.