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

Fix graph test #1914

Merged
merged 10 commits into from
Jan 24, 2025
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
5 changes: 5 additions & 0 deletions .changeset/@graphprotocol_graph-cli-1914-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphprotocol/graph-cli": patch
---
dependencies updates:
- Removed dependency [`binary-install@^1.1.0` ↗︎](https://www.npmjs.com/package/binary-install/v/1.1.0) (from `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/afraid-cycles-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

fix bug with graph test #1904
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@pinax/graph-networks-registry": "^0.6.5",
"@whatwg-node/fetch": "^0.10.1",
"assemblyscript": "0.19.23",
"binary-install": "^1.1.0",
"chokidar": "4.0.1",
"debug": "4.3.7",
"docker-compose": "1.1.0",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/binary-install.d.ts

This file was deleted.

60 changes: 39 additions & 21 deletions packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { exec, spawn } from 'node:child_process';
import events from 'node:events';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { Binary } from 'binary-install';
import { pipeline } from 'node:stream/promises';
import { fileURLToPath } from 'node:url';
import { filesystem, patching, print, system } from 'gluegun';
import yaml from 'js-yaml';
import semver from 'semver';
import { Args, Command, Flags } from '@oclif/core';
import { GRAPH_CLI_SHARED_HEADERS } from '../constants.js';
import fetch from '../fetch.js';

export default class TestCommand extends Command {
static description = 'Runs rust binary for subgraph testing.';
Expand Down Expand Up @@ -144,32 +146,52 @@ async function runBinary(
},
) {
const coverageOpt = opts.coverage;
const forceOpt = opts.force;
const logsOpt = opts.logs;
const versionOpt = opts.version;
const latestVersion = opts.latestVersion;
const recompileOpt = opts.recompile;
let binPath = '';

const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt);
try {
const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt);

const url = `https://github.com/LimeChain/matchstick/releases/download/${
versionOpt || latestVersion
}/${platform}`;
const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`;
const binDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'node_modules', '.bin');
binPath = path.join(binDir, `matchstick-${platform}`);

if (logsOpt) {
this.log(`Download link: ${url}`);
if (logsOpt) {
this.log(`Download link: ${url}`);
this.log(`Binary path: ${binPath}`);
}

if (!fs.existsSync(binPath)) {
this.log(`Downloading matchstick binary: ${url}`);
await fs.promises.mkdir(binDir, { recursive: true });
const response = await fetch(url);
if (!response.ok) throw new Error(`Status: ${response.statusText}`);
if (!response.body) throw new Error('No response body received');

const fileStream = fs.createWriteStream(binPath);
await pipeline(response.body, fileStream);
await fs.promises.chmod(binPath, '755');
}
} catch (e) {
this.error(
`Failed to get matchstick binary: ${e.message}\nConsider using -d flag to run it in Docker instead:\n graph test -d`,
{ exit: 1 },
);
}

const binary = new Binary(platform, url, versionOpt || latestVersion);
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
forceOpt ? await binary.install(true) : await binary.install(false);
const args = [];

if (coverageOpt) args.push('-c');
if (recompileOpt) args.push('-r');
if (datasource) args.push(datasource);
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
args.length > 0 ? binary.run(...args) : binary.run();

const child = spawn(binPath, args, { stdio: 'inherit' });
const [code] = await events.once(child, 'exit');
if (code !== 0) {
this.error('Matchstick failed', { exit: 1 });
}
}

async function getPlatform(
Expand All @@ -180,7 +202,7 @@ async function getPlatform(
const type = os.type();
const arch = os.arch();
const cpuCore = os.cpus()[0];
const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|M3|M4|processor)/.test(cpuCore.model);
const isAppleSilicon = arch === 'arm64' && /Apple (M[0-9]|processor)/.test(cpuCore.model);
const linuxInfo = type === 'Linux' ? await getLinuxInfo.bind(this)() : {};
const linuxDistro = linuxInfo.name;
const release = linuxInfo.version || os.release();
Expand All @@ -204,7 +226,7 @@ async function getPlatform(
}
return 'binary-macos-12';
}
if (type === 'Linux' && majorVersion === 22) {
if (type === 'Linux' && (majorVersion === 22 || majorVersion === 24)) {
return 'binary-linux-22';
}
} else {
Expand Down Expand Up @@ -283,10 +305,6 @@ async function runDocker(
const latestVersion = opts.latestVersion;
const recompileOpt = opts.recompile;

// Remove binary-install binaries, because docker has permission issues
// when building the docker images
filesystem.remove('./node_modules/binary-install/bin');

// Get current working directory
const current_folder = filesystem.cwd();

Expand Down
36 changes: 6 additions & 30 deletions pnpm-lock.yaml

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

Loading