diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d174a56b..07ffeb80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/examples/deno/.gitignore b/examples/deno/.gitignore new file mode 100644 index 00000000..7d821c89 --- /dev/null +++ b/examples/deno/.gitignore @@ -0,0 +1 @@ +test.wasm diff --git a/examples/deno/Makefile b/examples/deno/Makefile new file mode 100644 index 00000000..37ecd260 --- /dev/null +++ b/examples/deno/Makefile @@ -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 \ No newline at end of file diff --git a/examples/deno/main.ts b/examples/deno/main.ts new file mode 100644 index 00000000..8877a0c6 --- /dev/null +++ b/examples/deno/main.ts @@ -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); +} diff --git a/examples/deno/test.rego b/examples/deno/test.rego new file mode 100644 index 00000000..e68db09c --- /dev/null +++ b/examples/deno/test.rego @@ -0,0 +1,5 @@ +package test + +p { + input.foo == "bar" +} \ No newline at end of file diff --git a/src/index.cjs b/src/index.cjs index 9f3721dd..a8fb2342 100644 --- a/src/index.cjs +++ b/src/index.cjs @@ -1 +1 @@ -module.exports = require('./opa'); +module.exports = require("./opa");