Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deno example, separate build steps, update deno version #122

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 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,30 @@ jobs:
env:
OPA_CASES: test/cases/
OPA_TEST_CASES: testdata
- run: ./e2e.sh

examples-node:
name: NodeJS examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: infracost/setup-opa@v1
- uses: actions/setup-node@v2.5.1
with:
node-version: "12"
- name: nodejs
run: >
npm ci
npm run build
./e2e.sh

examples-deno:
name: Deno examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: infracost/setup-opa@v1
- uses: denoland/setup-deno@v1
with:
deno-version: v1.17.2
- 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");