Skip to content

Commit 2906af7

Browse files
authored
Add deno example, separate build steps, update deno version (#122)
Using deno was enabled by #110. Signed-off-by: Stephan Renatus <[email protected]>
1 parent 653ea5f commit 2906af7

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

.github/workflows/ci.yml

+28-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313
- uses: denoland/setup-deno@v1
1414
with:
15-
deno-version: v1.15.0
15+
deno-version: v1.17.2
1616
- uses: actions/checkout@v2
1717
- run: deno fmt --check
1818
- run: deno lint
@@ -71,4 +71,30 @@ jobs:
7171
env:
7272
OPA_CASES: test/cases/
7373
OPA_TEST_CASES: testdata
74-
- run: ./e2e.sh
74+
75+
examples-node:
76+
name: NodeJS examples
77+
runs-on: ubuntu-latest
78+
steps:
79+
- uses: actions/checkout@v2
80+
- uses: infracost/setup-opa@v1
81+
- uses: actions/[email protected]
82+
with:
83+
node-version: "12"
84+
- name: nodejs
85+
run: >
86+
npm ci
87+
npm run build
88+
./e2e.sh
89+
90+
examples-deno:
91+
name: Deno examples
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/checkout@v2
95+
- uses: infracost/setup-opa@v1
96+
- uses: denoland/setup-deno@v1
97+
with:
98+
deno-version: v1.17.2
99+
- run: make
100+
working-directory: examples/deno

examples/deno/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.wasm

examples/deno/Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: build run
2+
3+
build: test.wasm
4+
5+
test.wasm: test.rego
6+
opa build -t wasm -e test/p $<
7+
tar zxvf bundle.tar.gz /policy.wasm
8+
mv policy.wasm test.wasm
9+
touch test.wasm
10+
rm bundle.tar.gz
11+
12+
run:
13+
deno run --allow-read=test.wasm main.ts

examples/deno/main.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import opa from "https://unpkg.com/@open-policy-agent/[email protected]/dist/opa-wasm-browser.esm.js";
2+
3+
const file = await Deno.readFile("test.wasm");
4+
const policy = await opa.loadPolicy(file.buffer.slice(0, file.length));
5+
const input = { "foo": "bar" };
6+
7+
const result = policy.evaluate(input);
8+
9+
if (!result[0]?.result) {
10+
Deno.exit(1);
11+
}

examples/deno/test.rego

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test
2+
3+
p {
4+
input.foo == "bar"
5+
}

src/index.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./opa');
1+
module.exports = require("./opa");

0 commit comments

Comments
 (0)