Skip to content

Commit d4f6dd7

Browse files
committed
test the Readme in CI
1 parent 0d90ba9 commit d4f6dd7

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

.github/workflows/ci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,29 @@ jobs:
7272
if: success() || failure() # always run even if the previous step fails
7373
with:
7474
report_paths: '**/target/surefire-reports/TEST-*.xml'
75+
76+
readme-ci:
77+
runs-on: ubuntu-latest
78+
name: CI - Readme
79+
steps:
80+
- name: checkout
81+
uses: actions/checkout@v4
82+
- name: Set up Java
83+
uses: actions/setup-java@v4
84+
with:
85+
distribution: 'temurin'
86+
java-version: '17'
87+
cache: maven
88+
- name: Build Opa Java Wasm
89+
run: mvn clean install -DskipTests
90+
env:
91+
MAVEN_OPTS: "-Dmaven.repo.local=${{ github.workspace }}/repository"
92+
# Test root Readme
93+
- name: jbang
94+
uses: jbangdev/jbang-action@9f8c55e0a2b6b297711162b20c209c5e07076e59 # tag=v0.117.1
95+
with:
96+
script: Readme.md
97+
env:
98+
JBANG_REPO: "${{ github.workspace }}/repository"
99+
- name: compare results
100+
run: diff -r Readme.result TestReadme.result

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
target
22
.idea
33
testcases.tar.gz
4+
policy.wasm
5+
TestReadme.result

Readme.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,26 @@ With Maven add the core module dependency:
2929
</dependency>
3030
```
3131

32+
<!--
33+
```java
34+
//DEPS com.styra.opa:opa-java-wasm:999-SNAPSHOT
35+
36+
var policyPath = Path.of("core/src/main/resources/demo-policy.wasm");
37+
var targetPath = Path.of("policy.wasm");
38+
Files.copy(policyPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
39+
40+
var policyWasm = new File("policy.wasm");
41+
```
42+
-->
43+
3244
## Usage
3345

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

3648
### Import the module
3749

3850
```java
39-
import com.styra.opa.wasm.Opa;
51+
import com.styra.opa.wasm.OpaPolicy;
4052
```
4153

4254
### Load the policy
@@ -71,13 +83,19 @@ APIs for policy evaluation:
7183
Example:
7284

7385
```java
74-
input = '{"path": "/", "role": "admin"}';
86+
var input = "{\"path\": \"/\", \"role\": \"admin\"}";
7587

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

93+
<!--
94+
```java
95+
Files.write(Paths.get("TestReadme.result"), (result + "\n").getBytes());
96+
```
97+
-->
98+
8199
> For any `opa build` created WASM binaries the result set, when defined, will
82100
> contain a `result` key with the value of the compiled entrypoint. See
83101
> [https://www.openpolicyagent.org/docs/latest/wasm/](https://www.openpolicyagent.org/docs/latest/wasm/)

Readme.result

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"result":false}]

0 commit comments

Comments
 (0)