Skip to content

Commit

Permalink
fix(solidity-devops): correctly save new deployments when script entr…
Browse files Browse the repository at this point in the history
…y function is not `run()` (#2883)

* fix: latest broadcast file is not always "run-latest"

* fix: use timestamp when fetching new receipts

* fix: silent exit if broadcast directory doesn't exist
  • Loading branch information
ChiTimesChi authored Jul 17, 2024
1 parent ca253cf commit fd337e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/solidity-devops/js/forgeScriptRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ if (newDeployments.length === 0) {
logInfo('No new deployments found')
process.exit(0)
}
const newReceipts = getNewDeploymentReceipts(chainName, scriptFN)
const newReceipts = getNewDeploymentReceipts(
chainName,
scriptFN,
currentTimestamp
)
newDeployments.forEach((contractAlias) =>
saveNewDeployment(chainName, contractAlias, newReceipts)
)
25 changes: 22 additions & 3 deletions packages/solidity-devops/js/utils/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,30 @@ const getAllDeploymentReceipts = (chainName) => {
})
}

const getNewDeploymentReceipts = (chainName, scriptFN) => {
const getNewDeploymentReceipts = (chainName, scriptFN, timestamp) => {
const chainId = getChainId(chainName)
const scriptBaseName = path.basename(scriptFN)
const broadcastFN = `broadcast/${scriptBaseName}/${chainId}/run-latest.json`
return extractDeploymentReceipts(broadcastFN)
const broadcastDir = path.join('broadcast', scriptBaseName, chainId)
// Silent exit if the broadcast directory does not exist
if (!fs.existsSync(broadcastDir)) {
logError(
`No broadcast directory found for ${scriptBaseName} at ${broadcastDir}`
)
return []
}
// Look for "*-latest.json" files created after the given timestamp.
// These are named after the script entry function, which is usually "run", but could be different.
// In practice there should be only one file, but we implement a generic logic just in case.
return fs
.readdirSync(broadcastDir)
.filter((fn) => {
if (!fn.endsWith('-latest.json')) {
return false
}
const stats = fs.statSync(path.join(broadcastDir, fn))
return stats.mtimeMs > timestamp
})
.flatMap((fn) => extractDeploymentReceipts(path.join(broadcastDir, fn)))
}

const extractDeploymentReceipts = (broadcastFN) => {
Expand Down

0 comments on commit fd337e9

Please sign in to comment.