Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • semantic-release/bzlmod
1 result
Show changes
Commits on Source (7)
# [1.2.0](https://git.gitlab.arm.com/semantic-release/bzlmod/compare/v1.1.0...v1.2.0) (2023-12-01)
### Bug Fixes
- correct version regular expression
([e276e15](https://git.gitlab.arm.com/semantic-release/bzlmod/commit/e276e15f12389d3e308cdef9c6c3a1f004e0bcdd))
- use `@bazel/buildozer` to update `version`
([26a9907](https://git.gitlab.arm.com/semantic-release/bzlmod/commit/26a99079a401010430aee2225ef08771db062fd6))
### Features
- use `@bazel/buildozer` to update compatibility level
([47246dc](https://git.gitlab.arm.com/semantic-release/bzlmod/commit/47246dc5880f385d6c6db64c22fb602c230b8b41))
# [1.1.0](https://git.gitlab.arm.com/semantic-release/bzlmod/compare/v1.0.3...v1.1.0) (2023-11-16)
### Features
......
......@@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@bazel/buildozer": "^6.4.0",
"@semantic-release/error": "^3 || ^4",
"debug": "^4",
"execa": "^8||^7||^6",
......@@ -204,6 +205,14 @@
"node": ">=4"
}
},
"node_modules/@bazel/buildozer": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/@bazel/buildozer/-/buildozer-6.4.0.tgz",
"integrity": "sha512-v4/R4JXSsQs9DGJfdqfXdVVv9t+fPfkpUmwEYZhoWfb9v69l7tyWRfXU1F5eWjHL6BMZ3phPEHjzrGOIhfe7gg==",
"bin": {
"buildozer": "buildozer.js"
}
},
"node_modules/@bcoe/v8-coverage": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz",
......
{
"private": true,
"name": "@semantic-release/bzlmod",
"version": "1.1.0",
"version": "1.2.0",
"description": "A `semantic release` plugin for bzlmod",
"exports": {
"import": "./plugin.mjs",
......@@ -30,6 +30,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@bazel/buildozer": "^6",
"@semantic-release/error": "^3 || ^4",
"debug": "^4",
"execa": "^8||^7||^6",
......
......@@ -8,12 +8,10 @@ import SemanticReleaseError from '@semantic-release/error';
import debug from 'debug';
import {template} from 'lodash-es';
import ssri from 'ssri';
import {execa} from 'execa';
import {execa, $} from 'execa';
debug('semantic-release:bzlmod');
const REGEX = /(module\(.*?version *= *")([^"]+)(".*?\))/s;
function extension(path) {
const [tar, ext] = path.split('.').slice(-2);
......@@ -49,11 +47,12 @@ export async function verifyConditions(pluginConfig, context) {
}
})();
debug('Finding `module.version` in `%s`', bzlmod);
if (!REGEX.test(data)) {
debug('Finding `module` in `%s`', bzlmod);
const {stdout} = await $`buildozer -root_dir ${cwd} ${'print kind'} //${filepath}:all`;
if (stdout !== 'module') {
throw new SemanticReleaseError(
`\`${bzlmod}\` \`module.version\` does not exist`,
'EBZLMODMISSINGVERSION',
`\`${bzlmod}\` \`module\` does not exist`,
'EBZLMODMISSINGMODULE',
);
}
......@@ -159,20 +158,13 @@ export async function prepare(pluginConfig, context) {
logger,
nextRelease: {version},
} = context;
const bzlmod = path.join(cwd, filepath);
debug('Reading `%s`', bzlmod);
const data = await readFile(bzlmod, {encoding: 'utf8'});
debug('Setting `module.version` in `%s`', bzlmod);
const updated = data.replace(REGEX, (_, prefix, current, suffix) => {
logger.log('Replacing `%s` with `%s`', current, version);
return `${prefix}${version}${suffix}`;
});
debug('Writing `%s`', bzlmod);
await writeFile(bzlmod, updated);
logger.success('Wrote `%s`', bzlmod);
const {stdout: current} = await $`buildozer -root_dir ${cwd} ${'print version'} //${filepath}:%module`;
logger.log('Replacing `%s` with `%s`', current, version);
const set = `set version ${version}`;
const [major] = version.split('.');
const level = `set compatibility_level ${major}`;
await $`buildozer -root_dir ${cwd} ${set} ${level} //${filepath}:%module`;
const {source} = pluginConfig;
......
......@@ -9,6 +9,7 @@ import {temporaryDirectory} from 'tempy';
import git from 'isomorphic-git';
import which from 'which';
import ssri from 'ssri';
import {$} from 'execa';
test.beforeEach(async t => {
clearModule('../plugin.mjs');
......@@ -22,6 +23,8 @@ test.beforeEach(async t => {
t.context.metadata = path.join(dir, 'metadata.json');
t.context.touch = path.join(dir, 'touch.txt');
await writeFile(t.context.touch, 'Hello, world!');
t.context.workspace = path.join(dir, 'WORKSPACE');
await writeFile(t.context.workspace, '');
t.context.filepath = path.join(dir, 'nested', 'MODULE.bazel');
await mkdir(path.dirname(t.context.filepath));
......@@ -97,6 +100,15 @@ const success = test.macro(
await t.notThrowsAsync(t.context.m.verifyConditions(t.context.cfg, t.context.ctx));
t.context.ctx.nextRelease = {version: '1.0.0'};
await t.notThrowsAsync(t.context.m.prepare(t.context.cfg, t.context.ctx));
await t.notThrowsAsync(t.context.m.verifyConditions(t.context.cfg, t.context.ctx));
const {cwd, nextRelease: {version: expected}} = t.context.ctx;
const {filepath} = t.context.cfg;
const {stdout: version} = await $`buildozer -root_dir ${cwd} ${'print version'} //${filepath}:%module`;
const {stdout: level} = await $`buildozer -root_dir ${cwd} ${'print compatibility_level'} //${filepath}:%module`;
t.is(version, expected);
const [major] = expected.split('.');
t.is(level, major);
if (after) {
await after(t);
......@@ -108,8 +120,8 @@ test('Throws `EBZLMODREAD` error when failed to read `.+`', failure, async t =>
await unlink(t.context.filepath);
});
test('Throws `EBZLMODMISSINGVERSION` error when `.+` `module.version` does not exist', failure, async t => {
await writeFile(t.context.filepath, '');
test('Throws `EBZLMODMISSINGMODULE` error when `.+` `module` does not exist', failure, async t => {
await writeFile(t.context.filepath, 'module()\nbazel_dep(name ="whatever", version = "0.0.0")');
});
test('Throws `EBZLMODWRITE` error when failed to write `.+`', failure, async t => {
......