Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.5.0
8.6.0
Empty file added .bcr/config.yml
Empty file.
20 changes: 20 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"homepage": "https://github.com/hw-bzl/rules_chisel",
"maintainers": [
{
"name": "MrAMS",
"email": "25056812+MrAMS@users.noreply.github.com",
"github": "MrAMS",
"github_user_id": 25056812
},
{
"name": "UebelAndre",
"email": "26427366+UebelAndre@users.noreply.github.com",
"github": "UebelAndre",
"github_user_id": 26427366
}
],
"repository": ["github:hw-bzl/rules_chisel"],
"versions": [],
"yanked_versions": {}
}
17 changes: 17 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bcr_test_module:
module_path: ""
matrix:
platform:
- debian10
- ubuntu2004
- macos
bazel: [7.x, 8.x, 9.x]
tasks:
run_tests:
name: "Run tests"
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- "//..."
test_targets:
- "//..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "",
"strip_prefix": "",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{VERSION}/rules_chisel-{VERSION}.tar.gz"
}
Empty file added .bcr/tools/BUILD.bazel
Empty file.
14 changes: 14 additions & 0 deletions .bcr/tools/bzl_version/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@rules_python//python:py_test.bzl", "py_test")

py_test(
name = "version_test",
srcs = ["version_test.py"],
data = [
"//:MODULE.bazel",
"//:README.md",
"//:version.bzl",
],
deps = [
"@rules_python//python/runfiles",
],
)
87 changes: 87 additions & 0 deletions .bcr/tools/bzl_version/version_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""A suite of tests ensuring version strings are all in sync."""

import platform
import re
import unittest
from pathlib import Path

from python.runfiles import Runfiles

PKG_NAME = "rules_chisel"


def rlocation(runfiles: Runfiles, rlocationpath: str) -> Path:
"""Look up a runfile and ensure the file exists

Args:
runfiles: The runfiles object
rlocationpath: The runfile key

Returns:
The requested runfile.
"""
# TODO: https://github.com/periareon/rules_venv/issues/37
source_repo = None
if platform.system() == "Windows":
source_repo = ""
runfile = runfiles.Rlocation(rlocationpath, source_repo)
if not runfile:
raise FileNotFoundError(f"Failed to find runfile: {rlocationpath}")
path = Path(runfile)
if not path.exists():
raise FileNotFoundError(f"Runfile does not exist: ({rlocationpath}) {path}")
return path


class RepoVersionTests(unittest.TestCase):
"""Test that the `{PKG_NAME}` versions match in version.bzl, MODULE.bazel, and README.md."""

def test_versions(self) -> None:
"""Test that the version.bzl and MODULE.bazel versions are synced."""
runfiles = Runfiles.Create()
if not runfiles:
raise EnvironmentError("Failed to locate runfiles.")

version_bzl = rlocation(runfiles, f"{PKG_NAME}/version.bzl")
bzl_version = re.findall(
r'VERSION = "([\w\d\.]+)"',
version_bzl.read_text(encoding="utf-8"),
re.MULTILINE,
)
self.assertTrue(bzl_version, f"Failed to parse version from {version_bzl}")
self.assertTrue(
len(bzl_version) == 1,
(f"Expect len(bzl_version)=1, but got {len(bzl_version)}"),
)

bzl_version = bzl_version[0]

module_bazel = rlocation(runfiles, f"{PKG_NAME}/MODULE.bazel")
module_versions = re.findall(
rf'module\(\n\s+name = "{re.escape(PKG_NAME)}",\n\s+version = "([\d\w\.]+)",\n',
module_bazel.read_text(encoding="utf-8"),
re.MULTILINE,
)
self.assertTrue(module_versions, f"Failed to parse version from {module_bazel}")

readme_bazel = rlocation(runfiles, f"{PKG_NAME}/README.md")
readme_versions = re.findall(
rf'bazel_dep\(\s*name\s*=\s*"{re.escape(PKG_NAME)}",\s*version\s*=\s*"([\d\w\.]+)"\s*\)',
readme_bazel.read_text(encoding="utf-8"),
re.MULTILINE,
)
# allow readme_versions is empty

self.assertTrue(
all(e == bzl_version for e in module_versions),
("Version in MODULE.bazel does not match"),
)

self.assertTrue(
all(e == bzl_version for e in readme_versions),
("Version in README.md does not match"),
)


if __name__ == "__main__":
unittest.main()
Empty file added .codex
Empty file.
11 changes: 11 additions & 0 deletions .github/release_notes.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# {version}

To start using this module, make sure you have set up Bzlmod according to the [user guide](https://bazel.build/docs/bzlmod), and add the following to your MODULE.bazel file:

```python
bazel_dep(name = "rules_chisel", version = "{version}")
```

Additional documentation can be found at: https://github.com/hw-bzl/rules_chisel

SHA256: `{sha256_base64}`
44 changes: 44 additions & 0 deletions .github/workflows/bcr-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# See https://github.com/bazel-contrib/publish-to-bcr
name: Publish to BCR

on:
# Allow the publish workflow to be called from another workflow.
# In this case, we trigger it from the release.yaml workflow.
workflow_call:
inputs:
release_version:
required: true
type: string
secrets:
BCR_PUBLISH_TOKEN:
required: true
# In case of problems, let release engineers retry by manually dispatching
# the workflow from the GitHub UI.
workflow_dispatch:
inputs:
release_version:
required: true
type: string
description: Release version to publish to the Bazel Central Registry
templates_ref:
default: ''
type: string
description: Override the ref to read .bcr templates from
jobs:
publish:
uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.1.0
with:
attest: false
tag_name: ${{ inputs.release_version }}
author_name: periareon-bot
author_email: 260522848+periareon-bot@users.noreply.github.com
# Tags don't include a "v" prefix
tag_prefix: ""
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
registry_fork: hw-bzl/bazel-central-registry
templates_ref: ${{ inputs.templates_ref || inputs.release_version }}
draft: false
permissions:
contents: write
secrets:
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}
29 changes: 15 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ name: CI

on:
push:
paths-ignore:
- "**.md"
- "LICENSE"
branches:
- main
- master
pull_request:

jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
name: ${{ matrix.os }} / Bazel ${{ matrix.bazel-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
bazel-version: ["7.*", "8.*", "9.*"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.15.0
uses: bazel-contrib/setup-bazel@0.9.0
with:
bazelisk-version: "1.x"
bazelisk-cache: true
repository-cache: true
disk-cache: ${{ github.workflow }}-${{ matrix.os }}-${{ matrix.bazel-version }}

- name: Build all targets
run: bazel build //...

- name: Run tests
- name: Run all tests
env:
USE_BAZEL_VERSION: ${{ matrix.bazel-version }}
run: bazel test //... --test_output=errors

- name: Run Chisel version compatibility checks
run: tests/version_compat/check_chisel_versions.sh
9 changes: 7 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Lint

on:
push:
branches:
- main
- master
pull_request:

jobs:
Expand All @@ -13,8 +16,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- run: |
- name: Install buildifier
run: |
sudo wget https://github.com/bazelbuild/buildtools/releases/download/${{ env.BUILDIFIER_VERSION }}/buildifier-linux-amd64 -O /usr/local/bin/buildifier
sudo chmod +x /usr/local/bin/buildifier

- run: buildifier -lint=warn -mode=check -warnings=all -r .
- name: Check formatting
run: buildifier -lint=warn -mode=check -warnings=all -r .
77 changes: 77 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
name: Release
on:
workflow_dispatch:
push:
branches:
- main
paths:
# Only trigger for new releases
- "version.bzl"

defaults:
run:
shell: bash

jobs:
release:
if: ${{ github.repository_owner == 'hw-bzl' }}
permissions:
contents: write
actions: write
attestations: write
outputs:
release_version: ${{ steps.version.outputs.release_version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Detect the current version
id: version
run: |
version="$(grep 'VERSION =' ./version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
echo "release_version=${version}" >> $GITHUB_OUTPUT

- name: Create release artifact
id: artifact
run: |
tar -czf ${{ github.workspace }}/.github/rules_chisel.tar.gz --exclude=".git" --exclude=".github" -C ${{ github.workspace }} .
sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_chisel.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)"
echo "ARCHIVE_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV
echo "sha256=${sha256_base64}" >> $GITHUB_OUTPUT

- name: Generate release notes
run: |
sed "s/{version}/$RELEASE_VERSION/g" ${{ github.workspace }}/.github/release_notes.template \
| sed "s#{sha256_base64}#$ARCHIVE_SHA256_BASE64#g" \
> ${{ github.workspace }}/.github/release_notes.txt

- name: "Prepare and Upload Release"
run: |
mv ${{ github.workspace }}/.github/rules_chisel.tar.gz \
${{ github.workspace }}/.github/rules_chisel-$RELEASE_VERSION.tar.gz

- name: "Release and Upload Assets"
uses: softprops/action-gh-release@v2
id: rules_release
with:
tag_name: ${{ steps.version.outputs.release_version }}
target_commitish: ${{ github.sha }}
body_path: ${{ github.workspace }}/.github/release_notes.txt
generate_release_notes: true
files: |
${{ github.workspace }}/.github/rules_chisel-${{ steps.version.outputs.release_version }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bcr-publish:
needs: [release]
permissions:
contents: write
uses: ./.github/workflows/bcr-publish.yaml
with:
release_version: ${{ needs.release.outputs.release_version }}
secrets:
BCR_PUBLISH_TOKEN: ${{ secrets.BCR_PUBLISH_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bazel-*
user.bazelrc
.metals/
AGENT.md
MODULE.bazel.lock
21 changes: 6 additions & 15 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2026
#
# 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.

load("@rules_license//rules:license.bzl", "license")

package(
Expand All @@ -26,4 +12,9 @@ license(

licenses(["notice"])

exports_files(["LICENSE"])
exports_files([
"LICENSE",
"MODULE.bazel",
"version.bzl",
"README.md",
])
Loading
Loading