From 0d41562dad1ac4c1921ffa241ee8b4dd3cb5bd75 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Wed, 28 Aug 2024 16:26:48 +0200 Subject: [PATCH] chore: publish contracts to soldeer (#820) * 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 --- .eslintrc.json | 10 ++++++- .gitignore | 2 ++ .soldeerignore | 1 + package.json | 12 +++++---- scripts/clean-apps.ts | 1 + scripts/clean-cli-templates.ts | 1 + scripts/clean-packages.ts | 1 + scripts/publish.ts | 37 ++++++++++++++++++++++++++ scripts/remove-stable-version-field.ts | 11 ++++---- scripts/version.ts | 25 +++++++++++++++++ yarn.lock | 6 +++-- 11 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 .soldeerignore mode change 100644 => 100755 scripts/clean-apps.ts mode change 100644 => 100755 scripts/clean-cli-templates.ts mode change 100644 => 100755 scripts/clean-packages.ts create mode 100755 scripts/publish.ts mode change 100644 => 100755 scripts/remove-stable-version-field.ts create mode 100755 scripts/version.ts diff --git a/.eslintrc.json b/.eslintrc.json index 81bfd3bc8..e29a04cd2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" + } + } + ] } diff --git a/.gitignore b/.gitignore index 403ba0ef2..b41c0a075 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,5 @@ typechain-types # Other snark-artifacts + +*.zip diff --git a/.soldeerignore b/.soldeerignore new file mode 100644 index 000000000..ec6d3cdd7 --- /dev/null +++ b/.soldeerignore @@ -0,0 +1 @@ +package.json diff --git a/package.json b/package.json index fb9c9d0cd..825fd7941 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", @@ -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", diff --git a/scripts/clean-apps.ts b/scripts/clean-apps.ts old mode 100644 new mode 100755 index 6ce1c0d38..30c854cde --- a/scripts/clean-apps.ts +++ b/scripts/clean-apps.ts @@ -1,3 +1,4 @@ +#!node_modules/.bin/ts-node import { readdirSync, rmSync } from "fs" const folderName = "apps" diff --git a/scripts/clean-cli-templates.ts b/scripts/clean-cli-templates.ts old mode 100644 new mode 100755 index 0fa4381a4..9f472a98b --- a/scripts/clean-cli-templates.ts +++ b/scripts/clean-cli-templates.ts @@ -1,3 +1,4 @@ +#!node_modules/.bin/ts-node import { rmSync } from "fs" const folderName = "packages" diff --git a/scripts/clean-packages.ts b/scripts/clean-packages.ts old mode 100644 new mode 100755 index 546003827..299e95fd8 --- a/scripts/clean-packages.ts +++ b/scripts/clean-packages.ts @@ -1,3 +1,4 @@ +#!node_modules/.bin/ts-node import { readdirSync, rmSync } from "fs" const folderName = "packages" diff --git a/scripts/publish.ts b/scripts/publish.ts new file mode 100755 index 000000000..08f9adecf --- /dev/null +++ b/scripts/publish.ts @@ -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) + }) diff --git a/scripts/remove-stable-version-field.ts b/scripts/remove-stable-version-field.ts old mode 100644 new mode 100755 index 461ab765c..ea00e759a --- a/scripts/remove-stable-version-field.ts +++ b/scripts/remove-stable-version-field.ts @@ -1,3 +1,4 @@ +#!node_modules/.bin/ts-node import { readFileSync, readdirSync, writeFileSync } from "node:fs" const folderName = "packages" @@ -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) +}) diff --git a/scripts/version.ts b/scripts/version.ts new file mode 100755 index 000000000..12ee25915 --- /dev/null +++ b/scripts/version.ts @@ -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) + }) diff --git a/yarn.lock b/yarn.lock index 345c34bbc..51a36c95e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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" @@ -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" @@ -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: