diff --git a/packages/synthetic-chain/src/cli/cli.ts b/packages/synthetic-chain/src/cli/cli.ts index cc70e0bc..f8cf983c 100755 --- a/packages/synthetic-chain/src/cli/cli.ts +++ b/packages/synthetic-chain/src/cli/cli.ts @@ -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 { @@ -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. */ @@ -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' }); diff --git a/packages/synthetic-chain/src/cli/run.ts b/packages/synthetic-chain/src/cli/run.ts index 2fd5c738..2cb10732 100755 --- a/packages/synthetic-chain/src/cli/run.ts +++ b/packages/synthetic-chain/src/cli/run.ts @@ -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}`; @@ -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( @@ -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( ` @@ -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'); };