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: Fix potential undefined error in data[0]?.version and improve er… #932

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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)
})