Skip to content

Commit

Permalink
ci: fail actions on build/test failure (#42)
Browse files Browse the repository at this point in the history
* ci: fail actions on build/test failure

* lint

* prettier
  • Loading branch information
milapsheth authored Jun 3, 2024
1 parent 405ff8c commit d393553
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"main": "index.js",
"scripts": {
"build": "for d in ./move/*/; do cd $d; sui move build --lint --warnings-are-errors & cd ../../; done; wait",
"test": "for d in ./move/*/; do sui move test --path $d ; done",
"build": "./scripts/run.sh build",
"test": "./scripts/run.sh test",
"coverage": "./scripts/coverage.sh",
"lint": "eslint --fix './scripts/*.js'",
"prettier": "prettier --write './scripts/*.js'"
Expand Down
22 changes: 11 additions & 11 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ if ! which "$SUI" >/dev/null 2>&1; then
fi
fi

for d in ./move/*/; do
"$SUI" move test --path "$d" --coverage &
for module in ./move/*/; do
"$SUI" move test --path "$module" --coverage &
done

wait

found=0

for d in ./move/*/; do
echo "Generating coverage info for package $d"
for module in ./move/*/; do
echo "Generating coverage info for package ${module}"

if [ ! -f "$d/.coverage_map.mvcov" ]; then
echo "\n NO tests found for module $d. Skipped.\n" >> .coverage.info
echo "\n NO tests found for module $d. Skipped.\n" >> .coverage.extended.info
if [ ! -f "${module}/.coverage_map.mvcov" ]; then
echo "\n NO tests found for module ${module}. Skipped.\n" >> .coverage.info
echo "\n NO tests found for module ${module}. Skipped.\n" >> .coverage.extended.info
continue
fi

found=1

echo "Coverage report for module $d\n" >> .coverage.info
echo "Coverage report for module $d\n" >> .coverage.extended.info
echo "Coverage report for module ${module}\n" >> .coverage.info
echo "Coverage report for module ${module}\n" >> .coverage.extended.info

"$SUI" move coverage summary --path "$d" >> .coverage.info
"$SUI" move coverage summary --summarize-functions --path "$d" >> .coverage.extended.info
"$SUI" move coverage summary --path "${module}" >> .coverage.info
"$SUI" move coverage summary --summarize-functions --path "${module}" >> .coverage.extended.info

echo "" >> .coverage.info
echo "" >> .coverage.extended.info
Expand Down
4 changes: 2 additions & 2 deletions scripts/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getRandomOperators(n = 5) {
for (let i = 0; i < pubKeyLength; i++) {
const aByte = pubKeys[a][i];
const bByte = pubKeys[b][i];
if (aByte != bByte) return aByte - bByte;
if (aByte !== bByte) return aByte - bByte;
}

return 0;
Expand Down Expand Up @@ -198,7 +198,7 @@ async function approveContractCall(client, keypair, axelarInfo, sourceChain, sou
arguments: [tx.object(validators.objectId), tx.pure(String.fromCharCode(...input))],
typeArguments: [],
});
const approveTxn = await client.signAndExecuteTransactionBlock({
await client.signAndExecuteTransactionBlock({
transactionBlock: tx,
signer: keypair,
options: {
Expand Down
2 changes: 1 addition & 1 deletion scripts/governance.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function initializeGovernance(upgradeCap, client, keypair, env) {
async function takeUpgradeCaps(upgradeCaps, client, keypair, env) {
const governanceConfig = getConfig('governance', env.alias);
const packageId = governanceConfig.packageId;
tx = new TransactionBlock();
const tx = new TransactionBlock();

for (const upgradeCap of upgradeCaps) {
tx.moveCall({
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function publishAll(client, keypair, env) {
while (true)
try {
const { packageId, publishTxn } = await publishPackageFull(packagePath, client, keypair, env);
upgradeCaps[packagePath] = publishTxn.objectChanges.find((obj) => obj.objectType == '0x2::package::UpgradeCap');
upgradeCaps[packagePath] = publishTxn.objectChanges.find((obj) => obj.objectType === '0x2::package::UpgradeCap');
packageIds[packagePath] = packageId;
break;
} catch (e) {
Expand Down
16 changes: 11 additions & 5 deletions scripts/publish-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { execSync } = require('child_process');
const { parseEnv } = require('./utils');
const tmp = require('tmp');
const fs = require('fs');
const path = require('path');

async function publishPackage(packageName, client, keypair) {
const toml = fs.readFileSync(`${__dirname}/../move/${packageName}/Move.toml`, 'utf8');
Expand All @@ -19,10 +20,15 @@ async function publishPackage(packageName, client, keypair) {
const tmpobj = tmp.dirSync({ unsafeCleanup: true });

const { modules, dependencies } = JSON.parse(
execSync(`sui move build --dump-bytecode-as-base64 --path ${__dirname + '/../move/' + packageName} --install-dir ${tmpobj.name}`, {
encoding: 'utf-8',
stdio: 'pipe', // silent the output
}),
execSync(
`sui move build --dump-bytecode-as-base64 --path ${path.join(__dirname, '/../move/', packageName)} --install-dir ${
tmpobj.name
}`,
{
encoding: 'utf-8',
stdio: 'pipe', // silent the output
},
),
);

const tx = new TransactionBlock();
Expand All @@ -44,7 +50,7 @@ async function publishPackage(packageName, client, keypair) {
},
requestType: 'WaitForLocalExecution',
});
if (publishTxn.effects?.status.status != 'success') throw new Error('Publish Tx failed');
if (publishTxn.effects?.status.status !== 'success') throw new Error('Publish Tx failed');

const packageId = (publishTxn.objectChanges?.filter((a) => a.type === 'published') ?? [])[0].packageId;

Expand Down
20 changes: 20 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

if [[ ${#} -ne 1 || ( "$1" != "build" && "$1" != "test" ) ]]; then
echo "Usage: $0 [build|test]"
exit 1
fi

exit_code=0

for module in ./move/*/; do
if ! sui move build --lint --warnings-are-errors --path "$module"; then
exit_code=1
fi
done

if [ $exit_code -ne 0 ]; then
echo ""
echo -e "\033[0;31mBuild failed\033[0m"
exit 1
fi
12 changes: 6 additions & 6 deletions scripts/test-receive-call.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('dotenv').config();

const { BcsReader, BCS, fromHEX, getSuiMoveConfig, bcs: bcsEncoder } = require('@mysten/bcs');
const { BCS, getSuiMoveConfig, bcs: bcsEncoder } = require('@mysten/bcs');
const {
utils: { keccak256, arrayify, hexlify },
} = require('ethers');
Expand Down Expand Up @@ -39,9 +39,9 @@ async function receiveCall(client, keypair, axelarInfo, sourceChain, sourceAddre
type_arguments: [],
},
];
let is_final = false;
let isFinal = false;

while (!is_final) {
while (!isFinal) {
const tx = new TransactionBlock();
makeCalls(tx, moveCalls, payload);
const resp = await client.devInspectTransactionBlock({
Expand All @@ -51,7 +51,7 @@ async function receiveCall(client, keypair, axelarInfo, sourceChain, sourceAddre

const txData = resp.results[0].returnValues[0][0];
const nextTx = getTransactionBcs().de('Transaction', new Uint8Array(txData));
is_final = nextTx.is_final;
isFinal = nextTx.isFinal;
moveCalls = nextTx.move_calls;
}

Expand Down Expand Up @@ -105,7 +105,7 @@ function getTransactionBcs() {
type_arguments: 'vector<string>',
});
bcs.registerStructType('Transaction', {
is_final: 'bool',
isFinal: 'bool',
move_calls: 'vector<MoveCall>',
});
return bcs;
Expand Down Expand Up @@ -185,6 +185,6 @@ if (require.main === module) {
})
).data[0].parsedJson;

if (hexlify(event.data) != payload) throw new Error(`Emmited payload missmatch: ${hexlify(event.data)} != ${payload}`);
if (hexlify(event.data) !== payload) throw new Error(`Emmited payload missmatch: ${hexlify(event.data)} != ${payload}`);
})();
}
5 changes: 3 additions & 2 deletions scripts/test-send-call.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('dotenv').config();

const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
const { SuiClient } = require('@mysten/sui.js/client');

const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
const { TransactionBlock } = require('@mysten/sui.js/transactions');
Expand Down Expand Up @@ -55,5 +55,6 @@ const { toPure, parseEnv } = require('./utils');
).data[0].parsedJson;
console.log(event);

if (hexlify(event.source_id) != test.channel) throw new Error(`Emmited payload missmatch: ${hexlify(event.source)} != ${test.channel}`);
if (hexlify(event.source_id) !== test.channel)
throw new Error(`Emmited payload missmatch: ${hexlify(event.source)} != ${test.channel}`);
})();
1 change: 0 additions & 1 deletion scripts/test-transfer-operatorship.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { transferOperatorship, getRandomOperators } = require('./gateway');
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
const { SuiClient } = require('@mysten/sui.js/client');
const { parseEnv } = require('./utils');
const secp256k1 = require('secp256k1');
const fs = require('fs');

(async () => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getModuleNameFromSymbol(symbol) {
moduleName += char;
} else if (isUppercase(char)) {
moduleName += char.toLowerCase();
} else if (char == '_' || char == ' ') {
} else if (char === '_' || char === ' ') {
moduleName += '_';
}

Expand Down Expand Up @@ -84,7 +84,7 @@ function setConfig(packagePath, envAlias, config) {

async function requestSuiFromFaucet(env, address) {
try {
const resp = await requestSuiFromFaucetV0({
await requestSuiFromFaucetV0({
// use getFaucetHost to make sure you're using correct faucet address
// you can also just use the address (see Sui Typescript SDK Quick Start for values)
host: getFaucetHost(env.alias),
Expand Down

0 comments on commit d393553

Please sign in to comment.