Skip to content

Commit

Permalink
Enable JS GHA (#254)
Browse files Browse the repository at this point in the history
* Enable JS GHA
* Disable node check (duplicate functions cause errors)
* Remove non flake files and update docs
  • Loading branch information
hamishmack authored Jun 12, 2024
1 parent ea4fb83 commit d17ff47
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 45 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: TypeScript NPM Package

on:
#pull_request:
#push:
# branches: [ "master" ]
# tags: [ "*.*.*" ]
pull_request:
push:
branches: [ "master" ]
tags: [ "*.*.*" ]

jobs:
build:
Expand All @@ -17,26 +17,30 @@ jobs:
steps:
- name: '📥 Checkout Code'
uses: actions/checkout@v2.3.4
- uses: cachix/install-nix-action@v13
- name: Install nix
uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
experimental-features = nix-command flakes
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
substituters = https://cache.iog.io https://cache.nixos.org/
- name: 'Install dependencies'
run: 'nix-shell --run "npm install"'
run: 'nix develop ..#cardano-addresses-js-shell --command npm install'
- name: 'Build'
run: 'nix-shell --run "npm run build"'
run: 'nix develop ..#cardano-addresses-js-shell --command npm run build'
- name: 'Test'
run: 'nix-shell --run "npm run test"'
run: 'nix develop ..#cardano-addresses-js-shell --command npm run test'
- name: 'Typedoc'
run: |
du -cBM --max-depth=1 /opt 2> >(grep -v 'Permission denied') | sort -n
du -cBM --max-depth=1 /nix 2> >(grep -v 'Permission denied') | sort -n
du -cBM --max-depth=1 /usr 2> >(grep -v 'Permission denied') | sort -n
nix-shell --run "npm run typedoc"
nix develop ..#cardano-addresses-js-shell --command npm run typedoc
- name: 'Demo'
run: 'nix-build -A demo -o result-demo'
run: |
git add -f dist
nix build ..#cardano-addresses-demo-js -o result-demo
- name: 'Prepare Documentation'
run: |
mkdir ../_build
Expand All @@ -59,6 +63,6 @@ jobs:
package_version="$(jq -r .version package.json)"
echo "tag=$tag\npackage_version=$package_version"
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
nix-shell --run "npm publish"
nix develop ..#cardano-addresses-js-shell --command npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26 changes: 14 additions & 12 deletions jsapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,39 @@ This package comprises of four parts:

### NodeJS module: Building and testing

Start a `nix-shell` in *this directory* (not the top-level) and run:
Start a `nix develop .#cardano-addresses-js-shell` in the repo top-level directory and run:

```shell
$ nix develop .#cardano-addresses-js-shell
$ cd jsapi
$ nix-shell
[nix-shell:~/iohk/cardano-addresses/jsapi]$ npm install && npm run build
$ npm install && npm run build
...
[nix-shell:~/iohk/cardano-addresses/jsapi]$ npm run test
$ npm run test
```

Behind the scenes, this will use Nix to make the `ghcjs` build of the `cardano-addresses` library. The path to this Javascript file is stored in the `$CARDANO_ADDRESSES_JS` environment variable.

### Haskell module: Building and testing

To try it out run `nix-shell` from the repo top-level directory:
To try it out run `nix develop .#` from the repo top-level directory:

```shell
$ nix-shell
[nix-shell:~/iohk/cardano-addresses]$ js-unknown-ghcjs-cabal build cardano-addresses-jsapi:jsapi-test
[nix-shell:~/iohk/cardano-addresses]$ node dist-newstyle/build/js-ghcjs/ghcjs-8.10.4/cardano-addresses-jsapi-3.5.0/t/jsapi-test/build/jsapi-test/jsapi-test.jsexe/all.js
$ nix develop .#
$ cd jsapi
$ js-unknown-ghcjs-cabal build cardano-addresses-jsapi:jsapi-test
$ node dist-newstyle/build/js-ghcjs/ghcjs-8.10.4/cardano-addresses-jsapi-3.5.0/t/jsapi-test/build/jsapi-test/jsapi-test.jsexe/all.js
```

That test initializes the api from a JS function that is called from `Main.hs`. To build `.js` file that might be easier to use from a JS app run:

```shell
$ nix-build jsapi/default.nix -A cardano-addresses-js
/nix/store/dw0xwvjvwac68i2a4dkkpx4mw8yji9z8-cardano-addresses-js-3.5.0
$ nix build .#cardano-addresses-js
$ tree ./result
./result
result
├── cardano-addresses-jsapi.cjs.js
└── cardano-addresses-jsapi.js
├── cardano-addresses-jsapi.esm.js
├── cardano-addresses-jsapi.js
└── cardano-addresses-jsapi.mjs
```

This replaces the regular `runmain.js` with `jsapi/glue/runmain.js`. That exposes a single function you can call and pass in a continuation.
Expand Down
11 changes: 0 additions & 11 deletions jsapi/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion jsapi/shell.nix

This file was deleted.

17 changes: 9 additions & 8 deletions jsbits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ ghcjs.
Build and run CLI:

```terminal
$ nix-build release.nix -A ghcjs.cardano-address.x86_64-linux
$ node ./result/bin/cardano-address.jsexe/all.js --help
$ node ./result/bin/cardano-address.jsexe/all.js recovery-phrase generate
$ nix build .#ghc810-javascript-unknown-ghcjs:cardano-addresses-cli:exe:cardano-address
$ ./result/bin/cardano-address --help
$ ./result/bin/cardano-address recovery-phrase generate
```

Execute library unit tests:
```terminal
$ nix-build release.nix -A ghcjs.checks.cardano-addresses.unit.x86_64-linux
$ nix build .#checks.x86_64-linux.ghc810-javascript-unknown-ghcjs:cardano-addresses:test:unit
$ cat result/test-stdout
```

## With Cabal in nix-shell
Expand All @@ -26,16 +27,16 @@ The `nix-shell` development environment provides
Build and run CLI:

```terminal
$ nix-shell
[nix-shell:~/iohk/cardano-addresses]$ js-unknown-ghcjs-cabal --builddir=dist-ghcjs build all
$ nix develop
$ js-unknown-ghcjs-cabal --builddir=dist-ghcjs build all
...
[nix-shell:~/iohk/cardano-addresses]$ js-unknown-ghcjs-cabal --builddir=dist-ghcjs run cardano-addresses-cli:exe:cardano-address
$ js-unknown-ghcjs-cabal --builddir=dist-ghcjs run cardano-addresses-cli:exe:cardano-address
...
/home/rodney/iohk/cardano-addresses/dist-ghcjs/build/wasm32-none/ghcjs-8.6.5/cardano-addresses-cli-3.3.0/x/cardano-address/build/cardano-address/cardano-address: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
cardano-address: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
[nix-shell:~/iohk/cardano-addresses]$ node dist-ghcjs/build/wasm32-none/ghcjs-8.6.5/cardano-addresses-cli-3.3.0/x/cardano-address/build/cardano-address/cardano-address.jsexe/all.js recovery-phrase generate
$ node dist-ghcjs/build/wasm32-none/ghcjs-8.6.5/cardano-addresses-cli-3.3.0/x/cardano-address/build/cardano-address/cardano-address.jsexe/all.js recovery-phrase generate
culture fringe exercise stumble gold current balance ....
```

Expand Down
3 changes: 2 additions & 1 deletion nix/cardano-addresses-js.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ stdenv.mkDerivation rec {
checkPhase = ''
node --check $out/cardano-addresses-jsapi.js
node --check $out/cardano-addresses-jsapi.cjs.js
node --experimental-modules --check $out/cardano-addresses-jsapi.mjs
# TODO find a way to remove the duplicates or disable just that check
# node --experimental-modules --check $out/cardano-addresses-jsapi.mjs
echo "syntax check OK"
'';
installPhase = "true";
Expand Down
1 change: 0 additions & 1 deletion shell.nix

This file was deleted.

0 comments on commit d17ff47

Please sign in to comment.