Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanmani1122 committed Jan 24, 2025
1 parent f121f67 commit 679a083
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
16 changes: 0 additions & 16 deletions packages/synthetic-chain/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import chalk from 'chalk';
import assert from 'node:assert';
import { execSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { parseArgs } from 'node:util';
import {
Expand Down Expand Up @@ -64,8 +63,6 @@ Until https://github.com/docker/roadmap/issues/371, attempting it will error as
Instead use a builder that supports multiplatform such as depot.dev.
`;

const fileExists = (name: string) => existsSync(name);

/**
* Put into places files that building depends upon.
*/
Expand Down Expand Up @@ -120,20 +117,7 @@ switch (cmd) {
console.log(chalk.cyan.bold(`Testing ${proposal.proposalName}`));
const image = imageNameForProposal(proposal, 'test');
bakeTarget(image.target, values.dry);

const proposalHostScriptsDirectoryPath = `${root}/proposals/${proposal.path}/host`;

const afterHookScriptPath = `${proposalHostScriptsDirectoryPath}/after-test-run.sh`;
const beforeHookScriptPath = `${proposalHostScriptsDirectoryPath}/before-test-run.sh`;

fileExists(beforeHookScriptPath) &&
execSync(beforeHookScriptPath, { stdio: 'inherit' });

runTestImage(proposal);

fileExists(afterHookScriptPath) &&
execSync(afterHookScriptPath, { stdio: 'inherit' });

// delete the image to reclaim disk space. The next build
// will use the build cache.
execSync('docker system df', { stdio: 'inherit' });
Expand Down
30 changes: 24 additions & 6 deletions packages/synthetic-chain/src/cli/run.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { spawnSync } from 'node:child_process';
import { realpathSync } from 'node:fs';
import { existsSync, realpathSync } from 'node:fs';
import {resolve as resolvePath} from 'node:path';
import { ProposalInfo, imageNameForProposal } from './proposals.js';

const propagateMessageFilePath = (env: typeof process.env) => {
const fileName = 'message-file-path.tmp';
const executeHostScriptIfPresent = (
proposal: ProposalInfo,
scriptName: string,
) => {
const scriptPath = `${resolvePath('.')}/proposals/${proposal.path}/host/${scriptName}`;
if (fileExists(scriptPath)) {
console.log(`Running script ${scriptName} for proposal ${proposal.proposalName}`);
spawnSync(scriptPath, { stdio: 'inherit' });
}
};

const fileExists = (name: string) => existsSync(name);

const propagateMessageFilePath = (env: typeof process.env, proposal: ProposalInfo) => {
const fileName = `${proposal.proposalName}-message-file.tmp`;
const { HOME } = env;

const containerFilePath = `/root/${fileName}`;
Expand Down Expand Up @@ -42,6 +56,7 @@ const propagateSlogfile = env => {
};

export const runTestImage = (proposal: ProposalInfo) => {
executeHostScriptIfPresent(proposal, 'before-test-run.sh');
console.log(`Running test image for proposal ${proposal.proposalName}`);
const { name } = imageNameForProposal(proposal, 'test');
spawnSync(
Expand All @@ -52,14 +67,16 @@ export const runTestImage = (proposal: ProposalInfo) => {
'host',
'--rm',
...propagateSlogfile(process.env),
...propagateMessageFilePath(process.env),
...propagateMessageFilePath(process.env, proposal),
name,
],
{ stdio: 'inherit' },
);
executeHostScriptIfPresent(proposal, 'after-test-run.sh');
};

export const debugTestImage = (proposal: ProposalInfo) => {
executeHostScriptIfPresent(proposal, 'before-test-run.sh');
const { name } = imageNameForProposal(proposal, 'test');
console.log(
`
Expand Down Expand Up @@ -87,15 +104,16 @@ export const debugTestImage = (proposal: ProposalInfo) => {
'/usr/src/upgrade-test-scripts/start_agd.sh',
'--interactive',
'--publish',
'26657:26657',
'--publish',
'1317:1317',
'--publish',
'9090:9090',
'--publish',
'26657:26657',
'--tty',
...propagateSlogfile(process.env),
name,
],
{ stdio: 'inherit' },
);
executeHostScriptIfPresent(proposal, 'after-test-run.sh');
};

0 comments on commit 679a083

Please sign in to comment.