Build and contribute

rego4k builds with Gradle and JDK 21. The first release will publish the modules to Maven Central in the group dev.rego4k.

The parser uses parser4k

The parser uses parser4k combinators, not a parser generator such as ANTLR. The grammar is Kotlin code that we can read, debug and step through.

If parser4k does not have a feature that we need, we add the feature to parser4k and do not work around the gap.

The file system shows the domain

A reader must see the concepts of rego4k from the names of its files and packages, before they read a line of code.

The code must be obviously correct

"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies." — C. A. R. Hoare

Much of rego4k was written by coding agents. This rule applies to them as much as to people.

The build enforces part of it:

Prose (KDoc, comments, Markdown, commit messages) is in Simplified Technical English. See AGENTS.md.

Build

sh
./gradlew check       # the tests (with the conformance suite), the warnings, and the unused-code check
./gradlew bench       # the benchmark; then build/bench/report.html
./gradlew benchGate   # the benchmark thresholds on every 10th case (about 6 minutes)
./gradlew pitest      # the mutation testing (slow); -Pmutate=rego4k.values.* for one package

The build needs JDK 21. settings.gradle.kts finds the modules: each directory with a build.gradle.kts is a module.

The convention plugins in gradle/plugins hold all the configuration that two or more modules share. Thus most module build files hold only dependencies. Configuration that only one module needs is in the build file of that module.

just

The justfile at the root holds the commands that we use most. Install just, for example with brew install just, and run just to see the list. Each recipe runs ./gradlew and needs only JDK 21.

sh
just demo              # the demo server with 5 policies and their examples: http://localhost:8181
just demo-image        # the image of the demo for Heroku, with Jib
just demo-debugger     # the debugger with its example policy, in your browser
just server ./bundle   # rego4k run --server on a bundle, with the debugger and without signed decisions
just lsp               # install the language server, and print the path of its start script
just cli               # build rego4k's command line, and print the path of its start script
just test-rego ./policies  # the Rego tests of the policies, as `opa test ./policies` runs them
just check             # ./gradlew check
just fuzz              # the fuzz gate; it downloads opa if .bench-tools has none
just bench             # the benchmark

Publishing

Nothing is on Maven Central yet. The first release will put the modules there.

Coordinates. Each module in modules has the coordinates dev.rego4k:rego4k-<module>:<version>. The demo (demo/) is an application, not a library, so it is not published.

gradle.properties holds the group (group) and the version (version). The group is the domain rego4k.dev, in reverse order.

A module publishes these files:

The BOM rego4k-bom names each module. The convention plugin published makes the publications.

To make the artifacts in a local Maven repository, run this command:

sh
./gradlew publishToMavenLocal -Dmaven.repo.local=/path/to/repository

Signing. The build signs the publications only if the Gradle property signingInMemoryKey is set. The value is an ASCII-armored PGP secret key. signingInMemoryKeyPassword is the password of the key.

A CI job gives them as the environment variables ORG_GRADLE_PROJECT_signingInMemoryKey and ORG_GRADLE_PROJECT_signingInMemoryKeyPassword. Without a key, the build does not sign.

The upload to the Central Portal

The Gradle plugin nmcp uploads the modules to the Central Portal (central.sonatype.com) with its Publisher API. published applies com.gradleup.nmcp to each module and to the BOM.

The BOM applies com.gradleup.nmcp.aggregation. It collects the BOM and each module that it names into one deployment:

The Portal validates the deployment, but it does not publish it (USER_MANAGED). A person examines the deployment in the Portal and publishes it. If nobody publishes a deployment, a person can drop it in the Portal.

The version of a release

Each release has a tag v<major>.<minor>.<patch>, for example v0.1.0. The workflow release finds the highest tag and increments the part that you choose: patch, minor or major. Without a tag, the first release is 0.1.0.

The build gets the version on the command line, for example -Pversion=0.1.0. The other builds use 0.1.0-SNAPSHOT from gradle.properties, and nobody changes it after a release.

Release

The workflow release (.github/workflows/release.yml) runs only by hand, on main. It runs ./gradlew check fuzzGate. Then it builds, signs and uploads the modules with the new version. If the upload succeeds, it pushes the tag of the version.

It needs these secrets of the repository:

If a secret is missing, the job fails before the checks. To release, do these steps:

  1. In GitHub, open Actions > release > Run workflow. Choose patch, minor or major, and click "Run workflow".
  2. Wait for the workflow release. The upload task waits until the Portal validates the deployment. The summary of the run gives the version.
  3. In the Central Portal, open "Publish" (the deployments). Examine the files and the checks of the new deployment.
  4. Click "Publish". The files are on Maven Central after approximately 10 to 30 minutes.
  5. Change the text that says that nothing is on Maven Central: site/content/home/release.md, "Get started" in the root README.md, modules/bom/README.md and the start of this section. Give the real version. Do this only after the first release.

If you drop a deployment in the Portal, its tag stays. The next release then increments that tag.

Licence

rego4k is under the Apache License, Version 2.0. See LICENSE.

Ideas to specify

These ideas are not designed yet. They are not part of the current work. The next step for each is a specification.

Lazy input and data, with a record of the reads

The idea. Define an InputSource<T>, similar to a JSON converter of Kondor. A property of the source names a property of the input. The source reads the value from a Kotlin object only when the policy reads it.

An InputSource is a special kind of Value. rego4k records each path into an InputSource that an evaluation actually reads.

The record is the base for a dirty check of a decision, as in a signals library such as alien-signals. A decision must be evaluated again only when a value that the policy actually read changes, not when any value in the scope of the input changes.

Questions to answer first:

The language server over a WebSocket, for an editor in the browser

Now. The language server runs only on the standard input and output, because a desktop editor starts it as a process.

The idea. An editor in the browser, for example Monaco (the editor of VS Code), cannot start a process. It connects to a language server over a WebSocket, and lsp4j has a module for this.

A WebSocket route in the server would give the debugger's editor completion, go-to-definition and diagnostics, with the same server as VS Code or IntelliJ.

Questions to answer first: