-
Notifications
You must be signed in to change notification settings - Fork 579
docs: tell authors how to publish stardocs #6209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,61 @@ | ||
| # Starlark API Documentation | ||
|
|
||
| Modules that expose Starlark APIs (rulesets, for example) may choose to publish documentation as a reference URL on releases. | ||
|
|
||
| Read more about this feature: https://blog.aspect.build/stardocs-on-bcr | ||
|
|
||
| ## Generating API docs | ||
|
|
||
| The built-in rule [starlark_doc_extract](https://bazel.build/versions/8.3.0/reference/be/general#starlark_doc_extract) outputs `.binaryproto` files containing `stardoc_output.ModuleInfo` messages. | ||
|
|
||
| - Source: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/stardoc_output.proto | ||
| - Docs: https://buf.build/bazel/bazel/docs/main:stardoc_output#stardoc_output.ModuleInfo | ||
|
|
||
| Authors are free to generate these files however they choose. | ||
| The simplest option is to add a `starlark_doc_extract` target for each `bzl_library` target you wish to document. | ||
|
|
||
| Note that the `bzl_library` rule from `bazel_skylib` has `filegroup` semantics - it doesn't produce any outputs, nor verify that the `bzl_library` has all dependencies provided. | ||
| See https://github.com/bazel-contrib/bazel-lib/blob/main/bzl_library.bzl for an alternative that fixes this. | ||
|
|
||
| It is wise to run `bazel query 'kind(starlark_doc_extract, //...)'` to confirm which starlark modules your ruleset documents. | ||
|
|
||
| ## Creating the docs artifact | ||
|
|
||
| Users of the Publish-to-BCR workflow have an existing `.github/workflows/release_prep.sh` script. | ||
| In this case you can simply add a snippet to create an archive file containing the stardoc output: | ||
|
|
||
| ```bash | ||
| # Add generated API docs to the release, see https://github.com/bazelbuild/bazel-central-registry/issues/5593 | ||
| docs="$(mktemp -d)"; targets="$(mktemp)" | ||
| bazel --output_base="$docs" query --output=label --output_file="$targets" 'kind("starlark_doc_extract rule", //...)' | ||
| bazel --output_base="$docs" build --target_pattern_file="$targets" | ||
| tar --create --auto-compress \ | ||
| --directory "$(bazel --output_base="$docs" info bazel-bin)" \ | ||
| --file "$GITHUB_WORKSPACE/${ARCHIVE%.tar.gz}.docs.tar.gz" . | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
| > The `--output_file` flag was added in Bazel 7.5.0 | ||
|
|
||
| Of course authors are free to produce the docs archive using a different technique. | ||
|
|
||
| ## Publishing the docs | ||
|
|
||
| Again, we assume use of Publish-to-BCR. | ||
|
|
||
| Edit `.bcr/source.template.json` to include a link, such as | ||
|
|
||
| ```json | ||
| { | ||
| ... | ||
| "docs_url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.docs.tar.gz", | ||
| } | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
| > publish-to-bcr version v0.2.3 or greater is required to pick up a fix for multiple replacements in source.template.json | ||
|
|
||
| ## Rendered docs | ||
|
|
||
| The https://registry.bazel.build site renders stardocs for modules that have published them. | ||
| The code for that site is in https://github.com/bazel-contrib/bcr-ui. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.