From 437e68da36a928b1ffba7aadceb8b94decdfb8bc Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Thu, 9 Jan 2025 14:45:51 +0000 Subject: [PATCH] test the Readme in CI --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ .gitignore | 2 ++ Readme.md | 22 ++++++++++++++++++++-- Readme.result | 1 + 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 Readme.result diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e462fa..ed3d351 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index 895a237..e0ec41a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ target .idea testcases.tar.gz +policy.wasm +TestReadme.result diff --git a/Readme.md b/Readme.md index e51d814..9c97bf7 100644 --- a/Readme.md +++ b/Readme.md @@ -29,6 +29,18 @@ With Maven add the core module dependency: ``` + + ## Usage There are only a couple of steps required to start evaluating the policy. @@ -36,7 +48,7 @@ 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 @@ -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); ``` + + > 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/) diff --git a/Readme.result b/Readme.result new file mode 100644 index 0000000..94abeb8 --- /dev/null +++ b/Readme.result @@ -0,0 +1 @@ +[{"result":false}]