diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d174a56..0276f49 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,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 \ No newline at end of file diff --git a/examples/deno/.gitignore b/examples/deno/.gitignore new file mode 100644 index 0000000..7d821c8 --- /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 0000000..37ecd26 --- /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 0000000..8877a0c --- /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 0000000..e68db09 --- /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 9f3721d..a8fb234 100644 --- a/src/index.cjs +++ b/src/index.cjs @@ -1 +1 @@ -module.exports = require('./opa'); +module.exports = require("./opa");