Skip to content

Commit

Permalink
fix(ruby-yoshi): Fix the initial release of new Ruby-Yoshi libraries (#…
Browse files Browse the repository at this point in the history
…933)

* fix(ruby-yoshi): Fix the initial release of new Ruby-Yoshi libraries

* Lint fixes

* Add initial test for ruby-yoshi

* Fix attempt

* Test resulting version numbers
  • Loading branch information
dazuma authored Jun 18, 2021
1 parent 06722a8 commit 86f96c9
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/releasers/ruby-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ export class RubyYoshi extends ReleasePR {
),
changelogSections: CHANGELOG_SECTIONS,
});
const githubTag: GitHubTag | undefined = this.lastPackageVersion
? ({
version: this.lastPackageVersion,
name: this.lastPackageVersion,
} as GitHubTag)
: undefined;
const candidate: ReleaseCandidate = await this.coerceReleaseCandidate(
cc,
{
version: this.lastPackageVersion,
name: this.lastPackageVersion,
} as GitHubTag
githubTag
);
const changelogEntry: string = await cc.generateChangelogEntry({
version: candidate.version,
Expand Down
107 changes: 107 additions & 0 deletions test/releasers/ruby-yoshi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as assert from 'assert';
import {describe, it, afterEach} from 'mocha';
import {GitHub} from '../../src/github';
import * as sinon from 'sinon';
import {stubFilesFromFixtures} from './utils';
import {buildMockCommit, stubSuggesterWithSnapshot} from '../helpers';
import {RubyYoshi} from '../../src/releasers/ruby-yoshi';

const sandbox = sinon.createSandbox();

function stubFilesToUpdate(github: GitHub, files: string[]) {
stubFilesFromFixtures({
fixturePath: './test/updaters/fixtures',
sandbox,
github,
files,
});
}

const TAG_SHA = 'da6e52d956c1e35d19e75e0f2fdba439739ba364';

const COMMITS = [
buildMockCommit(
'fix(deps): update dependency com.google.cloud:google-cloud-storage to v1.120.0'
),
buildMockCommit(
'fix(deps): update dependency com.google.cloud:google-cloud-spanner to v1.50.0'
),
buildMockCommit('chore: update common templates'),
];

function stubGithub(releasePR: RubyYoshi, expectedVersion: string) {
sandbox
.stub(releasePR.gh, 'findMergedReleasePR')
.returns(Promise.resolve(undefined));
sandbox.stub(releasePR.gh, 'findOpenReleasePRs').returns(Promise.resolve([]));
sandbox.stub(releasePR.gh, 'openPR').callsFake(arg => {
if (arg.updates[0].version === expectedVersion) {
return Promise.resolve(22);
} else {
return Promise.resolve(21);
}
});
sandbox.stub(releasePR.gh, 'addLabels');
sandbox.stub(releasePR.gh, 'getDefaultBranch').resolves('master');
}

describe('RubyYoshi', () => {
afterEach(() => {
sandbox.restore();
});
const pkgName = 'google-cloud-automl';

describe('run', () => {
it('creates a release PR with a previous release', async function () {
const releasePR = new RubyYoshi({
github: new GitHub({owner: 'googleapis', repo: 'ruby-test-repo'}),
versionFile: 'version.rb',
bumpMinorPreMajor: true,
monorepoTags: true,
packageName: pkgName,
lastPackageVersion: '0.5.0',
});

stubSuggesterWithSnapshot(sandbox, this.test!.fullTitle());
stubGithub(releasePR, '0.5.1');
sandbox.stub(releasePR.gh, 'getTagSha').resolves(TAG_SHA);
sandbox.stub(releasePR.gh, 'commitsSinceSha').resolves(COMMITS);
stubFilesToUpdate(releasePR.gh, ['version.rb']);

const pr = await releasePR.run();
assert.strictEqual(pr, 22);
});

it('creates a release PR with no previous release', async function () {
const releasePR = new RubyYoshi({
github: new GitHub({owner: 'googleapis', repo: 'ruby-test-repo'}),
versionFile: 'version.rb',
bumpMinorPreMajor: true,
monorepoTags: true,
packageName: pkgName,
});

stubSuggesterWithSnapshot(sandbox, this.test!.fullTitle());
stubGithub(releasePR, '0.1.0');
sandbox.stub(releasePR.gh, 'commitsSinceSha').resolves(COMMITS);
stubFilesToUpdate(releasePR.gh, ['version.rb']);

const pr = await releasePR.run();
assert.strictEqual(pr, 22);
});
});
});

0 comments on commit 86f96c9

Please sign in to comment.