Skip to content

Commit

Permalink
Fix node check
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Dec 11, 2023
1 parent c023f5d commit 3e128bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
7 changes: 4 additions & 3 deletions common/shell/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { exec, execSync } from "child_process"
import { ExecOptions, exec, execSync } from "child_process"
import { ObjectEncodingOptions } from "fs"

/**
* Run any shell command in a child process and return a promise
* @param command - The full command to run
* @returns A promise that resolves when the command exits
*/
export async function run(command: string) {
const child = exec(command)
export async function run(command: string, options?: ObjectEncodingOptions & ExecOptions) {
const child = exec(command, options)
let data = ""
return new Promise((resolve, reject) => {
child.on("error", reject)
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 15 additions & 18 deletions scripts/root/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ import fs from "fs"
*/
void async function () {
if (process.env.CI !== "true") {
const submodules = fs.readFileSync(".gitmodules", "utf8")
const submoduleDirs = submodules.match(/path = (.*)/g)?.map((path) => path.replace("path = ", ""))
if (submoduleDirs) {
try {
for (const dir of submoduleDirs) {
const content = fs.readdirSync(dir)
if (!content.length) {
throw new Error("🚩 Missing ssh key for submodules")
}
try {
const submodules = fs.readFileSync(".gitmodules", "utf8")
const submoduleDirs = submodules.match(/path = (.*)/g)?.map((path) => path.replace("path = ", ""))
submoduleDirs?.forEach((dir) => {
const content = fs.readdirSync(dir)
if (!content.length) {
throw new Error("🚩 Missing ssh key for submodules")
}
} catch (error) {
console.error(error.message)
throw new Error("🚩 Please add an ssh key for submodules (see https://github.com/consensusnetworks/casimir#prerequisites #1)")
}
})
} catch (error) {
console.error(error.message)
throw new Error("🚩 Please add an ssh key for submodules (see https://github.com/consensusnetworks/casimir#prerequisites #1)")
}

const docker = await run("docker --version") as string
try {
const docker = await run("docker --version") as string
const dockerSplit = docker.split(" ")
const dockerNumber = dockerSplit[2]
const dockerNumberSplit = dockerNumber.split(".")
Expand All @@ -36,8 +34,8 @@ void async function () {
throw new Error("🚩 Please install docker 24.x (see https://github.com/consensusnetworks/casimir#prerequisites #2)")
}

const go = await run("go version") as string
try {
const go = await run("go version") as string
if (!go.includes("1.20")) {
throw new Error("🚩 Incompatible go version")
}
Expand All @@ -48,9 +46,8 @@ void async function () {

try {
const node = await run("node --version") as string
const nodeLtsList = (await run("nvm ls-remote --lts") as string).split("\n")
const nodeLts = nodeLtsList[nodeLtsList.length - 1].split(" ")[0]
if (!nodeLts.includes(node)) {
const nodeLts = await run("source ~/.nvm/nvm.sh && nvm ls-remote --lts | grep 'Latest LTS' | tail -n 1 | awk '{print $2}'") as string
if (!nodeLts.trim().includes(node.trim())) {
throw new Error("🚩 Incompatible node version")
}
} catch (error) {
Expand Down

0 comments on commit 3e128bf

Please sign in to comment.