Automatically build aquamarine.wasm & publish to NPM as base64 (#29)

This commit is contained in:
folex 2020-11-17 12:02:43 +03:00 committed by GitHub
parent 0c7d066666
commit 605c5dda18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 256 additions and 26 deletions

102
.github/workflows/publish_npm.yml vendored Normal file
View File

@ -0,0 +1,102 @@
# run locally like this:
# act -b -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j npm-publish -s "NPM_TOKEN=uuid-uuid-uuid-uuid"
name: "publish-base64-npm"
on:
push:
branches:
- "master"
jobs:
npm-publish:
name: "Publish Aquamarine to NPM"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v2
### Install rust & wasm-pack
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: wasm32-unknown-unknown
profile: minimal
override: true
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
### Build aquamarine.wasm
- run: wasm-pack build $GITHUB_WORKSPACE/stepper --no-typescript --release -d $(pwd)/pkg
### Generate aquamarine.wasm.base64.js
- run: sudo apt-get update && sudo apt-get --yes --force-yes install jq
- name: Generate aquamarine.wasm.base64.js
run: |
cat << EOF > pkg/aquamarine.wasm.base64.js
export const wasmBs64 = "$(base64 -w0 pkg/aquamarine_client_bg.wasm)";
EOF
### Generate index files so import works as: | import {wasmBs64} from "@fluencelabs/aquamarine-stepper"; |
- name: Generate index.js & index.d.ts
run: |
cat << EOF > index.js
export * from "./aquamarine.wasm.base64.js";
EOF
cp index.js index.d.ts
working-directory: pkg
- name: Generate aquamarine.wasm.base64.d.ts
run: |
cat << EOF > aquamarine.wasm.base64.d.ts
export const wasmBs64: string;
EOF
working-directory: pkg
- name: Prepare package.json for publishing
run: |
cat pkg/package.json | jq --arg name aquamarine.wasm.base64.js \
'. + {
files: [ "aquamarine.wasm.base64.js", "aquamarine.wasm.base64.d.ts", "index.js", "index.d.ts" ],
"name": "@fluencelabs/aquamarine-stepper",
"description": "Aquamarine IR interpreter as base64 WASM",
"main": "index.js",
"repository": "https://github.com/fluencelabs/aquamarine",
"author": "Fluence Labs",
"license": "Apache 2.0",
"private": false,
"main": "index.js",
"types": "index.d.ts"
}' > pkg/package_new.json
cat pkg/package_new.json
mv pkg/package_new.json pkg/package.json
### Get version from NPM registry
- run: yarn version --new-version $(yarn info --silent @fluencelabs/aquamarine-stepper version) --no-git-tag-version
working-directory: pkg
### Increment patch component of the version
- run: yarn version --patch --no-git-tag-version
working-directory: pkg
### Add README so it appears on npmjs.org
- run: |
cat <<EOF > README.md
# Aquamarine IR interpreter as base64 WASM
EOF
working-directory: pkg
### Publish aquamarine-stepper to NPM
- uses: JS-DevTools/npm-publish@v1
with:
package: pkg/package.json
access: public
check-version: false
token: ${{ secrets.NPM_TOKEN }}

124
.github/workflows/publish_npm_dev.yml vendored Normal file
View File

@ -0,0 +1,124 @@
# run locally like this:
# act -b -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j npm-publish-dev -s "NPM_TOKEN=uuid-uuid-uuid-uuid"
name: "publish-base64-npm-dev"
on:
push:
branches-ignore:
- master
jobs:
npm-publish-dev:
name: "Publish Aquamarine to NPM"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
### Extract branch name
- name: Extract branch name
if: github.event_name != 'pull_request'
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
id: extract_branch
- name: Extract branch name
if: github.event_name == 'pull_request'
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
### Install rust & wasm-pack
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: wasm32-unknown-unknown
profile: minimal
override: true
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
### Build aquamarine.wasm
- run: wasm-pack build $GITHUB_WORKSPACE/stepper --no-typescript --release -d $(pwd)/pkg
### Generate aquamarine.wasm.base64.js
- run: sudo apt-get update && sudo apt-get --yes --force-yes install jq
- name: Generate aquamarine.wasm.base64.js
run: |
cat << EOF > pkg/aquamarine.wasm.base64.js
export const wasmBs64 = "$(base64 -w0 pkg/aquamarine_client_bg.wasm)";
EOF
### Generate index files so import works as: | import {wasmBs64} from "@fluencelabs/aquamarine-stepper"; |
- name: Generate index.js & index.d.ts
run: |
cat << EOF > index.js
export * from "./aquamarine.wasm.base64.js";
EOF
cp index.js index.d.ts
working-directory: pkg
- name: Generate aquamarine.wasm.base64.d.ts
run: |
cat << EOF > aquamarine.wasm.base64.d.ts
export const wasmBs64: string;
EOF
working-directory: pkg
- run: cat pkg/package.json
- name: Prepare package.json for publishing
run: |
cat pkg/package.json | jq --arg name aquamarine.wasm.base64.js \
'. + {
files: [ "aquamarine.wasm.base64.js", "aquamarine.wasm.base64.d.ts", "index.js", "index.d.ts" ],
"name": "@fluencelabs/aquamarine-stepper-${{ env.BRANCH_NAME }}",
"description": "Aquamarine IR interpreter as base64 WASM",
"main": "index.js",
"repository": "https://github.com/fluencelabs/aquamarine",
"author": "Fluence Labs",
"license": "Apache 2.0",
"private": false,
"main": "index.js",
"types": "index.d.ts"
}' > pkg/package_new.json
cat pkg/package_new.json
mv pkg/package_new.json pkg/package.json
- run: cat pkg/package.json
### Set default version
- run: yarn version --new-version 0.0.0 --no-git-tag-version
working-directory: pkg
### Maybe get version from NPM registry
- run: yarn version --new-version $(yarn info --silent @fluencelabs/aquamarine-stepper-${{ env.BRANCH_NAME }} version) --no-git-tag-version || true
working-directory: pkg
### Increment patch component of the version
- run: yarn version --patch --no-git-tag-version
working-directory: pkg
### Add README so it appears on npmjs.org
- run: |
cat <<EOF > README.md
# Aquamarine IR interpreter as base64 WASM
Built from branch ${{ env.BRANCH_NAME }}
EOF
working-directory: pkg
### Publish to NPM registry
- uses: actions/setup-node@v1
with:
node-version: '15'
registry-url: 'https://registry.npmjs.org'
- run: npm publish --access public
working-directory: pkg
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

48
Cargo.lock generated
View File

@ -67,7 +67,7 @@ dependencies = [
[[package]]
name = "aquamarine-vm"
version = "0.1.2"
source = "git+https://github.com/fluencelabs/fce?branch=master#af75084ceb950560a56399a946c985c5df0bb480"
source = "git+https://github.com/fluencelabs/fce?branch=master#afa612a5639f900f5730f005f61651edb0c97569"
dependencies = [
"fluence-faas",
"maplit",
@ -639,7 +639,7 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fce"
version = "0.1.11"
source = "git+https://github.com/fluencelabs/fce?branch=master#af75084ceb950560a56399a946c985c5df0bb480"
source = "git+https://github.com/fluencelabs/fce?branch=master#afa612a5639f900f5730f005f61651edb0c97569"
dependencies = [
"boolinator",
"fce-utils",
@ -661,12 +661,12 @@ dependencies = [
[[package]]
name = "fce-utils"
version = "0.1.0"
source = "git+https://github.com/fluencelabs/fce?branch=master#af75084ceb950560a56399a946c985c5df0bb480"
source = "git+https://github.com/fluencelabs/fce?branch=master#afa612a5639f900f5730f005f61651edb0c97569"
[[package]]
name = "fce-wit-interfaces"
version = "0.1.8"
source = "git+https://github.com/fluencelabs/fce?branch=master#af75084ceb950560a56399a946c985c5df0bb480"
source = "git+https://github.com/fluencelabs/fce?branch=master#afa612a5639f900f5730f005f61651edb0c97569"
dependencies = [
"multimap",
"wasmer-interface-types-fl",
@ -675,7 +675,7 @@ dependencies = [
[[package]]
name = "fce-wit-parser"
version = "0.1.10"
source = "git+https://github.com/fluencelabs/fce?branch=master#af75084ceb950560a56399a946c985c5df0bb480"
source = "git+https://github.com/fluencelabs/fce?branch=master#afa612a5639f900f5730f005f61651edb0c97569"
dependencies = [
"anyhow",
"fce-wit-interfaces",
@ -702,7 +702,7 @@ dependencies = [
[[package]]
name = "fluence-faas"
version = "0.1.12"
source = "git+https://github.com/fluencelabs/fce?branch=master#af75084ceb950560a56399a946c985c5df0bb480"
source = "git+https://github.com/fluencelabs/fce?branch=master#afa612a5639f900f5730f005f61651edb0c97569"
dependencies = [
"cmd_lib",
"fce",
@ -976,9 +976,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "js-sys"
version = "0.3.45"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
dependencies = [
"wasm-bindgen",
]
@ -1174,9 +1174,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.5.1"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f53cef67919d7d247eb9a2f128ca9e522789967ef1eb4ccd8c71a95a8aedf596"
checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
[[package]]
name = "oorandom"
@ -1794,9 +1794,9 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
checksum = "db8716a166f290ff49dabc18b44aa407cb7c6dbe1aa0971b44b8a24b0ca35aae"
[[package]]
name = "unicode-width"
@ -1882,9 +1882,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasm-bindgen"
version = "0.2.68"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
dependencies = [
"cfg-if 0.1.10",
"wasm-bindgen-macro",
@ -1892,9 +1892,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.68"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
dependencies = [
"bumpalo",
"lazy_static",
@ -1907,9 +1907,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.68"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1917,9 +1917,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.68"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
dependencies = [
"proc-macro2",
"quote",
@ -1930,9 +1930,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.68"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
[[package]]
name = "wasmer-clif-backend-fl"
@ -2127,9 +2127,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.45"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d"
checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
dependencies = [
"js-sys",
"wasm-bindgen",

View File

@ -20,7 +20,9 @@ jsonpath_lib = "0.2.5"
boolinator = "2.4.0"
log = "0.4.11"
serde_json = "1.0"
wasm-bindgen = "0.2.68"
# Keep 0.2.65 until this is resolved https://github.com/rustwasm/wasm-pack/issues/886
wasm-bindgen = "=0.2.65"
[dev_dependencies]
aqua-test-utils = { path = "../crates/test-utils" }

View File

@ -17,7 +17,9 @@ path = "src/fce.rs"
stepper-lib = { path = "../stepper-lib" }
fluence = { git = "https://github.com/fluencelabs/rust-sdk", features = ["logger"] }
wasm-bindgen = "0.2.68"
# Keep 0.2.65 until this is resolved https://github.com/rustwasm/wasm-pack/issues/886
wasm-bindgen = "=0.2.65"
log = "0.4.11"
serde_json = "1.0"