Skip to content
README.md 3.92 KiB
Newer Older
# `semantic-release/bzlmod`
Matthew Clarkson's avatar
Matthew Clarkson committed

> A `semantic-release` plugin to update the Bazel module version specified in `MODULE.bazel`.
Matthew Clarkson's avatar
Matthew Clarkson committed

Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
| Step | Description |
| ---- | ----------- |
| verifyConditions | Verify that `MODULE.bazel` exists, `module.version` is specified in it and is writable. |
| prepare | Updates the version specified by `module.version` following semantic versioning. |
Matthew Clarkson's avatar
Matthew Clarkson committed

Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
## Getting Started
Matthew Clarkson's avatar
Matthew Clarkson committed

Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
```sh
npm config --location project set registry https://gitlab.arm.com/api/v4/groups/semantic-release/-/packages/npm/
npm install --save-dev @semantic-release/bzlmod
Matthew Clarkson's avatar
Matthew Clarkson committed
```

Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
Add the following to `.releaserc.yaml`:
Matthew Clarkson's avatar
Matthew Clarkson committed

Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
```yaml
plugins:
  - "@semantic-release/bzlmod"
```
Matthew Clarkson's avatar
Matthew Clarkson committed

Matthew Clarkson's avatar
Matthew Clarkson committed
## Usage
Matthew Clarkson's avatar
Matthew Clarkson committed

Matthew Clarkson's avatar
Matthew Clarkson committed
### Version Bumps
Matthew Clarkson's avatar
Matthew Clarkson committed

Matthew Clarkson's avatar
Matthew Clarkson committed
The plugin will update the `MODULE.bazel` with the next release version.
Matthew Clarkson's avatar
Matthew Clarkson committed
This is required by [bzlmod] to make sure that the `version` keyword in the `module()` definitions mirrors the actual project version.
Matthew Clarkson's avatar
Matthew Clarkson committed

Matthew Clarkson's avatar
Matthew Clarkson committed
To configure this scenario, combine the plugin with the `@semantic-release/git` plugin to add the version update to the release branch:
Matthew Clarkson's avatar
Matthew Clarkson committed

Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
```yaml
plugins:
Matthew Clarkson's avatar
Matthew Clarkson committed
  - "@semantic-release/bzlmod"
  - path: "@semantic-release/git"
    assets:
      - MODULE.bazel
Zhen Yuen Chong's avatar
Zhen Yuen Chong committed
```
Matthew Clarkson's avatar
Matthew Clarkson committed

Matthew Clarkson's avatar
Matthew Clarkson committed
### `source.json` and archive generation
Matthew Clarkson's avatar
Matthew Clarkson committed
`bzlmod` expects to download source archives from a central registry.
Matthew Clarkson's avatar
Matthew Clarkson committed
It does this by looking for a `modules/${name}/${version}/source.json` at the provided `bazel --registry` argument(s).

However, this leads to an unfortunate release cycle:

- Perform release of project with `semantic-release/bzlmod`
- Create a merge request for an `bzlmod` registry such as the [BCR][bcr]
- Once merged, use the release

This can create a huge amount of churn, especially when performing pre-release `alpha`/`beta` releases.

The plugin has a secondary mode when it can generate an archive and `source.json` for the project.

The archive and `source.json` can be uploaded as release assets with `@semantic-release/gitlab` (or similar).
Matthew Clarkson's avatar
Matthew Clarkson committed
To configure this scenario, the plugin will be used a _second_ time (after the version bump):
  - "@semantic-release/bzlmod"
  - path: "@semantic-release/git"
    assets:
      - MODULE.bazel
  - path: "@semantic-release/bzlmod"
    source:
      prefix: ${CI_PROJECT_NAME}-v${version}
      url: ${CI_PROJECT_URL}/-/releases/v${version}/downloads/src.tar.gz
  - path: "@semantic-release/gitlab"
      - path: MODULE.bazel
        type: package
        filepath: /modules/${env.CI_PROJECT_NAME}/${nextRelease.version}/MODULE.bazel
      - path: source.json
        type: package
        filepath: /modules/${env.CI_PROJECT_NAME}/${nextRelease.version}/source.json
      - path: src.tar.gz
Matthew Clarkson's avatar
Matthew Clarkson committed
        type: package
      - path: metadata.json
        type: package
        filepath: /modules/${env.CI_PROJECT_NAME}/metadata.json
Matthew Clarkson's avatar
Matthew Clarkson committed
`bzlmod` can then be pointed directly at the GitLab release to use the project. This negates the need to upload all released versions to a `bzlmod` registry.

Set the `--registry` to the release URL (`${CI_PROJECT_URL}/-/releases/v${version}`).

## Configuration

By default the plugin will locate `MODULE.bazel` in the current package root `.`

### `filepath`

The path to `MODULE.bazel` can be specified in the plugin configuration. 

For example, to specify `MODULE.bazel` in `./custom/`, do:

```yaml
plugins:
  - path: "@semantic-release/bzlmod"
    filepath:
      - "./custom/MODULE.bazel"
```

### `source`

The plugin can automatically create a `source.json` which can be used to integrate with `bzlmod`.

It *must* be performed _after_ the `@semantic-release/git` to generate the correct integrity for the source tarball.

The `prefix`, `archive` and `url` must be specified which can use environment variables.
Matthew Clarkson's avatar
Matthew Clarkson committed
Often the `source` keywords use the CI environment keywords to point the `source.json` back to a release within the version control system being used (GitLab, GitHub, etc).

[bzlmod]: https://bazel.build/build/bzlmod
Matthew Clarkson's avatar
Matthew Clarkson committed
[bcr]: https://github.com/bazelbuild/bazel-central-registry