Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ag 37 actions api layer #16

Merged
merged 4 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ jobs:
node-version: 20.x

- name: Install dependencies
run: npm install
run: node ci --function installDeps

- name: Run linter
run: npm run lint
run: node ci --function lint

- name: Run duplications check
run: npm run duplicated
run: node ci --function checksDuplications

- name: Run smart contracts unit tests
run: npm run test-contracts
run: node ci --function smartContractsUnitTest

- name: Run scripts unit tests
run: npm run test-scripts
run: node ci --function scriptsUnitTest
24 changes: 24 additions & 0 deletions ci/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const execSync = require("child_process").execSync;

const execSyncOptions = { stdio: "inherit" };

const functions = {
installDeps: function () {
return execSync("npm install", execSyncOptions);
},
lint: function () {
return execSync("npm run lint", execSyncOptions);
},
checksDuplications: function () {
return execSync("npm run duplicated", execSyncOptions);
},
smartContractsUnitTest: function () {
return execSync("npm run test-contracts", execSyncOptions);
},
scriptsUnitTest: function () {
return execSync("npm run test-scripts", execSyncOptions);
},
};

module.exports = functions;
33 changes: 33 additions & 0 deletions ci/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* This script implements logic delegated from the GitHub Actions workflows.
* The workflow invokes the API interface using the CLI with the following command:
*
* node ci --function functionOne --params '{"param1": "value1", "param2": "value2"}'
*/
const functions = require("./functions");

// process command line arguments
const args = process.argv.slice(2);

// checks the arguments
if (args.length < 2 || args[0] !== "--function") {
console.error(
'Correct usage: node ci --function <functionName> --params \'{"param1": "value1", "param2": "value2"}\'',
);
process.exit(1);
}

const functionName = args[1];

let params;
if (args[3]) {
params = JSON.parse(args[3]);
}

// Execute the function invoked
try {
functions[functionName](params);
} catch (e) {
console.error("Error: the function invoked does not exists");
}
Loading