diff --git a/.github/workflows/spawn_examples.yml b/.github/workflows/spawn_examples.yml deleted file mode 100644 index a8c6a179c..000000000 --- a/.github/workflows/spawn_examples.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Spawn Examples -on: - workflow_dispatch: - pull_request: - push: - branches: - - main -jobs: - generate_example_paths: - name: Generate example paths - runs-on: ubuntu-latest - outputs: - example_paths: ${{ steps.generate_example_paths.outputs.example_paths }} - steps: - - uses: actions/checkout@v3 - - name: Setup fd-find - uses: ./.github/actions/setup-fd-find - - id: generate_example_paths - run: | - fd --print0 --glob "*.ts" ./examples | jq -Rnc '(input | split("\u0000"))' > example_paths.json - example_paths=`cat example_paths.json` - echo "example_paths=$example_paths" >> $GITHUB_OUTPUT - run_example_workflow: - needs: generate_example_paths - name: Run examples - uses: ./.github/workflows/example.yml - with: - example_paths: ${{ needs.generate_example_paths.outputs.example_paths }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da8904bc3..53953b587 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,4 +18,4 @@ jobs: - run: deno lint - run: deno task codegen - run: deno task star - - run: deno task test + - run: deno task test:ci diff --git a/deno.jsonc b/deno.jsonc index fbff8f1b8..29ca9e228 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -36,6 +36,7 @@ "star": "deno task run _tasks/star.ts && deno cache --check target/star.ts", "codegen": "deno task run cache.ts examples/mod.ts", "test": "deno task run test_util/ctx.ts -- deno test -A -L=info --ignore=target --parallel", + "test:ci": "ENV_TYPE_CI=1 deno task test", "test:update": "deno task test -- -- --update", "bench": "deno bench -A", "moderate": "deno task run https://deno.land/x/moderate@0.0.5/mod.ts && dprint fmt" diff --git a/deps/run_with_limit.ts b/deps/run_with_limit.ts new file mode 100644 index 000000000..e1258b2b7 --- /dev/null +++ b/deps/run_with_limit.ts @@ -0,0 +1 @@ +export * from "https://deno.land/x/run_with_limit@v1.0.1/mod.ts" diff --git a/deps/std/io.ts b/deps/std/io.ts new file mode 100644 index 000000000..0328cb286 --- /dev/null +++ b/deps/std/io.ts @@ -0,0 +1 @@ +export * from "https://deno.land/std@0.172.0/io/mod.ts" diff --git a/deps/std/streams.ts b/deps/std/streams.ts new file mode 100644 index 000000000..6f625b942 --- /dev/null +++ b/deps/std/streams.ts @@ -0,0 +1 @@ +export * from "https://deno.land/std@0.172.0/streams/mod.ts" diff --git a/examples/.ignore b/examples/.ignore index c941fcc58..302b3aa7d 100644 --- a/examples/.ignore +++ b/examples/.ignore @@ -2,3 +2,4 @@ mod.ts multisig_transfer.ts smart_contract.ts xcm_teleport_assets.ts +examples.test.ts diff --git a/examples/examples.test.ts b/examples/examples.test.ts new file mode 100644 index 000000000..3a233b1df --- /dev/null +++ b/examples/examples.test.ts @@ -0,0 +1,61 @@ +import * as path from "http://localhost:5646/@local/deps/std/path.ts" +import { makeRunWithLimit } from "../deps/run_with_limit.ts" +import { Buffer, readLines } from "../deps/std/io.ts" +import { writeAll } from "../deps/std/streams.ts" +import { assert } from "../deps/std/testing/asserts.ts" + +const IS_CI = Deno.env.get("ENV_TYPE_CI") ? true : false + +const { runWithLimit } = makeRunWithLimit(navigator.hardwareConcurrency) + +function getModuleDir(importMeta: ImportMeta): string { + return path.resolve(path.dirname(path.fromFileUrl(importMeta.url))) +} + +async function pipeThrough( + reader: Deno.Reader, + writer: Deno.Writer, +) { + const encoder = new TextEncoder() + for await (const line of readLines(reader)) { + await writeAll(writer, encoder.encode(`${line}\n`)) + } +} + +const ignoreFile = await Deno.readTextFile(path.join(getModuleDir(import.meta), ".ignore")) +const ignoredFiles = new Set(ignoreFile.split("\n")) + +const exampleFileNames = Array.from(Deno.readDirSync(getModuleDir(import.meta))) + .filter((e) => e.name.match(/^.*\.ts$/g) && e.isFile && !ignoredFiles.has(e.name)) + .map((f) => f.name) + +const exampleTasks = IS_CI + ? exampleFileNames.map((fileName) => + runWithLimit(async () => { + const t = Deno.run({ + cmd: ["deno", "task", "run", `${getModuleDir(import.meta)}/${fileName}`], + stdout: "piped", + stderr: "piped", + }) + + const out = new Buffer() + pipeThrough(t.stdout, out) + pipeThrough(t.stderr, out) + + const status = await t.status() + + t.close() + + return Deno.test({ + name: fileName, + async fn() { + await pipeThrough(out, Deno.stdout) + assert(status.code === 0, `task failed with status code: ${status.code}`) + assert(status.success, `unsuccessful`) + }, + }) + }) + ) + : [] + +await Promise.all(exampleTasks)