Skip to content

Commit

Permalink
test the Readme in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Jan 9, 2025
1 parent d37dcea commit 437e68d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,29 @@ jobs:
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/target/surefire-reports/TEST-*.xml'

readme-ci:
runs-on: ubuntu-latest
name: CI - Readme
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: maven
- name: Build Opa Java Wasm
run: mvn clean install -DskipTests
env:
MAVEN_OPTS: "-Dmaven.repo.local=${{ github.workspace }}/repository"
# Test root Readme
- name: jbang
uses: jbangdev/jbang-action@9f8c55e0a2b6b297711162b20c209c5e07076e59 # tag=v0.117.1
with:
script: Readme.md
env:
JBANG_REPO: "${{ github.workspace }}/repository"
- name: compare results
run: diff -r Readme.result TestReadme.result
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target
.idea
testcases.tar.gz
policy.wasm
TestReadme.result
22 changes: 20 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@ With Maven add the core module dependency:
</dependency>
```

<!--
```java
//DEPS com.styra.opa:opa-java-wasm:999-SNAPSHOT
var policyPath = Path.of("core/src/main/resources/demo-policy.wasm");
var targetPath = Path.of("policy.wasm");
Files.copy(policyPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
var policyWasm = new File("policy.wasm");
```
-->

## Usage

There are only a couple of steps required to start evaluating the policy.

### Import the module

```java
import com.styra.opa.wasm.Opa;
import com.styra.opa.wasm.OpaPolicy;
```

### Load the policy
Expand Down Expand Up @@ -71,13 +83,19 @@ APIs for policy evaluation:
Example:

```java
input = '{"path": "/", "role": "admin"}';
var input = "{\"path\": \"/\", \"role\": \"admin\"}";

var policy = OpaPolicy.builder().withPolicy(policyWasm).build();
var result = policy.evaluate(input);
System.out.println("Result is: " + result);
```

<!--
```java
Files.write(Paths.get("TestReadme.result"), (result + "\n").getBytes());
```
-->

> For any `opa build` created WASM binaries the result set, when defined, will
> contain a `result` key with the value of the compiled entrypoint. See
> [https://www.openpolicyagent.org/docs/latest/wasm/](https://www.openpolicyagent.org/docs/latest/wasm/)
Expand Down
1 change: 1 addition & 0 deletions Readme.result
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"result":false}]

0 comments on commit 437e68d

Please sign in to comment.