Skip to content

Commit

Permalink
chore: publish contracts to soldeer (#820)
Browse files Browse the repository at this point in the history
* chore: define separate version.ts script

* chore: include publishing to soldeer in script

* fix(contracts): push to soldeer

re 800

* ci: fetch latest contract version from soldeer

* refactor: do not use execa in scripts

* fix: do not exit process in script

* chore: remove comments

* refactor: use shebang in ts scripts

* chore(contracts): add soldeerignore

* chore: inherit stdio in scripts

* chore: remove dry run flag

* chore: uncomment

* chore: fix typo in comment
  • Loading branch information
sripwoud authored Aug 28, 2024
1 parent c435712 commit 0d41562
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 14 deletions.
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 @@ -23,12 +23,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 @@ -57,6 +57,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 @@ -78,6 +79,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
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"
)
const { data, status } = await response.json()

// fail status if no version published at all yet
if (status === "fail" || 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"
})

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 @@ -7872,7 +7872,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 @@ -24679,6 +24679,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 @@ -24700,6 +24701,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 @@ -24804,7 +24806,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

0 comments on commit 0d41562

Please sign in to comment.