diff --git a/src/factory.ts b/src/factory.ts index 60021e963..488272314 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -85,7 +85,6 @@ const releasers: Releasers = { 'php-yoshi': options => new PHPYoshi(options), python: options => new Python(options), rust: options => new Rust(options), - simple: options => new Simple(options), 'terraform-module': options => new TerraformModule(options), helm: options => new Helm(options), elixir: options => new Elixir(options), @@ -177,6 +176,12 @@ export async function buildStrategy( versioningStrategy: new ServicePackVersioningStrategy(), }); } + case 'simple': { + return new Simple({ + ...strategyOptions, + versionFile: options.versionFile, + }); + } default: { const builder = releasers[options.releaseType]; if (builder) { diff --git a/src/strategies/simple.ts b/src/strategies/simple.ts index a46e2adcb..93904f9a8 100644 --- a/src/strategies/simple.ts +++ b/src/strategies/simple.ts @@ -15,11 +15,20 @@ // Generic import {Changelog} from '../updaters/changelog'; // version.txt support -import {BaseStrategy, BuildUpdatesOptions} from './base'; +import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base'; import {Update} from '../update'; import {DefaultUpdater} from '../updaters/default'; +interface SimpleStrategyOptions extends BaseStrategyOptions { + versionFile?: string; +} + export class Simple extends BaseStrategy { + readonly versionFile: string; + constructor(options: SimpleStrategyOptions) { + super(options); + this.versionFile = options.versionFile ?? 'version.txt'; + } protected async buildUpdates( options: BuildUpdatesOptions ): Promise { @@ -36,7 +45,7 @@ export class Simple extends BaseStrategy { }); updates.push({ - path: this.addPath('version.txt'), + path: this.addPath(this.versionFile), createIfMissing: false, updater: new DefaultUpdater({ version, diff --git a/test/factory.ts b/test/factory.ts index 0e431c19b..313bfc666 100644 --- a/test/factory.ts +++ b/test/factory.ts @@ -199,4 +199,13 @@ describe('factory', () => { }); } }); + it('should customize a version-file for Simple', async () => { + const strategy = await buildStrategy({ + github, + releaseType: 'simple', + versionFile: 'foo/bar', + }); + expect(strategy).instanceof(Simple); + expect((strategy as Simple).versionFile).to.eql('foo/bar'); + }); }); diff --git a/test/strategies/simple.ts b/test/strategies/simple.ts index e36332881..75e46a5f8 100644 --- a/test/strategies/simple.ts +++ b/test/strategies/simple.ts @@ -98,5 +98,22 @@ describe('Simple', () => { assertHasUpdate(updates, 'CHANGELOG.md', Changelog); assertHasUpdate(updates, 'version.txt', DefaultUpdater); }); + it('allows configuring the version file', async () => { + const strategy = new Simple({ + targetBranch: 'main', + github, + component: 'google-cloud-automl', + versionFile: 'some-path/VERSION', + path: 'packages', + }); + const latestRelease = undefined; + const release = await strategy.buildReleasePullRequest( + COMMITS, + latestRelease + ); + const updates = release!.updates; + assertHasUpdate(updates, 'packages/CHANGELOG.md', Changelog); + assertHasUpdate(updates, 'packages/some-path/VERSION', DefaultUpdater); + }); }); });