Skip to content

Commit

Permalink
Add deno example, separate build steps, update deno version
Browse files Browse the repository at this point in the history
Using deno was enabled by
#110.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed Jan 10, 2022
1 parent 653ea5f commit ac952fc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.15.0
deno-version: v1.17.2
- uses: actions/checkout@v2
- run: deno fmt --check
- run: deno lint
Expand Down Expand Up @@ -71,4 +71,22 @@ jobs:
env:
OPA_CASES: test/cases/
OPA_TEST_CASES: testdata
- run: ./e2e.sh

examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Open Policy Agent (latest))
uses: infracost/setup-opa@v1
- name: Use Node.js (12)
uses: actions/setup-node@v2.5.1
with:
node-version: "12"
- uses: denoland/setup-deno@v1
with:
deno-version: v1.17.2
- name: nodejs
run: ./e2e.sh
- name: deno
run: make
working-directory: examples/deno
1 change: 1 addition & 0 deletions examples/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.wasm
13 changes: 13 additions & 0 deletions examples/deno/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: build run

build: test.wasm

test.wasm: test.rego
opa build -t wasm -e test/p $<
tar zxvf bundle.tar.gz /policy.wasm
mv policy.wasm test.wasm
touch test.wasm
rm bundle.tar.gz

run:
deno run --allow-read=test.wasm main.ts
11 changes: 11 additions & 0 deletions examples/deno/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import opa from "https://unpkg.com/@open-policy-agent/opa-wasm@1.6.0/dist/opa-wasm-browser.esm.js";

const file = await Deno.readFile("test.wasm");
const policy = await opa.loadPolicy(file.buffer.slice(0, file.length));
const input = { "foo": "bar" };

const result = policy.evaluate(input);

if (!result[0]?.result) {
Deno.exit(1);
}
5 changes: 5 additions & 0 deletions examples/deno/test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test

p {
input.foo == "bar"
}
2 changes: 1 addition & 1 deletion src/index.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./opa');
module.exports = require("./opa");

0 comments on commit ac952fc

Please sign in to comment.