diff --git a/.bcr/config.yaml b/.bcr/config.yaml deleted file mode 100644 index c5e4e201..00000000 --- a/.bcr/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -fixedReleaser: - login: "martis42" - email: "martis42.dev@gmail.com" diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json deleted file mode 100644 index 5e98de6b..00000000 --- a/.bcr/metadata.template.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "homepage": "https://github.com/martis42/depend_on_what_you_use", - "maintainers": [ - { - "name": "Martin Medler", - "email": "martis42.dev@gmail.com", - "github": "martis42" - } - ], - "repository": [ - "github:martis42/depend_on_what_you_use" - ], - "versions": [], - "yanked_versions": {} -} diff --git a/.bcr/source.template.json b/.bcr/source.template.json deleted file mode 100644 index 20374716..00000000 --- a/.bcr/source.template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "integrity": "", - "strip_prefix": "{REPO}-{VERSION}", - "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz" -} diff --git a/.github/workflows/prepare_release.py b/.github/workflows/prepare_release.py index 1978e2eb..8ddfef6d 100755 --- a/.github/workflows/prepare_release.py +++ b/.github/workflows/prepare_release.py @@ -16,6 +16,9 @@ RELEASE_NOTES_TEMPLATE = """ ## Using Bzlmod (Recommended) +> :construction: Not yet deployed to BCR :construction: +> Release will become usable via bzlmod as soon as it is no longer the pre-release phase. + Add to your `MODULE.bazel` file: ```starlark diff --git a/MODULE.bazel b/MODULE.bazel index 16f55095..f55ef603 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,5 +1,6 @@ module( name = "depend_on_what_you_use", + version = "0.0.0", # Keep in sync with setup_step_2.bzl bazel_compatibility = [">=5.4.0"], ) diff --git a/scripts/deploy_to_bcr.py b/scripts/deploy_to_bcr.py new file mode 100755 index 00000000..742083f9 --- /dev/null +++ b/scripts/deploy_to_bcr.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import subprocess +import sys +from pathlib import Path +from shutil import rmtree + +# No benefit for using logging, and we deliberately use '/tmp' which has no risk in this context +# ruff: noqa: T201n +# ruff: noqa: S108 + +BCR_DATA_TEMPLATE = """{{ + "build_file": null, + "build_targets": [], + "compatibility_level": "0", + "deps": [], + "module_dot_bazel": "{module_dot_bazel}", + "name": "depend_on_what_you_use", + "patch_strip": 0, + "patches": [], + "presubmit_yml": "{presubmit_dot_yml}", + "strip_prefix": "depend_on_what_you_use-{version}", + "test_module_build_targets": [], + "test_module_path": null, + "test_module_test_targets": [], + "url": "https://github.com/martis42/depend_on_what_you_use/releases/download/{version}/depend_on_what_you_use-{version}.tar.gz", + "version": "{version}" +}} +""" + +BCR_FORK_REPO = "git@github.com:martis42/bazel-central-registry-fork.git" +BCR_FORK_DIR = Path("/tmp/bcr_fork") + + +def get_dwyu_files() -> tuple[Path, Path]: + dwyu_dir = Path( + subprocess.run(["bazel", "info", "workspace"], capture_output=True, text=True, check=True).stdout.strip() + ) + print(f"Detected DWYU directory: '{dwyu_dir}'") + module_file = dwyu_dir / "MODULE.bazel" + presubmit_file = dwyu_dir / ".bcr/presubmit.yml" + + return module_file, presubmit_file + + +def setup_bcr_fork() -> None: + print(f"\nSetup BCR fork at '{BCR_FORK_DIR}'\n") + if BCR_FORK_DIR.exists(): + rmtree(BCR_FORK_DIR) + subprocess.run(["git", "clone", BCR_FORK_REPO, BCR_FORK_DIR], check=True) + + +def prepare_bcr_data(version: str) -> Path: + module, presubmit = get_dwyu_files() + + module_file_with_version = Path("/tmp/dwyu_with_version.MODULE.bazel") + with module.open(mode="rt", encoding="utf-8") as module_in: + module_content = module_in.read() + with module_file_with_version.open(mode="wt", encoding="utf-8") as module_out: + module_out.write(module_content.replace('version = "0.0.0",', f'version = "{version}",')) + + bcr_data = Path("/tmp/dwyu_bcr_data.json") + with bcr_data.open(mode="wt", encoding="utf-8") as bcr_data_out: + bcr_data_out.write( + BCR_DATA_TEMPLATE.format( + version=version, module_dot_bazel=module_file_with_version, presubmit_dot_yml=presubmit + ) + ) + + return bcr_data + + +def add_dwyu_to_bcr_fork(bcr_data: Path, version: str) -> None: + print(f"\n========= Adding DWYU '{version}' to BCR fork '{BCR_FORK_DIR}' =========\n") + + subprocess.run(["bazel", "run", "//tools:add_module", "--", "--input", bcr_data], cwd=BCR_FORK_DIR, check=True) + check_process = subprocess.run( + ["bazel", "run", "//tools:bcr_validation", "--", "--check", f"depend_on_what_you_use@{version}"], + cwd=BCR_FORK_DIR, + check=False, + ) + + print("\n================================================================================\n") + + if check_process.returncode in [ + 0, # All good + 42, # Check is fine, but a BCR maintainer will have to review + ]: + print(f"Successfully added DWYU '{version}' to the BCR fork") + else: + print(f"Adding DWYU '{version}' to the BCR fork failed. Look into the terminal output above to find the issue.") + sys.exit(1) + + +def push_to_upstream(version: str) -> None: + yn = input(f"\nDo you want to push DWYU '{version}' [y/n]: ") + if yn != "y": + print("Aborting") + sys.exit(0) + + print("\nPushing release to BCR\n") + + branch = f"depend_on_what_you_use@{version}" + subprocess.run(["git", "checkout", "-B", branch], cwd=BCR_FORK_DIR, check=True) + subprocess.run(["git", "add", "modules/depend_on_what_you_use/"], cwd=BCR_FORK_DIR, check=True) + subprocess.run(["git", "commit", "-m", f"depend_on_what_you_use@{version}"], cwd=BCR_FORK_DIR, check=True) + subprocess.run(["git", "push", "--set-upstream", "origin", branch], cwd=BCR_FORK_DIR, check=True) + + +def main() -> None: + version = input("To be released version: ") + print() + + bcr_data = prepare_bcr_data(version) + setup_bcr_fork() + add_dwyu_to_bcr_fork(bcr_data=bcr_data, version=version) + push_to_upstream(version) + + +if __name__ == "__main__": + main() diff --git a/scripts/release.md b/scripts/release.md new file mode 100644 index 00000000..02825340 --- /dev/null +++ b/scripts/release.md @@ -0,0 +1,22 @@ +# Semi automatic release process + +## Release creation + +1. `git tag VERSION` +1. `git push origin VERSION` +1. The CI will automatically create a draft PR +1. Check the release notes and fill manual sections +1. TODO do we have to set to 'pre-release', or can we continue with Draft for adding to BCR? + +## Adding to BCR + +1. Execute [scripts/deploy_to_bcr.py](/scripts/deploy_to_bcr.py) and provide version when asked for +1. Follow lnk in terminal and open PR on https://github.com/bazelbuild/bazel-central-registry + +## Finish release + +1. Wait until release is available via BCR +1. Make sure the release works via the [test repo](https://github.com/martis42/test_dwyu) +1. Finish release notes: + - Remove BCR warning + - Set to latest release