|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import {expect} from 'chai'; |
| 16 | +import {afterEach, beforeEach, describe, it} from 'mocha'; |
| 17 | +import * as sinon from 'sinon'; |
| 18 | +import {GitHub} from '../../src/github'; |
| 19 | +import {Bazel} from '../../src/strategies/bazel'; |
| 20 | +import {ModuleBazel} from '../../src/updaters/bazel/module-bazel'; |
| 21 | +import {Changelog} from '../../src/updaters/changelog'; |
| 22 | +import {TagName} from '../../src/util/tag-name'; |
| 23 | +import {Version} from '../../src/version'; |
| 24 | +import {assertHasUpdate, buildMockConventionalCommit} from '../helpers'; |
| 25 | + |
| 26 | +const sandbox = sinon.createSandbox(); |
| 27 | + |
| 28 | +const COMMITS = [ |
| 29 | + ...buildMockConventionalCommit( |
| 30 | + 'fix(deps): update dependency com.google.cloud:google-cloud-storage to v1.120.0' |
| 31 | + ), |
| 32 | + ...buildMockConventionalCommit( |
| 33 | + 'fix(deps): update dependency com.google.cloud:google-cloud-spanner to v1.50.0' |
| 34 | + ), |
| 35 | + ...buildMockConventionalCommit('chore: update common templates'), |
| 36 | +]; |
| 37 | + |
| 38 | +describe('Bazel', () => { |
| 39 | + let github: GitHub; |
| 40 | + beforeEach(async () => { |
| 41 | + github = await GitHub.create({ |
| 42 | + owner: 'googleapis', |
| 43 | + repo: 'bazel-test-repo', |
| 44 | + defaultBranch: 'main', |
| 45 | + }); |
| 46 | + }); |
| 47 | + afterEach(() => { |
| 48 | + sandbox.restore(); |
| 49 | + }); |
| 50 | + describe('buildReleasePullRequest', () => { |
| 51 | + it('returns release PR changes with defaultInitialVersion', async () => { |
| 52 | + const expectedVersion = '1.0.0'; |
| 53 | + const strategy = new Bazel({ |
| 54 | + targetBranch: 'main', |
| 55 | + github, |
| 56 | + component: 'rules_cc', |
| 57 | + }); |
| 58 | + const latestRelease = undefined; |
| 59 | + const release = await strategy.buildReleasePullRequest( |
| 60 | + COMMITS, |
| 61 | + latestRelease |
| 62 | + ); |
| 63 | + expect(release!.version?.toString()).to.eql(expectedVersion); |
| 64 | + }); |
| 65 | + it('returns release PR changes with semver patch bump', async () => { |
| 66 | + const expectedVersion = '0.123.5'; |
| 67 | + const strategy = new Bazel({ |
| 68 | + targetBranch: 'main', |
| 69 | + github, |
| 70 | + component: 'rules_cc', |
| 71 | + }); |
| 72 | + const latestRelease = { |
| 73 | + tag: new TagName(Version.parse('0.123.4'), 'rules_cc'), |
| 74 | + sha: 'abc123', |
| 75 | + notes: 'some notes', |
| 76 | + }; |
| 77 | + const release = await strategy.buildReleasePullRequest( |
| 78 | + COMMITS, |
| 79 | + latestRelease |
| 80 | + ); |
| 81 | + expect(release!.version?.toString()).to.eql(expectedVersion); |
| 82 | + }); |
| 83 | + }); |
| 84 | + describe('buildUpdates', () => { |
| 85 | + it('builds common files', async () => { |
| 86 | + const strategy = new Bazel({ |
| 87 | + targetBranch: 'main', |
| 88 | + github, |
| 89 | + component: 'rules_cc', |
| 90 | + }); |
| 91 | + const latestRelease = undefined; |
| 92 | + const release = await strategy.buildReleasePullRequest( |
| 93 | + COMMITS, |
| 94 | + latestRelease |
| 95 | + ); |
| 96 | + const updates = release!.updates; |
| 97 | + assertHasUpdate(updates, 'CHANGELOG.md', Changelog); |
| 98 | + assertHasUpdate(updates, 'MODULE.bazel', ModuleBazel); |
| 99 | + }); |
| 100 | + it('allows configuring the version file', async () => { |
| 101 | + const strategy = new Bazel({ |
| 102 | + targetBranch: 'main', |
| 103 | + github, |
| 104 | + component: 'rules_cc', |
| 105 | + versionFile: 'some-path/MODULE.bazel', |
| 106 | + path: 'packages', |
| 107 | + }); |
| 108 | + const latestRelease = undefined; |
| 109 | + const release = await strategy.buildReleasePullRequest( |
| 110 | + COMMITS, |
| 111 | + latestRelease |
| 112 | + ); |
| 113 | + const updates = release!.updates; |
| 114 | + assertHasUpdate(updates, 'packages/CHANGELOG.md', Changelog); |
| 115 | + assertHasUpdate(updates, 'packages/some-path/MODULE.bazel', ModuleBazel); |
| 116 | + }); |
| 117 | + }); |
| 118 | +}); |
0 commit comments