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

chore: publish contracts to soldeer #820

Merged
merged 13 commits into from
Aug 28, 2024
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@
"no-console": ["warn", { "allow": ["info", "warn", "error"] }],
"@typescript-eslint/lines-between-class-members": "off",
"no-param-reassign": "off"
}
},
"overrides": [
{
"files": ["./scripts/*"],
"rules": {
"no-console": "off"
}
}
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ typechain-types

# Other
snark-artifacts

*.zip
1 change: 1 addition & 0 deletions .soldeerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"format": "concurrently -c auto -g -n prettier,embark \"prettier -c .\" \"yarn workspace semaphore-docs format\"",
"format:write": "concurrently -c auto -g -n prettier,embark \"prettier -w .\" \"yarn workspace semaphore-docs format:write\"",
"docs": "typedoc",
"version:bump": "yarn workspaces foreach -A --no-private version -d ${0} && yarn version apply --all && yarn remove:stable-version-field && NO_HOOK=1 git commit -am \"chore: v${0}\" && git tag v${0}",
"version:publish": "yarn build:libraries && yarn clean:cli-templates && yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public",
"version:bump": "scripts/version.ts ${0}",
"version:publish": "scripts/publish.ts",
"version:release": "changelogithub",
"clean": "ts-node scripts/clean-apps.ts && ts-node scripts/clean-packages.ts && yarn clean:cli-templates && rimraf node_modules",
"clean:cli-templates": "ts-node scripts/clean-cli-templates.ts",
"remove:stable-version-field": "ts-node scripts/remove-stable-version-field.ts && yarn format:write",
"clean": "scripts/clean-apps.ts && scripts/clean-packages.ts && yarn clean:cli-templates && rimraf node_modules",
"clean:cli-templates": "scripts/clean-cli-templates.ts",
"remove:stable-version-field": "scripts/remove-stable-version-field.ts && yarn format:write",
"precommit": "lint-staged",
"postinstall": "husky && git config --local core.editor cat"
},
Expand Down Expand Up @@ -55,6 +55,7 @@
"@types/glob": "^7.2.0",
"@types/jest": "^29.5.12",
"@types/node": "^20",
"@types/semver": "^7",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"changelogithub": "0.12.7",
Expand All @@ -76,6 +77,7 @@
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"semver": "^7.6.2",
"snarkjs": "0.7.4",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
Expand Down
1 change: 1 addition & 0 deletions scripts/clean-apps.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!node_modules/.bin/ts-node
cedoor marked this conversation as resolved.
Show resolved Hide resolved
import { readdirSync, rmSync } from "fs"

const folderName = "apps"
Expand Down
1 change: 1 addition & 0 deletions scripts/clean-cli-templates.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!node_modules/.bin/ts-node
import { rmSync } from "fs"

const folderName = "packages"
Expand Down
1 change: 1 addition & 0 deletions scripts/clean-packages.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!node_modules/.bin/ts-node
import { readdirSync, rmSync } from "fs"

const folderName = "packages"
Expand Down
37 changes: 37 additions & 0 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!node_modules/.bin/ts-node
import compare from "semver/functions/compare"
import { execSync } from "child_process"
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"
Copy link
Contributor Author

@sripwoud sripwoud Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest semaphore-protocol-contracts as pkg name on soldeer. soldeer does not support orgs.

Copy link
Member

@cedoor cedoor Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about semaphore-contracts? Sounds easier to remember

)
const { data, status } = await response.json()

// fail status is no version published at all yet
if (status === "fail" || compare(contractsLocalVersion, data[0].version) === 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status will be fail only for the first run (no pkg in soldeer db yet)

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"
})

await maybePushToSoldeer()
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
11 changes: 5 additions & 6 deletions scripts/remove-stable-version-field.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!node_modules/.bin/ts-node
import { readFileSync, readdirSync, writeFileSync } from "node:fs"

const folderName = "packages"
Expand All @@ -19,9 +20,7 @@ async function main() {
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
main().catch((error) => {
console.error(error)
process.exit(1)
})
25 changes: 25 additions & 0 deletions scripts/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!node_modules/.bin/ts-node
import { execSync } from "child_process"

async function main() {
const version = process.argv[2]

// Perform the workspaces version update
execSync(`yarn workspaces foreach -A --no-private version -d ${version}`, { stdio: "inherit" })

// Apply the versions
execSync("yarn version apply --all", { stdio: "inherit" })

await import("./remove-stable-version-field")

execSync("yarn format:write")
execSync(`NO_HOOK=1 git commit -am 'chore: v${version}'`)
execSync(`git tag v${version}`)
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
6 changes: 4 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7863,7 +7863,7 @@ __metadata:
languageName: node
linkType: hard

"@types/semver@npm:^7.3.12, @types/semver@npm:^7.5.8":
"@types/semver@npm:^7, @types/semver@npm:^7.3.12, @types/semver@npm:^7.5.8":
version: 7.5.8
resolution: "@types/semver@npm:7.5.8"
checksum: 10/3496808818ddb36deabfe4974fd343a78101fa242c4690044ccdc3b95dcf8785b494f5d628f2f47f38a702f8db9c53c67f47d7818f2be1b79f2efb09692e1178
Expand Down Expand Up @@ -24659,6 +24659,7 @@ __metadata:
"@types/glob": "npm:^7.2.0"
"@types/jest": "npm:^29.5.12"
"@types/node": "npm:^20"
"@types/semver": "npm:^7"
"@typescript-eslint/eslint-plugin": "npm:^7.0.2"
"@typescript-eslint/parser": "npm:^7.0.2"
changelogithub: "npm:0.12.7"
Expand All @@ -24680,6 +24681,7 @@ __metadata:
lint-staged: "npm:^15.2.2"
prettier: "npm:^3.2.5"
rimraf: "npm:^5.0.5"
semver: "npm:^7.6.2"
snarkjs: "npm:0.7.4"
ts-jest: "npm:^29.1.2"
ts-node: "npm:^10.9.2"
Expand Down Expand Up @@ -24784,7 +24786,7 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^7.1.1, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.2, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0":
"semver@npm:^7.1.1, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.2, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:^7.6.2":
version: 7.6.2
resolution: "semver@npm:7.6.2"
bin:
Expand Down