Skip to content

Commit

Permalink
Task to check if localnet is still running for CI (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Oct 24, 2024
1 parent d78f121 commit aa4a53a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./packages/tasks/src/localnet";
import "./packages/tasks/src/stop";
import "./packages/tasks/src/check";

import { HardhatUserConfig } from "hardhat/config";

Expand Down
32 changes: 32 additions & 0 deletions packages/tasks/src/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { task, types } from "hardhat/config";
import fs from "fs";
import ansis from "ansis";

const LOCALNET_PID_FILE = "./localnet.pid";

const localnetCheck = async (args: any) => {
await new Promise((resolve) => setTimeout(resolve, args.delay * 1000));

if (!fs.existsSync(LOCALNET_PID_FILE)) {
console.log(ansis.red("Localnet is not running (PID file missing)."));
process.exit(1);
}

const pid = fs.readFileSync(LOCALNET_PID_FILE, "utf-8").trim();

try {
process.kill(Number(pid), 0);
console.log(ansis.green(`Localnet is running (PID: ${pid}).`));
process.exit(0);
} catch (err) {
console.log(ansis.yellow(`Localnet process (PID: ${pid}) is not running.`));
process.exit(1);
}
};

export const localnetCheckTask = task(
"localnet-check",
"Check if localnet is running"
)
.addParam("delay", "Seconds to wait before checking localnet", 3, types.int)
.setAction(localnetCheck);
1 change: 1 addition & 0 deletions packages/tasks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { localnetTask } from "./localnet";
export { localnetStopTask } from "./stop";
export { localnetCheckTask } from "./check";

0 comments on commit aa4a53a

Please sign in to comment.