Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Make NPM packages (WASM binding) to be used in deps on every green CI 
Options:
- build and commit, use as git URLs;
- publish a snapshot version (use tag?);


Discussion / hints:

Fix patch:
diff --git a/bindings/ergo-lib-wasm/README.md b/bindings/ergo-lib-wasm/README.md
index cce6ec73b..802e329b2 100644
--- a/bindings/ergo-lib-wasm/README.md
+++ b/bindings/ergo-lib-wasm/README.md
@@ -10,6 +10,9 @@ Packages(npm):
 - [ergo-lib-wasm-browser](https://www.npmjs.com/package/ergo-lib-wasm-browser) [![Latest version](https://img.shields.io/npm/v/ergo-lib-wasm-browser)](https://www.npmjs.com/package/ergo-lib-wasm-browser)
 - [ergo-lib-wasm-nodejs](https://www.npmjs.com/package/ergo-lib-wasm-nodejs) [![Latest version](https://img.shields.io/npm/v/ergo-lib-wasm-nodejs)](https://www.npmjs.com/package/ergo-lib-wasm-nodejs)
 
+## Alpha version
+On CI build (job `JS tests`) an alpha build of npm packages is published. The version of the alpha build is comprised of the next minor version with git commit hash suffix (i.e if the current version is `0.12.0` then alpha build will be `0.13.0-alpha-[COMMIT]`) and published with `alpha` tag. See `JS tests` CI job output for details. 
+
 ## Troubleshooting
 ### When I build the `ergo-lib-wasm` and include the `pkg` folder as dependency in my app I get "TypeError: TextDecoder is not a constructor".
 
diff --git a/bindings/ergo-lib-wasm/package.json b/bindings/ergo-lib-wasm/package.json
index f5d0a2772..994b1122b 100644
--- a/bindings/ergo-lib-wasm/package.json
+++ b/bindings/ergo-lib-wasm/package.json
@@ -4,10 +4,12 @@
         "serve": "wasm-pack build --target browser && webpack-dev-server",
         "test": "wasm-pack build --target nodejs && mocha --require @babel/register --require @babel/polyfill 'tests/test*.js'",
         "doc": "jsdoc -c jsdoc.json pkg/ergo_wallet_wasm.js README.md -d docs",
-        "build-nodejs": "rm -rf ./pkg && wasm-pack build --target nodejs",
-        "build-browser": "rm -rf ./pkg && wasm-pack build --target browser --release",
-        "publish-nodejs": "npm run build-nodejs && node ./scripts/publish_helper -nodejs && cd pkg && npm publish",
-        "publish-browser": "npm run build-browser && node ./scripts/publish_helper -browser && cd pkg && npm publish"
+        "build-nodejs": "rm -rf ./pkg-nodejs && wasm-pack build --target nodejs --out-dir pkg-nodejs && cd pkg-nodejs && node ../scripts/publish_helper -nodejs",
+        "build-nodejs-alpha": "rm -rf ./pkg-nodejs && wasm-pack build --target nodejs --out-dir pkg-nodejs && cd pkg-nodejs && node ../scripts/publish_helper -nodejs && npm version minor && node ../scripts/set_alpha_version -nodejs $(git rev-parse --short HEAD)",
+        "build-browser": "rm -rf ./pkg-browser && wasm-pack build --target browser --out-dir pkg-browser && cd pkg-browser && node ../scripts/publish_helper -browser",
+        "build-browser-alpha": "rm -rf ./pkg-browser && wasm-pack build --target browser --out-dir pkg-browser && cd pkg-browser && node ../scripts/publish_helper -browser && npm version minor && node ../scripts/set_alpha_version -browser $(git rev-parse --short HEAD)",
+        "publish-nodejs": "npm run build-nodejs &&  cd pkg-nodejs && npm publish",
+        "publish-browser": "npm run build-browser && cd pkg-browser && npm publish"
     },
     "devDependencies": {
         "@babel/core": "^7.6.4",
diff --git a/bindings/ergo-lib-wasm/scripts/publish_helper.js b/bindings/ergo-lib-wasm/scripts/publish_helper.js
index c26fdccba..ace7fa8f2 100644
--- a/bindings/ergo-lib-wasm/scripts/publish_helper.js
+++ b/bindings/ergo-lib-wasm/scripts/publish_helper.js
@@ -1,13 +1,16 @@
 const fs = require('fs');
-const oldPkg = require('../pkg/package.json');
+
+const arg = process.argv.slice(2)[0];
+
+const oldPkg = require(`../pkg${arg}/package.json`);
 
 // based on https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/master/scripts/publish-helper.js
 
 if (oldPkg.name === 'ergo-lib-wasm') {
-  oldPkg.name = oldPkg.name + process.argv.slice(2)[0];
+  oldPkg.name = oldPkg.name + arg;
 }
 
-if (process.argv.slice(2)[0] === '-browser') {
+if (arg === '-browser') {
   // due to a bug in wasm-pack, this file is missing from browser builds
   const missingFile = 'ergo_lib_wasm_bg.js';
   if (oldPkg.files.find(entry => entry === missingFile) == null) {
@@ -16,4 +19,4 @@ if (process.argv.slice(2)[0] === '-browser') {
 }
 
 console.log(oldPkg);
-fs.writeFileSync('./pkg/package.json', JSON.stringify(oldPkg, null, 2));
+fs.writeFileSync('./package.json', JSON.stringify(oldPkg, null, 2));
diff --git a/bindings/ergo-lib-wasm/scripts/set_alpha_version.js b/bindings/ergo-lib-wasm/scripts/set_alpha_version.js
new file mode 100644
index 000000000..0485afc6e
--- /dev/null
+++ b/bindings/ergo-lib-wasm/scripts/set_alpha_version.js
@@ -0,0 +1,13 @@
+const fs = require('fs');
+
+const argSuffix = process.argv.slice(2)[0];
+const argBuildVer = process.argv.slice(2)[1];
+
+const oldPkg = require(`../pkg${argSuffix}/package.json`);
+
+// based on https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/master/scripts/publish-helper.js
+
+oldPkg.version = oldPkg.version + `-alpha-${argBuildVer}`;
+
+console.log(oldPkg);
+fs.writeFileSync('./package.json', JSON.stringify(oldPkg, null, 2));


Test patch:
diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml
index 7ebdb15be..e1234cdd6 100644
--- a/.github/workflows/js_tests.yml
+++ b/.github/workflows/js_tests.yml
@@ -30,5 +30,24 @@ jobs:
       - name: run tests
         run: |
           wasm-pack build
-          npm install && npm run test
+          npm install
+          npm run test 
+          
+      - name: build alpha versions
+        run: |
+          npm run build-nodejs-alpha
+          npm run build-browser-alpha
+
+      - name: publish nodejs alpha version to npm
+        uses: JS-DevTools/npm-publish@v1
+        with:
+          token: ${{ secrets.NPM_TOKEN }}
+          package: ./bindings/ergo-lib-wasm/pkg-nodejs/package.json
+          tag: "alpha"
 
+      - name: publish browser alpha version to npm
+        uses: JS-DevTools/npm-publish@v1
+        with:
+          token: ${{ secrets.NPM_TOKEN }}
+          package: ./bindings/ergo-lib-wasm/pkg-browser/package.json
+          tag: "alpha"