mirror of
https://github.com/fluencelabs/examples
synced 2025-04-26 03:02:15 +00:00
Using try finally in nodejs examples, fix CI pipelines (#199)
This commit is contained in:
parent
6a05fc381a
commit
c25674f79c
7
.github/check_connection.aqua
vendored
Normal file
7
.github/check_connection.aqua
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
service Op("op"):
|
||||||
|
noop()
|
||||||
|
|
||||||
|
func check_connection() -> string:
|
||||||
|
on HOST_PEER_ID:
|
||||||
|
Op.noop()
|
||||||
|
<- "ok"
|
8
.github/deploy.aqua
vendored
Normal file
8
.github/deploy.aqua
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
service CallParameters:
|
||||||
|
call_parameters() -> string
|
||||||
|
|
||||||
|
func call(service_id: string) -> string:
|
||||||
|
on HOST_PEER_ID:
|
||||||
|
CallParameters service_id
|
||||||
|
r <- CallParameters.call_parameters()
|
||||||
|
<- r
|
84
.github/workflows/check-connection.yml
vendored
Normal file
84
.github/workflows/check-connection.yml
vendored
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
name: "check-connection"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
# branches:
|
||||||
|
# - "master"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check-deployment:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node: [
|
||||||
|
'/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e',
|
||||||
|
'/dns4/kras-00.fluence.dev/tcp/19001/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51',
|
||||||
|
'/dns4/kras-01.fluence.dev/tcp/19001/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA',
|
||||||
|
'/dns4/kras-02.fluence.dev/tcp/19001/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf',
|
||||||
|
'/dns4/kras-03.fluence.dev/tcp/19001/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE',
|
||||||
|
'/dns4/kras-04.fluence.dev/tcp/19001/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi',
|
||||||
|
'/dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS',
|
||||||
|
'/dns4/kras-06.fluence.dev/tcp/19001/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr',
|
||||||
|
'/dns4/kras-07.fluence.dev/tcp/19001/wss/p2p/12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn',
|
||||||
|
'/dns4/kras-08.fluence.dev/tcp/19001/wss/p2p/12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt',
|
||||||
|
'/dns4/kras-09.fluence.dev/tcp/19001/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm'
|
||||||
|
]
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
~/.cargo/bin
|
||||||
|
target
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
|
- run: docker run -d --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj --local
|
||||||
|
|
||||||
|
- name: Download marine
|
||||||
|
run: sudo bash $GITHUB_WORKSPACE/.github/download_marine.sh
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
run: |
|
||||||
|
rustup toolchain install nightly-2021-04-24-x86_64-unknown-linux-gnu
|
||||||
|
rustup default nightly-2021-04-24-x86_64-unknown-linux-gnu
|
||||||
|
rustup target add wasm32-wasi --toolchain nightly-2021-04-24-x86_64-unknown-linux-gnu
|
||||||
|
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-v1-node-16-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-v1-node-16
|
||||||
|
|
||||||
|
- name: Setup Node.js 16
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
|
||||||
|
- run: npm install -g @fluencelabs/aqua@0.6.4-283
|
||||||
|
|
||||||
|
- name: "Check connection to network"
|
||||||
|
run: |
|
||||||
|
set -x
|
||||||
|
NODE=${{ matrix.node }}
|
||||||
|
INPUT=$GITHUB_WORKSPACE/.github/check_connection.aqua
|
||||||
|
|
||||||
|
RESULT=$(aqua run --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= -f 'check_connection()' --input $INPUT)
|
||||||
|
RESULT=$(echo $RESULT | sed -e 's/Your peerId: [a-zA-Z0-9]*//g' | xargs)
|
||||||
|
|
||||||
|
if [ "$RESULT" != "ok" ]; then
|
||||||
|
echo "Failed to connect to $NODE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
working-directory: marine-examples/call_parameters
|
||||||
|
|
@ -37,27 +37,40 @@ jobs:
|
|||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-v1-node-14-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-v1-node-16-${{ hashFiles('**/package-lock.json') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-v1-node-14
|
${{ runner.os }}-v1-node-16
|
||||||
|
|
||||||
- name: Setup Node.js 14
|
- name: Setup Node.js 16
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: 16
|
||||||
|
|
||||||
- run: npm install -g @fluencelabs/fldist
|
- run: npm install -g @fluencelabs/aqua@0.6.4-283
|
||||||
|
|
||||||
- name: "Check call_parameters deployment"
|
- name: "Check call_parameters deployment"
|
||||||
run: |
|
run: |
|
||||||
set -x
|
set -x
|
||||||
export NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3"
|
NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3"
|
||||||
SERVICE_ID=`./deploy.sh`
|
SERVICE_ID=`./deploy.sh $NODE`
|
||||||
fldist --node-addr $NODE run_air -d '{"service_id": "'$SERVICE_ID'"}' -p <(echo '
|
INPUT=$GITHUB_WORKSPACE/.github/deploy.aqua
|
||||||
(seq
|
|
||||||
(call relay (service_id "call_parameters") [] result)
|
RESULT=$(aqua run --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= -f 'call(service_id)' -d '{"service_id": "'$SERVICE_ID'"}' --input $INPUT)
|
||||||
(call %init_peer_id% (returnService "run") [result])
|
RESULT=$(echo $RESULT | sed -e 's/Your peerId: [a-zA-Z0-9]*//g')
|
||||||
)
|
|
||||||
')
|
EXPECTED_PEER_ID=$(echo -e "$RESULT" | sed -n '1p' | grep -o '12D3.*')
|
||||||
|
RESULT_PEER_ID=$(echo -e "$RESULT" | sed -n '2p' | tr -d \")
|
||||||
|
if [ "$EXPECTED_PEER_ID" -neq "$RESULT_PEER_ID" ]; then
|
||||||
|
echo "Expected $EXPECTED_PEER_ID, got $RESULT_PEER_ID"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
RESULT_SERVICE_ID=$(echo -e "$RESULT" | sed -n '3p')
|
||||||
|
if [ "$SERVICE_ID" -neq "$RESULT_SERVICE_ID" ]; then
|
||||||
|
echo "Expected $SERVICE_ID, got $RESULT_SERVICE_ID"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
aqua dist remove --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= --id "$SERVICE_ID"
|
||||||
working-directory: marine-examples/call_parameters
|
working-directory: marine-examples/call_parameters
|
||||||
|
|
@ -10,6 +10,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [16.x]
|
node-version: [16.x]
|
||||||
|
project: [web, nodejs]
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -61,5 +63,4 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npm i
|
npm i
|
||||||
CI=false npm run build
|
CI=false npm run build
|
||||||
npm run test -w nodejs
|
npm run test -w ${{ matrix.project }}
|
||||||
npm run test -w web
|
|
||||||
|
1
.github/workflows/test-js-projects.yml
vendored
1
.github/workflows/test-js-projects.yml
vendored
@ -20,6 +20,7 @@ jobs:
|
|||||||
"./aqua-examples/price-oracle/client-peer",
|
"./aqua-examples/price-oracle/client-peer",
|
||||||
"./aqua-examples/price-oracle/web"
|
"./aqua-examples/price-oracle/web"
|
||||||
]
|
]
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -29,6 +29,7 @@ export async function main(environment: Node[]) {
|
|||||||
let serviceHost = environment[2];
|
let serviceHost = environment[2];
|
||||||
|
|
||||||
let providerClient = new FluencePeer();
|
let providerClient = new FluencePeer();
|
||||||
|
try {
|
||||||
await providerClient.start({ connectTo: providerHost });
|
await providerClient.start({ connectTo: providerHost });
|
||||||
console.log('📘 uploading .wasm to node %s', providerHost.multiaddr);
|
console.log('📘 uploading .wasm to node %s', providerHost.multiaddr);
|
||||||
let path = globSource('../service/artifacts/process_files.wasm');
|
let path = globSource('../service/artifacts/process_files.wasm');
|
||||||
@ -85,10 +86,11 @@ export async function main(environment: Node[]) {
|
|||||||
|
|
||||||
let result = await remove_service(serviceHost.peerId, service_id);
|
let result = await remove_service(serviceHost.peerId, service_id);
|
||||||
console.log('📗 ProcessFiles service removed', result);
|
console.log('📗 ProcessFiles service removed', result);
|
||||||
|
} finally {
|
||||||
await Fluence.stop();
|
await Fluence.stop();
|
||||||
await providerClient.stop();
|
await providerClient.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function fromOption<T>(opt: T | T[] | null): T | null {
|
function fromOption<T>(opt: T | T[] | null): T | null {
|
||||||
if (Array.isArray(opt)) {
|
if (Array.isArray(opt)) {
|
||||||
|
@ -89,6 +89,7 @@ export async function main() {
|
|||||||
// console.log("hello");
|
// console.log("hello");
|
||||||
// setLogLevel('DEBUG');
|
// setLogLevel('DEBUG');
|
||||||
|
|
||||||
|
try {
|
||||||
await Fluence.start({ connectTo: krasnodar[2] });
|
await Fluence.start({ connectTo: krasnodar[2] });
|
||||||
console.log(
|
console.log(
|
||||||
'created a fluence client %s with relay %s',
|
'created a fluence client %s with relay %s',
|
||||||
@ -123,6 +124,7 @@ export async function main() {
|
|||||||
|
|
||||||
par_result = await echo_greeting_par_improved(echo_service, greeting_services);
|
par_result = await echo_greeting_par_improved(echo_service, greeting_services);
|
||||||
console.log('par improved signature result : ', par_result);
|
console.log('par improved signature result : ', par_result);
|
||||||
|
} finally {
|
||||||
await Fluence.stop();
|
await Fluence.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -54,7 +54,7 @@ export async function main() {
|
|||||||
|
|
||||||
// Uncomment to enable debug logs:
|
// Uncomment to enable debug logs:
|
||||||
// setLogLevel('DEBUG');
|
// setLogLevel('DEBUG');
|
||||||
|
try {
|
||||||
// create the Fluence client for the Krasnodar testnet
|
// create the Fluence client for the Krasnodar testnet
|
||||||
await Fluence.start({ connectTo: krasnodar[5] });
|
await Fluence.start({ connectTo: krasnodar[5] });
|
||||||
console.log(
|
console.log(
|
||||||
@ -77,6 +77,7 @@ export async function main() {
|
|||||||
// func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result:
|
// func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result:
|
||||||
const network_result_par = await get_price_par('ethereum', 'usd', getter_topo, mean_topo[0]);
|
const network_result_par = await get_price_par('ethereum', 'usd', getter_topo, mean_topo[0]);
|
||||||
console.log('par result: ', network_result_par);
|
console.log('par result: ', network_result_par);
|
||||||
|
} finally {
|
||||||
await Fluence.stop();
|
await Fluence.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -o errexit -o nounset -o pipefail
|
set -o errexit -o nounset -o pipefail
|
||||||
|
|
||||||
if [[ -z "${NODE:-}" ]]; then
|
./build.sh
|
||||||
NODE_ADDR=""
|
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
NODE="$1"
|
||||||
else
|
else
|
||||||
NODE_ADDR="--node-addr $NODE"
|
echo "Expected single argument: node multiaddress. Got $# arguments."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./build.sh
|
|
||||||
|
|
||||||
# check it .wasm was built
|
# check it .wasm was built
|
||||||
WASM="artifacts/call_parameters.wasm"
|
WASM="artifacts/call_parameters.wasm"
|
||||||
@ -15,5 +17,5 @@ test -f "$WASM" || echo >&2 "Couldn't find $WASM"
|
|||||||
|
|
||||||
# create a service from that .wasm
|
# create a service from that .wasm
|
||||||
CONFIG="config.json"
|
CONFIG="config.json"
|
||||||
SERVICE_ID=$(fldist new_service $NODE_ADDR --modules "$WASM:$CONFIG" --name call_parameters | head -n1 | sed -e 's/service id: //')
|
SERVICE_ID=$(aqua dist deploy --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= --data-path config.json --service call_parameters --addr "$NODE" | tail -n 1 | tr -d \")
|
||||||
echo $SERVICE_ID
|
echo $SERVICE_ID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user