From 0d3ed6081f7423d5ee66d25e84107a5428433279 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 22 Dec 2021 16:27:54 -0800 Subject: [PATCH 1/2] feat: allow configuring simple strategy version file --- src/strategies/simple.ts | 13 +++++++++++-- test/strategies/simple.ts | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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/strategies/simple.ts b/test/strategies/simple.ts index e36332881..ead76a877 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); + }); }); }); From 06cdeb82baa7067ed4825ca4b99a32e57c0145a7 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 22 Dec 2021 16:34:09 -0800 Subject: [PATCH 2/2] fix: factory can build simple strategy with custom version file --- src/factory.ts | 7 ++++++- test/factory.ts | 9 +++++++++ test/strategies/simple.ts | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/factory.ts b/src/factory.ts index 460d921b2..bccdba1fb 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -84,7 +84,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), @@ -184,6 +183,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/test/factory.ts b/test/factory.ts index 6a3706cbb..c11ee8cec 100644 --- a/test/factory.ts +++ b/test/factory.ts @@ -187,4 +187,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 ead76a877..75e46a5f8 100644 --- a/test/strategies/simple.ts +++ b/test/strategies/simple.ts @@ -104,7 +104,7 @@ describe('Simple', () => { github, component: 'google-cloud-automl', versionFile: 'some-path/VERSION', - path: 'packages' + path: 'packages', }); const latestRelease = undefined; const release = await strategy.buildReleasePullRequest(