Skip to content

Commit

Permalink
add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed Nov 12, 2022
1 parent c004488 commit 3f18a73
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 22 additions & 6 deletions _tasks/build.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import * as flags from "https://deno.land/[email protected]/flags/mod.ts"
import * as path from "https://deno.land/[email protected]/path/mod.ts"
import { assertEquals } from "https://deno.land/[email protected]/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({
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions hashers/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// moderate --exclude *.wasm.ts

export * from "./blake2b.ts"
export * from "./common.ts"
export * from "./xxhash.ts"
3 changes: 1 addition & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// moderate
// moderate --exclude util.ts

export * from "./hashers/mod.ts"
export * from "./util.ts"
4 changes: 4 additions & 0 deletions words.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
dprint
hashers
paritytech
deno
denoland
chiefbiiko
wabt

0 comments on commit 3f18a73

Please sign in to comment.