forked from googleapis/release-please
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby.ts
More file actions
147 lines (143 loc) · 4.95 KB
/
ruby.ts
File metadata and controls
147 lines (143 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// 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 {describe, it, afterEach, beforeEach} from 'mocha';
import {expect} from 'chai';
import {GitHub} from '../../src/github';
import {Ruby} from '../../src/strategies/ruby';
import * as sinon from 'sinon';
import {assertHasUpdate} from '../helpers';
import {buildMockConventionalCommit} from '../helpers';
import {TagName} from '../../src/util/tag-name';
import {Version} from '../../src/version';
import {Changelog} from '../../src/updaters/changelog';
import {VersionRB} from '../../src/updaters/ruby/version-rb';
import {GemfileLock} from '../../src/updaters/ruby/gemfile-lock';
import {PullRequestBody} from '../../src/util/pull-request-body';
const sandbox = sinon.createSandbox();
const COMMITS = [
...buildMockConventionalCommit(
'fix(deps): update dependency com.google.cloud:google-cloud-storage to v1.120.0'
),
...buildMockConventionalCommit(
'fix(deps): update dependency com.google.cloud:google-cloud-spanner to v1.50.0'
),
...buildMockConventionalCommit('chore: update common templates'),
];
describe('Ruby', () => {
let github: GitHub;
beforeEach(async () => {
github = await GitHub.create({
owner: 'googleapis',
repo: 'ruby-test-repo',
defaultBranch: 'main',
});
});
afterEach(() => {
sandbox.restore();
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '1.0.0';
const strategy = new Ruby({
targetBranch: 'main',
github,
component: 'google-cloud-automl',
});
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
expect(release!.version?.toString()).to.eql(expectedVersion);
});
it('returns release PR changes with semver patch bump', async () => {
const expectedVersion = '0.123.5';
const strategy = new Ruby({
targetBranch: 'main',
github,
component: 'google-cloud-automl',
});
const latestRelease = {
tag: new TagName(Version.parse('0.123.4'), 'google-cloud-automl'),
sha: 'abc123',
notes: 'some notes',
};
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
expect(release!.version?.toString()).to.eql(expectedVersion);
});
});
describe('buildUpdates', () => {
it('builds common files', async () => {
const strategy = new Ruby({
targetBranch: 'main',
github,
component: 'google-cloud-automl',
});
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
const updates = release!.updates;
expect(updates).lengthOf(3);
assertHasUpdate(updates, 'CHANGELOG.md', Changelog);
assertHasUpdate(updates, 'lib/google/cloud/automl/version.rb', VersionRB);
assertHasUpdate(updates, 'Gemfile.lock', GemfileLock);
});
it('allows overriding version file', async () => {
const strategy = new Ruby({
targetBranch: 'main',
github,
component: 'google-cloud-automl',
versionFile: 'lib/foo/version.rb',
});
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
const updates = release!.updates;
expect(updates).lengthOf(3);
assertHasUpdate(updates, 'CHANGELOG.md', Changelog);
assertHasUpdate(updates, 'lib/foo/version.rb', VersionRB);
assertHasUpdate(updates, 'Gemfile.lock', GemfileLock);
});
// TODO: add tests for tag separator
// TODO: add tests for post-processing commit messages
});
describe('buildRelease', () => {
it('overrides the tag separator', async () => {
const strategy = new Ruby({
targetBranch: 'main',
github,
component: 'google-cloud-automl',
});
const release = await strategy.buildRelease({
title: 'chore(main): release v1.2.3',
headBranchName: 'release-please/branches/main',
baseBranchName: 'main',
number: 1234,
body: new PullRequestBody([]).toString(),
labels: [],
files: [],
sha: 'abc123',
});
expect(release, 'Release').to.not.be.undefined;
expect(release!.tag.separator).to.eql('/');
});
});
});