Skip to content

Commit

Permalink
fix: Fix potential undefined error in data[0]?.version and improve er…
Browse files Browse the repository at this point in the history
…ror handling
  • Loading branch information
ursulabauer authored Dec 21, 2024
1 parent a2e8f5a commit 23902a5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,39 @@ import contractsPkgJson from "@semaphore-protocol/contracts/package.json"
const { version: contractsLocalVersion } = contractsPkgJson

async function maybePushToSoldeer() {
// api not documented, may change, found by inspecting the network tab
const response = await fetch(
"https://api.soldeer.xyz/api/v1/revision?project_name=semaphore-protocol-contracts&limit=1"
)
const { data } = await response.json()

if (
data.length === 0 || // data = [] if no version has ever been published yet
compare(contractsLocalVersion, data[0].version) === 1
)
data.length === 0 ||
compare(contractsLocalVersion, data[0]?.version) === 1
) {
execSync(`soldeer push semaphore-protocol-contracts~${contractsLocalVersion} packages/contracts/contracts`, {
stdio: "inherit"
})
}
}

async function main() {
execSync(`yarn build:libraries`, { stdio: "inherit" })
execSync(`yarn clean:cli-templates`)
execSync(`yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public`, {
stdio: "inherit"
})
try {
execSync(`yarn build:libraries`, { stdio: "inherit" })
execSync(`yarn clean:cli-templates`)
execSync(`yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public`, {
stdio: "inherit"
})

await maybePushToSoldeer()
await maybePushToSoldeer()
} catch (error) {
console.error("Error executing the script:", error)
process.exit(1)
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
console.error("Error in main process:", error)
process.exit(1)
})

0 comments on commit 23902a5

Please sign in to comment.