Skip to content

Commit

Permalink
fix(ruby): The Ruby releaser defaults to the correct version.rb path (g…
Browse files Browse the repository at this point in the history
…oogleapis#1041)

* fix(ruby): The Ruby releaser defaults to the correct version.rb path

* Lint fixes
  • Loading branch information
dazuma committed Sep 8, 2021
1 parent fc929df commit fd904c0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
50 changes: 49 additions & 1 deletion __snapshots__/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ filename: projects/ruby/CHANGELOG.md
* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([08ca011](https://www.github.com/googleapis/ruby-test-repo/commit/08ca01180a91c0a1ba8992b491db9212))
* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([845db13](https://www.github.com/googleapis/ruby-test-repo/commit/845db1381b3d5d20151cad2588f85feb))
filename: projects/ruby/lib/google/cloud/automl/version.rb
# Copyright 2019 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
#
# https://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.
module Google
module Cloud
module Bigtable
VERSION = "0.5.1".freeze
end
end
end
`

exports['Ruby run creates a release PR relative to a path: options'] = `
Expand Down Expand Up @@ -61,6 +85,30 @@ filename: projects/ruby/HISTORY.md
* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([08ca011](https://www.github.com/googleapis/ruby-test-repo/commit/08ca01180a91c0a1ba8992b491db9212))
* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([845db13](https://www.github.com/googleapis/ruby-test-repo/commit/845db1381b3d5d20151cad2588f85feb))
filename: projects/ruby/lib/blah/version.rb
# Copyright 2019 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
#
# https://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.
module Google
module Cloud
module Bigtable
VERSION = "0.6.0".freeze
end
end
end
`

exports['Ruby run creates a release PR with custom config: options'] = `
Expand Down Expand Up @@ -111,7 +159,7 @@ filename: CHANGELOG.md
* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([08ca011](https://www.github.com/googleapis/ruby-test-repo/commit/08ca01180a91c0a1ba8992b491db9212))
* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([845db13](https://www.github.com/googleapis/ruby-test-repo/commit/845db1381b3d5d20151cad2588f85feb))
filename: version.rb
filename: lib/google/cloud/automl/version.rb
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 4 additions & 1 deletion src/releasers/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class Ruby extends ReleasePR {
packageName: PackageName
): Promise<Update[]> {
const updates: Update[] = [];
const versionFile: string = this.versionFile
? this.versionFile
: `lib/${packageName.name.replace(/-/g, '/')}/version.rb`;

updates.push(
new Changelog({
Expand All @@ -54,7 +57,7 @@ export class Ruby extends ReleasePR {

updates.push(
new VersionRB({
path: this.addPath(this.versionFile),
path: this.addPath(versionFile),
changelogEntry,
version: candidate.version,
packageName: packageName.name,
Expand Down
10 changes: 6 additions & 4 deletions test/releasers/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ describe('Ruby', () => {
describe('run', () => {
it('creates a release PR with defaults', async function () {
const releasePR = new Ruby({
versionFile: 'version.rb',
github: new GitHub({owner: 'googleapis', repo: 'ruby-test-repo'}),
packageName: pkgName,
});

stubSuggesterWithSnapshot(sandbox, this.test!.fullTitle());
stubGithub(releasePR);
stubFilesToUpdate(releasePR.gh, ['version.rb']);
stubFilesToUpdate(releasePR.gh, ['lib/google/cloud/automl/version.rb']);
const pr = await releasePR.run();
assert.strictEqual(pr, 22);
});
Expand All @@ -93,7 +92,9 @@ describe('Ruby', () => {

stubSuggesterWithSnapshot(sandbox, this.test!.fullTitle());
stubGithub(releasePR);
stubFilesToUpdate(releasePR.gh, ['version.rb']);
stubFilesToUpdate(releasePR.gh, [
'projects/ruby/lib/google/cloud/automl/version.rb',
]);
const pr = await releasePR.run();
assert.strictEqual(pr, 22);
});
Expand All @@ -106,6 +107,7 @@ describe('Ruby', () => {
bumpMinorPreMajor: true,
monorepoTags: true,
changelogPath: 'HISTORY.md',
versionFile: 'lib/blah/version.rb',
});

stubSuggesterWithSnapshot(sandbox, this.test!.fullTitle());
Expand All @@ -114,7 +116,7 @@ describe('Ruby', () => {
const latestTag = {...LATEST_TAG};
latestTag.name = pkgName + '/v' + latestTag.version;
stubGithub(releasePR, commits, latestTag);
stubFilesToUpdate(releasePR.gh, ['projects/ruby/version.rb']);
stubFilesToUpdate(releasePR.gh, ['projects/ruby/lib/blah/version.rb']);
const pr = await releasePR.run();
assert.strictEqual(pr, 22);
});
Expand Down

0 comments on commit fd904c0

Please sign in to comment.