-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3569f15
commit b12904a
Showing
12 changed files
with
390 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
exports['ModuleBazel updateContent updates version in MODULE.bazel file 1'] = ` | ||
module( | ||
name = "rules_cc", | ||
version = "0.0.5", | ||
compatibility_level = 1, | ||
) | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
register_toolchains("@local_config_cc_toolchains//:all") | ||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) | ||
` | ||
|
||
exports['ModuleBazel updateContent updates version when inline 1'] = ` | ||
module(name = "rules_cc", version = "0.0.5") | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
register_toolchains("@local_config_cc_toolchains//:all") | ||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) | ||
` | ||
|
||
exports['ModuleBazel updateContent updates version when ordered improperly 1'] = ` | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
module(name = "rules_cc", version = "0.0.5") | ||
register_toolchains("@local_config_cc_toolchains//:all") | ||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2024 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 {Update} from '../update'; | ||
import {ModuleBazel} from '../updaters/bazel/module-bazel'; | ||
import {Changelog} from '../updaters/changelog'; | ||
import {BaseStrategy, BaseStrategyOptions, BuildUpdatesOptions} from './base'; | ||
|
||
export class Bazel extends BaseStrategy { | ||
readonly versionFile: string; | ||
constructor(options: BaseStrategyOptions) { | ||
super(options); | ||
this.versionFile = options.versionFile ?? 'MODULE.bazel'; | ||
} | ||
protected async buildUpdates( | ||
options: BuildUpdatesOptions | ||
): Promise<Update[]> { | ||
const updates: Update[] = []; | ||
const version = options.newVersion; | ||
|
||
updates.push({ | ||
path: this.addPath(this.changelogPath), | ||
createIfMissing: true, | ||
updater: new Changelog({ | ||
version, | ||
changelogEntry: options.changelogEntry, | ||
}), | ||
}); | ||
|
||
updates.push({ | ||
path: this.addPath(this.versionFile), | ||
createIfMissing: false, | ||
updater: new ModuleBazel({ | ||
version, | ||
}), | ||
}); | ||
|
||
return updates; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 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 {DefaultUpdater} from '../default'; | ||
|
||
/** | ||
* Updates a Bazel Module file. | ||
*/ | ||
export class ModuleBazel extends DefaultUpdater { | ||
updateContent(content: string): string { | ||
const match = content.match( | ||
/module[\s\S]*?\([\s\S]*?version\s*=\s*(['"])(.*?)\1/m | ||
); | ||
if (!match) { | ||
return content; | ||
} | ||
const [fullMatch, , version] = match; | ||
const module = fullMatch.replace(version, this.version.toString()); | ||
return content.replace(fullMatch, module); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2024 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 {expect} from 'chai'; | ||
import {afterEach, beforeEach, describe, it} from 'mocha'; | ||
import * as sinon from 'sinon'; | ||
import {GitHub} from '../../src/github'; | ||
import {Bazel} from '../../src/strategies/bazel'; | ||
import {ModuleBazel} from '../../src/updaters/bazel/module-bazel'; | ||
import {Changelog} from '../../src/updaters/changelog'; | ||
import {TagName} from '../../src/util/tag-name'; | ||
import {Version} from '../../src/version'; | ||
import {assertHasUpdate, buildMockConventionalCommit} from '../helpers'; | ||
|
||
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('Bazel', () => { | ||
let github: GitHub; | ||
beforeEach(async () => { | ||
github = await GitHub.create({ | ||
owner: 'googleapis', | ||
repo: 'bazel-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 Bazel({ | ||
targetBranch: 'main', | ||
github, | ||
component: 'rules_cc', | ||
}); | ||
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 Bazel({ | ||
targetBranch: 'main', | ||
github, | ||
component: 'rules_cc', | ||
}); | ||
const latestRelease = { | ||
tag: new TagName(Version.parse('0.123.4'), 'rules_cc'), | ||
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 Bazel({ | ||
targetBranch: 'main', | ||
github, | ||
component: 'rules_cc', | ||
}); | ||
const latestRelease = undefined; | ||
const release = await strategy.buildReleasePullRequest( | ||
COMMITS, | ||
latestRelease | ||
); | ||
const updates = release!.updates; | ||
assertHasUpdate(updates, 'CHANGELOG.md', Changelog); | ||
assertHasUpdate(updates, 'MODULE.bazel', ModuleBazel); | ||
}); | ||
it('allows configuring the version file', async () => { | ||
const strategy = new Bazel({ | ||
targetBranch: 'main', | ||
github, | ||
component: 'rules_cc', | ||
versionFile: 'some-path/MODULE.bazel', | ||
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/MODULE.bazel', ModuleBazel); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module(name = "rules_cc", version = "0.0.4") | ||
|
||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
|
||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
|
||
register_toolchains("@local_config_cc_toolchains//:all") | ||
|
||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
|
||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
|
||
register_toolchains("@local_config_cc_toolchains//:all") | ||
|
||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
|
||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
|
||
module(name = "rules_cc", version = "0.0.4") | ||
|
||
register_toolchains("@local_config_cc_toolchains//:all") | ||
|
||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module( | ||
name = "rules_cc", | ||
version = "0.0.4", | ||
compatibility_level = 1, | ||
) | ||
|
||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "platforms", version = "0.0.7") | ||
|
||
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") | ||
use_repo(cc_configure, "local_config_cc_toolchains") | ||
|
||
register_toolchains("@local_config_cc_toolchains//:all") | ||
|
||
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) |
Oops, something went wrong.