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

feat: allow configuring simple strategy version file #1168

Merged
merged 4 commits into from
Jan 12, 2022
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
7 changes: 6 additions & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions src/strategies/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Update[]> {
Expand All @@ -36,7 +45,7 @@ export class Simple extends BaseStrategy {
});

updates.push({
path: this.addPath('version.txt'),
path: this.addPath(this.versionFile),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 🥳

Is it worth adding a test that we default to version.txt?

createIfMissing: false,
updater: new DefaultUpdater({
version,
Expand Down
9 changes: 9 additions & 0 deletions test/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
17 changes: 17 additions & 0 deletions test/strategies/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});