diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..142cbb8 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..78fa441 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: Release +on: + release: + types: + - created +jobs: + publish: + name: Build & Publish to NPM + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.1 + with: + deno-version: v1.x + - name: Retrieve Version + if: startsWith(github.ref, 'refs/tags/') + id: get_tag_version + run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//} + - uses: actions/setup-node@v3 + with: + node-version: "16.x" + registry-url: "https://registry.npmjs.org" + - name: Build NPM Package + run: deno run -A --no-check=remote ./_tasks/dnt.ts ${{steps.get_tag_version.outputs.TAG_VERSION}} + - run: npm pack + working-directory: "./target/npm_pkg/" + - uses: actions/upload-artifact@v3 + with: + name: package + path: "./target/npm_pkg/*.tgz" + - uses: octokit/request-action@v2.x + if: startsWith(github.ref, 'refs/tags/') + with: + route: POST /repos/paritytech/npm_publish_automation/actions/workflows/publish.yml/dispatches + ref: main + inputs: '${{ format(''{{ "repo": "{0}", "run_id": "{1}" }}'', github.repository, github.run_id) }}' + env: + GITHUB_TOKEN: ${{ secrets.NPM_PUBLISH_AUTOMATION_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6c0a271 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,18 @@ +name: Test +on: push +jobs: + test: + name: Run Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.1 + with: + deno-version: v1.x + - name: Download wabt + run: | + curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.30/wabt-1.0.30-ubuntu.tar.gz | tar -xz -C ~ + echo "$HOME/wabt-1.0.30/bin" >> $GITHUB_PATH + - run: deno task star + - run: deno task build --check + - run: deno task test diff --git a/_tasks/build.ts b/_tasks/build.ts index 70c487e..3376de7 100644 --- a/_tasks/build.ts +++ b/_tasks/build.ts @@ -1,12 +1,23 @@ +import * as flags from "https://deno.land/std@0.163.0/flags/mod.ts" import * as path from "https://deno.land/std@0.163.0/path/mod.ts" +import { assertEquals } from "https://deno.land/std@0.163.0/testing/asserts.ts" import { encodeHex } from "../util.ts" +const { check } = flags.parse(Deno.args, { boolean: ["check"] }) + const wasmPaths = [ "hashers/xxhash", "hashers/blake2b", ] -await Promise.all(wasmPaths.map(build)) +let success = true +await Promise.all(wasmPaths.map((path) => + build(path).catch((error) => { + console.error(`${path}:`, error) + success = false + }) +)) +Deno.exit(success ? 0 : 1) async function build(wasmPath: string) { const process = Deno.run({ @@ -22,14 +33,19 @@ async function build(wasmPath: string) { const wasm = await process.output() - await Deno.writeTextFile( - wasmPath + ".wasm.ts", - ` + const content = ` // @generated import { decodeHex } from "${path.relative(path.dirname(wasmPath), "util.ts")}" export default decodeHex(\n"${encodeHex(wasm).replace(/.{0,64}|$/g, "\\\n$&")}",\n) -`.trimStart(), - ) +`.trimStart() + + const outputPath = wasmPath + ".wasm.ts" + if (check) { + const existing = await Deno.readTextFile(outputPath) + assertEquals(existing, content, "Outdated file") + } else { + await Deno.writeTextFile(outputPath, content) + } } diff --git a/deno.jsonc b/deno.jsonc index c294076..ade1ef2 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -26,7 +26,7 @@ "tasks": { "build": "deno run -A _tasks/build.ts", "run": "deno task build && deno run -A --no-check=remote", - "dnt": "deno task build && deno task run _tasks/build_npm_pkg.ts", + "dnt": "deno task build && deno task run _tasks/dnt.ts", "test": "deno task build && deno test -A --no-check=remote -L=info", "test-update": "deno task build && deno test -A --no-check=remote -L=info -- --update", "bench": "deno task build && deno bench -A --no-check=remote --unstable", diff --git a/hashers/mod.ts b/hashers/mod.ts index 3cb4cf0..4672c87 100644 --- a/hashers/mod.ts +++ b/hashers/mod.ts @@ -1,4 +1,5 @@ // moderate --exclude *.wasm.ts export * from "./blake2b.ts" +export * from "./common.ts" export * from "./xxhash.ts" diff --git a/mod.ts b/mod.ts index 157325d..37e8f50 100644 --- a/mod.ts +++ b/mod.ts @@ -1,4 +1,3 @@ -// moderate +// moderate --exclude util.ts export * from "./hashers/mod.ts" -export * from "./util.ts" diff --git a/words.txt b/words.txt index 0587e40..149c2cd 100644 --- a/words.txt +++ b/words.txt @@ -1,3 +1,7 @@ dprint hashers paritytech +deno +denoland +chiefbiiko +wabt